Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Code completion using LSP and clangd
ollydbg:
--- Code: ---[Window Title]
codeblocks.exe
[Content]
LSP_DidChange error: [json.exception.type_error.316] invalid UTF-8 byte at index 4: 0xB4
file:///D:/project/abc.cpp
[OK]
--- End code ---
I also got some message like the above in the rev67.
I checked the code change and it looks like:
--- Code: ---@@ -2585,7 +2609,12 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
///- hasChangedLineCount = true; //(ph 2021/07/26) //(ph 2021/10/11) clangd v13 looks ok
if ( (hasChangedLineCount) or (lineChangedNbr >= oldLineCount-1) )
// send the whole editor text to the server.
- edText = pCtrl->GetText();
+ // Assure text is UTF8 before handing to DidChange()
+ #if wxCHECK_VERSION(3,1,5) //3.1.5 or higher
+ edText = pCtrl->GetText().utf8_string(); //(ph 2022/06/22)
+ #else
+ edText = pCtrl->GetText().ToUTF8();
+ #endif
else
{
// send only the one line that changed. //(send previous, current, and next line maybe??)
@@ -2599,9 +2628,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
didChangeEvent.range = range;
}
- // Assure text is UTF8 before handing to DidChange()
didChangeEvent.text = edText;
- // didChangeEvent.text = edText.ToUTF8(); Trying to find bad utf8 problem
std::vector<TextDocumentContentChangeEvent> tdcce{didChangeEvent};
DocumentUri docuri = DocumentUri(fileURI.c_str());
// **debugging**
--- End code ---
This may cause the issue.
EDIT: code in rev67.
--- Code: --- wxString edText;
// If line count has changed, send full text, else send changed line.
// Also, special handling for last line of text
///- hasChangedLineCount = true; //(ph 2021/07/26) //(ph 2021/10/11) clangd v13 looks ok
if ( (hasChangedLineCount) or (lineChangedNbr >= oldLineCount-1) )
// send the whole editor text to the server.
// Assure text is UTF8 before handing to DidChange()
#if wxCHECK_VERSION(3,1,5) //3.1.5 or higher
edText = pCtrl->GetText().utf8_string(); //(ph 2022/06/22)
#else
edText = pCtrl->GetText().ToUTF8();
#endif
else
{
// send only the one line that changed. //(send previous, current, and next line maybe??)
edText = lineText;
Range range;
range.start.line = lineChangedNbr;
range.start.character = lineBeginCol;
range.end.line = lineEndNbr+1;
range.end.character = 0;
//didChangeEvent.rangeLength = lineText.Length(); dont use. it's been deprecated
didChangeEvent.range = range;
}
didChangeEvent.text = edText;
--- End code ---
I think the variable "edText" should have the std::string type, not the wxString.
Also, if possible this line
edText = lineText;
Should also be adjusted because lineText is wxString, while edText is changed to std::string.
Maybe, you should also put the wxString to utf8 format at the last stage as:
didChangeEvent.text = edText.ToUTF8();
Pecan:
--- Quote from: ollydbg on July 17, 2022, 09:40:34 am ---...snipped...
I think the variable "edText" should have the std::string type, not the wxString.
Also, if possible this line
edText = lineText;
Should also be adjusted because lineText is wxString, while edText is changed to std::string.
Maybe, you should also put the wxString to utf8 format at the last stage as:
didChangeEvent.text = edText.ToUTF8();
--- End quote ---
I will revert DidChange() and DidOpen() to rev66 since that code worked ok.
Then (after the revert commit) I'll make an experimental branch with your suggestions and have you test the changes.
Thanks for the suggestions and thanks for testing.
Pecan:
--- Quote from: ollydbg on July 17, 2022, 01:35:19 am ---Sometimes, when a new editor get opened. (mostly happens when I use find declaration to open a new editor), there is a message shown in the right bottom corner of the C::B's main frame immediately after the editor opened, and it said this file is not parsed yet. I also believe this is a wrong event sequence handling issue.
--- End quote ---
Yes, I know.
There needs to be some wait set between the time a closed file is opened and sent to clangd and when the code for GoTo Decl/Impl is executed. This probably is also true of FindReferences etc.
I'll enter this comment into the clangd_client repo ticket system.
(Ticket #54 in Clangd_Client repo)
AndrewCot:
Pecan, You can blow away my old experimental branch so that there is only one experimental branch.
ollydbg:
Hi, Pecan, I think this patch is still needed to handle the wxString to char* convertion, the char* should be UTF-8 format.
This is against rev69.
--- Code: ----------------------- clangd_client/src/LSPclient/client.cpp --------------------
index c1d5d59..c6f8c22 100644
@@ -2649,7 +2649,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
didChangeEvent.range = range;
}
- didChangeEvent.text = edText;
+ didChangeEvent.text = edText.ToStdString(wxConvUTF8);
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