Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Code completion using LSP and clangd
ollydbg:
--- Quote from: Pecan on January 16, 2022, 03:17:19 am ---@ollydbg.
Well, I'm at a loss to figure out why that variable is false for you.
Somehow, clangd_client is seeing Setting/Editor/Code completion as unchecked in your CB .conf file.
This has nothing to do with your .cbp file. It's the contents of the .conf file that the debugger is using that's causing this problem.
--- End quote ---
Hi, Pecan, thanks for the help, I will try to debug this issue and see what happens in the code.
ollydbg:
I see some code:
--- Code: --- wxString fileURI = fileUtils.FilePathToURI(infilename); //(ph 2022/01/5)
fileURI.Replace("\\", "/");
DocumentUri docuri = DocumentUri(fileURI.c_str());
cbStyledTextCtrl* pCntl = pcbEd->GetControl();
if (not pCntl) return false;
// save current length of the file
m_FileLinesHistory[pcbEd] = pCntl->GetLineCount();
wxString strText = pCntl->GetText();
const char* pText = strText.mb_str(); //works
writeClientLog(wxString::Format("<<< LSP_DidOpen:%s", docuri.c_str()) );
try { DidOpen(docuri, string_ref(pText, strText.Length()) ); }
catch(std::exception &err)
{
//printf("read error -> %s\nread -> %s\n ", e.what(), read.c_str());
wxString errMsg(wxString::Format("\nLSP_DidOpen() error: %s\n%s", err.what(), docuri.c_str()) );
writeClientLog(errMsg);
cbMessageBox(errMsg);
return false;
}
--- End code ---
My guess is that:
--- Code: ---const char* pText = strText.mb_str();
--- End code ---
Is this correct?
From my point of view, it should be:
--- Quote ---Final word of caution: most of these functions may return either directly the pointer to internal string buffer or a temporary wxCharBuffer or wxWCharBuffer object. Such objects are implicitly convertible to char and wchar_t pointers, respectively, and so the result of, for example, wxString::ToUTF8() can always be passed directly to a function taking const char*. However code such as
--- Code: ---const char *p = s.ToUTF8();
...
puts(p); // or call any other function taking const char *
--- End code ---
--- End quote ---
This is from wx document here: https://docs.wxwidgets.org/trunk/overview_unicode.html
ollydbg:
I make a clean git svn clone, and it looks like the clangd_client can be active now. I'm not sure why.
I see that the changes in my previous post did solve the error message issue. Here is the whole patch I use.
--- Code: --- clangd_client/clangd_client_wx31_64.cbp | 11 ++++++-----
clangd_client/src/LSPclient/src/client.cpp | 4 ++--
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/clangd_client/clangd_client_wx31_64.cbp b/clangd_client/clangd_client_wx31_64.cbp
index 1af073c..eb3e6d4 100644
--- a/clangd_client/clangd_client_wx31_64.cbp
+++ b/clangd_client/clangd_client_wx31_64.cbp
@@ -6,8 +6,8 @@
<Option compiler="gcc" />
<Build>
<Target title="Clangd_Client-uw">
- <Option output="bin/Clangd_Client" prefix_auto="1" extension_auto="1" />
- <Option working_dir="bin31_64" />
+ <Option output="$(TARGET_DEVEL_DIR)/src/devel31_64/share/CodeBlocks/plugins/clangd_client" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="$(TARGET_DEVEL_DIR)/src/devel31_64" />
<Option object_output=".objs31_64" />
<Option external_deps="$(CODEBLOCKS)/libcodeblocks.a;" />
<Option type="3" />
@@ -50,12 +50,13 @@
<Add before="cmd /c @echo CODEBLOCKS: $(CODEBLOCKS)" />
<Add before="cmd /c @echo TARGET_DEVEL_DIR: $(TARGET_DEVEL_DIR)" />
<Add before="g++ --version" />
- <Add after="cmd /c MakeRepoUpload.bat" />
+ <Add after="cmd /c if not exist $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks mkdir $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks" />
+ <Add after="zip -jq9 $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/manifest.xml src/resources/*.xrc" />
+ <Add after="zip -r9 $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/images" />
<Mode after="always" />
</ExtraCommands>
<Environment>
- <Variable name="TARGET_DEVEL_DIR" value="$(CODEBLOCKS)\..\.." />
- <Variable name="TARGET_DEVEL_DIR_AC" value="D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller" />
+ <Variable name="TARGET_DEVEL_DIR" value="D:\code\cb\cb_sf_git\cccrash2019" />
</Environment>
</Target>
<Environment>
diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 3aa6956..6ae6afa 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -1053,7 +1053,7 @@ bool ProcessLanguageClient::DoValidateUTF8data(std::string& data)
char invChar = data[invloc]; // **debugging**
data[invloc] = ' '; //clear the invalid utf8 char
wxString msg = "Error: Removed clangd response invalid utf8 char:";
- msg << "\'" << invChar << "\'";
+ msg << "\'" << wxString::Format("%x", invChar ) << "\'";
Manager::Get()->GetLogManager()->DebugLog(msg);
}
}
@@ -1562,7 +1562,7 @@ bool ProcessLanguageClient::LSP_DidOpen(cbEditor* pcbEd)
m_FileLinesHistory[pcbEd] = pCntl->GetLineCount();
wxString strText = pCntl->GetText();
- const char* pText = strText.mb_str(); //works
+ const char* pText = strText.ToUTF8(); // ollydbg 2022-01-16
writeClientLog(wxString::Format("<<< LSP_DidOpen:%s", docuri.c_str()) );
--- End code ---
Note the change in :
--- Code: ---msg << "\'" << wxString::Format("%x", invChar ) << "\'";
--- End code ---
is also try to suppress a message alert box(an ascii char to wxString convert, but the invChar value is bigger than 127)
Pecan:
@ollydbg
Thanks for working on that. I'll give those changes a test tomorrow.
ollydbg:
I have another patch, it looks like this code should be enabled:
--- Code: --- clangd_client/src/LSPclient/src/client.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 6ae6afa..88f5f8f 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -2443,7 +2443,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
// Assure text is UTF8 before handing to DidChange()
didChangeEvent.text = edText;
- // didChangeEvent.text = edText.ToUTF8(); Trying to find bad utf8 problem
+ didChangeEvent.text = edText.ToUTF8(); //Trying to find bad utf8 problem
std::vector<TextDocumentContentChangeEvent> tdcce{didChangeEvent};
DocumentUri docuri = DocumentUri(fileURI.c_str());
// **debugging**
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version