[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]
I also got some message like the above in the rev67.
I checked the code change and it looks like:
@@ -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**
This may cause the issue.
EDIT: code in rev67.
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;
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();