Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Code completion using LSP and clangd
ollydbg:
I see there are many pch files in the folder such as:
C:\Users\[myusername]\AppData\Local\Temp\preamble-c7460b.pch
I think those files is created by clangd, and are there any way to automatically delete them when exit C::B?
EDIT:
clangd writes too much disk : CPP-19402
This discussion looks like the pch can keep in "memory". :)
ollydbg:
I see some error message comes from this function call, but I'm not sure why, this happens when I'm editing source file in the C::B editor.
--- Code: ---int ProcessLanguageClient::ReadLSPinputLength()
// ----------------------------------------------------------------------------
{
// this function is driven by readJson() via the thread in transport::loop()
// and the incoming data is locked.
// thread was started in constructor and called from readJason() after locking the buffer
// "Content-Length: <digits>\r\n\r\n"
if (Has_LSPServerProcess() and m_std_LSP_IncomingStr.length())
{
// search for LSP header
size_t hdrPosn = m_std_LSP_IncomingStr.find("Content-Length: ");
if (hdrPosn == std::string::npos)
return wxNOT_FOUND;
else //have incoming text
{
if (hdrPosn != 0) // verify LSP header is at beginning of buffer
{
// Error: header is not at beginning of buffer. Try to fix it.
// usually caused by clangd invalid utf8 sequence
wxString msg(wxString::Format("ERROR:%s(): buffLength (%d): Position of content header %d.\n",
__FUNCTION__, int(m_std_LSP_IncomingStr.length()), int(hdrPosn)) );
msg += "Buffer contents written to client log.";
#if defined(cb_DEBUG)
wxSafeShowMessage("Input Buffer error",msg);
#endif
msg += "LSP_IncomingStrBuf:\n" + m_std_LSP_IncomingStr + "\n";
writeClientLog(msg);
// adjust the data buf to get clangd header at buff beginning
m_std_LSP_IncomingStr = m_std_LSP_IncomingStr.substr(hdrPosn);
}
--- End code ---
I just enabled the log file, and see the log message(in C:\Users\[myusername]\AppData\Local\Temp\CBclangd_client-1332.log
And the content of the log file are:
--- Code: ---19:45:09.758 ERROR:ReadLSPinputLength(): buffLength (549): Position of content header 112.
Buffer contents written to client log.LSP_IncomingStrBuf:
":{"newText":"wxConvAuto($0)","range":{"end":{"character":16,"line":94},"start":{"character":12,"line":94}}}}]}}Content-Length: 414
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"category":"Parse Issue","code":"expected_unqualified_id","codeActions":[],"message":"Expected unqualified-id","range":{"end":{"character":14,"line":97},"start":{"character":12,"line":97}},"relatedInformation":[],"severity":1,"source":"clang"}],"uri":"file:///F:/test/Config.cpp","version":1}}
--- End code ---
ollydbg:
--- Quote from: ollydbg on January 17, 2022, 12:32:16 pm ---I see there are many pch files in the folder such as:
C:\Users\[myusername]\AppData\Local\Temp\preamble-c7460b.pch
I think those files is created by clangd, and are there any way to automatically delete them when exit C::B?
EDIT:
clangd writes too much disk : CPP-19402
This discussion looks like the pch can keep in "memory". :)
--- End quote ---
Here is the patch to fix this pch file issue:
--- Code: --- clangd_client/src/LSPclient/src/client.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 88f5f8f..f6b5eb9 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -266,6 +266,10 @@ ProcessLanguageClient::ProcessLanguageClient(const cbProject* pProject, const ch
command += " --limit-results=20"; // Limit the number of results returned by clangd. 0 means no limit (default=100)
+ // clangd writes too much disk : CPP-19402 https://youtrack.jetbrains.com/issue/CPP-19402
+ // "-pch-storage=memory"
+ command += " -pch-storage=memory";
+
if (wxDirExists(clangResourceDir))
command += " --resource-dir=" + clangResourceDir; // Directory for system includes
--- End code ---
ollydbg:
I see there are some code snippet like:
--- Code: ---m_MutexInputBufGuard.Lock;
m_MutexInputBufGuard.Unlock();
--- End code ---
But in the code, we have to carefully handle the unlocking the wxMutex when return the function body, especially when there are multiply returns.
Is it possible to use the wxMutexLocker, and check the IsOK() function for checking whether it get locked or not.
Pecan:
--- Quote from: ollydbg on January 17, 2022, 01:14:47 pm ---I see some error message comes from this function call, but I'm not sure why, this happens when I'm editing source file in the C::B editor.
--- Code: ---int ProcessLanguageClient::ReadLSPinputLength()
// ----------------------------------------------------------------------------
{
// this function is driven by readJson() via the thread in transport::loop()
// and the incoming data is locked.
// thread was started in constructor and called from readJason() after locking the buffer
// "Content-Length: <digits>\r\n\r\n"
if (Has_LSPServerProcess() and m_std_LSP_IncomingStr.length())
{
// search for LSP header
size_t hdrPosn = m_std_LSP_IncomingStr.find("Content-Length: ");
if (hdrPosn == std::string::npos)
return wxNOT_FOUND;
else //have incoming text
{
if (hdrPosn != 0) // verify LSP header is at beginning of buffer
{
// Error: header is not at beginning of buffer. Try to fix it.
// usually caused by clangd invalid utf8 sequence
wxString msg(wxString::Format("ERROR:%s(): buffLength (%d): Position of content header %d.\n",
__FUNCTION__, int(m_std_LSP_IncomingStr.length()), int(hdrPosn)) );
msg += "Buffer contents written to client log.";
#if defined(cb_DEBUG)
wxSafeShowMessage("Input Buffer error",msg);
#endif
msg += "LSP_IncomingStrBuf:\n" + m_std_LSP_IncomingStr + "\n";
writeClientLog(msg);
// adjust the data buf to get clangd header at buff beginning
m_std_LSP_IncomingStr = m_std_LSP_IncomingStr.substr(hdrPosn);
}
--- End code ---
I just enabled the log file, and see the log message(in C:\Users\[myusername]\AppData\Local\Temp\CBclangd_client-1332.log
And the content of the log file are:
--- Code: ---19:45:09.758 ERROR:ReadLSPinputLength(): buffLength (549): Position of content header 112.
Buffer contents written to client log.LSP_IncomingStrBuf:
":{"newText":"wxConvAuto($0)","range":{"end":{"character":16,"line":94},"start":{"character":12,"line":94}}}}]}}Content-Length: 414
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"category":"Parse Issue","code":"expected_unqualified_id","codeActions":[],"message":"Expected unqualified-id","range":{"end":{"character":14,"line":97},"start":{"character":12,"line":97}},"relatedInformation":[],"severity":1,"source":"clang"}],"uri":"file:///F:/test/Config.cpp","version":1}}
--- End code ---
--- End quote ---
This is caused by clangd sending a message (usually a code completion response) with an illegal utf8 char. Clangd sets the message with a header specifying the wrong length which eats up the content-header for the following message.
I have to correct the situation by searching for the content-header.
I have now commented out that message box. The code works to correct the situation so we don't need that anymore.
Thanks for testing and finding these "gotchas" I've forgotten about.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version