Author Topic: Code completion using LSP and clangd  (Read 210186 times)

Offline blauzahn

  • Almost regular
  • **
  • Posts: 173
Re: Code completion using LSP and clangd
« Reply #435 on: May 14, 2024, 09:26:51 pm »
meaningful workflow during editing/debugging should be the guide to visual appearance.

@ollydbg: What is your take on this? For how long do both markers compete for the spot in your projects? Do either markers last that long that it really matters?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #436 on: May 15, 2024, 12:03:28 am »
meaningful workflow during editing/debugging should be the guide to visual appearance.

@ollydbg: What is your take on this? For how long do both markers compete for the spot in your projects? Do either markers last that long that it really matters?

I prefer Pecan's method "I can change it to a small right pointing arrow that fits inside any other marker".

I use C::B for my daily work, and some of the clangd_client warnings come from third part library's source code, so those warnings will last for a long time.

Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2790
Re: Code completion using LSP and clangd
« Reply #437 on: May 15, 2024, 06:10:46 pm »

I prefer Pecan's method "I can change it to a small right pointing arrow that fits inside any other marker".

Commit HEAD 13521:
Clangd_client warning margin marker changed to a small right pointing arrow.
« Last Edit: May 16, 2024, 02:31:21 am by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #438 on: May 16, 2024, 02:45:26 pm »

I prefer Pecan's method "I can change it to a small right pointing arrow that fits inside any other marker".

Commit HEAD 13521:
Clangd_client warning margin marker changed to a small right pointing arrow.

Hi, thanks.

I just tried this latest revision.

There is still one issue, clangd error and breakpoint happens in the same line. Still they have the same size. One is circle, and the other is a square.

I can't reproduce a clangd warning easily.  :(

see below image shot:

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2790
Re: Code completion using LSP and clangd
« Reply #439 on: May 16, 2024, 08:27:55 pm »
Hi, thanks.
I just tried this latest revision.

There is still one issue, clangd error and breakpoint happens in the same line. Still they have the same size. One is circle, and the other is a square.

I can't reproduce a clangd warning easily.  :(

see below image shot:

Same with legacy CC . It's always been that way.
I'd have to change legacy CC use of cbEditor to do anything about that.
I'd prefer not changing legacy CC if I can avoid it.

For me, an obvious code  error (red square) should be corrected before debugging occurs. When the error is corrected, the debugger breakpoint circle appears.

Also you can always use the "Debugging windows" icon (top line main menu, left of info icon) to see your breakpoints listed.

I really do not know how to solves this situation without changing the legacy CC interface (cbeditor) for current users.
Legacy CC is used way more than clangd_client.

Suggestions accepted.
« Last Edit: May 17, 2024, 05:20:19 pm by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #440 on: May 18, 2024, 11:52:07 pm »
Quote
I really do not know how to solves this situation without changing the legacy CC interface (cbeditor) for current users.
Legacy CC is used way more than clangd_client.

Hi, pecan, thanks for the work.

I see it is hard to solve this issue. If I remember correctly, the legecy code completion plugin does not use any markers. So, the issue is that the sdk(cb editor) need to supply more options for the markers.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Code completion using LSP and clangd
« Reply #441 on: June 22, 2024, 11:41:29 am »
Hi Pecan,

compile_commands.json is read and parsed every time a file is opened. This uses a lot of CPU, especially during the initial parsing of all files, where
 compile_commands.json is read and parsed as many times as the number of files in the project. Attached patch does some optimisation for this.
1. Save the parsed compile_commands.json until the first batch parsing is completed, cleared after that.
2. After initial batch processing, all the filesnames are stored in a vector, and only if the filename is not present in this vector, compile commands is parsed. This helps to avoid parsing of the compile_commands.json after editing and saving of the file.

Thanks, Christo

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5931
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #442 on: June 23, 2024, 04:05:12 am »
I see you have made several contribution to C::B. Either in this thread or in the compiler log parsing acceleration (High CPU usage during build operation when verbose is enabled)

Great job. But it is a bit hard for me to understand the patch's logic currently.

BTW: Can you show the CPU usage reduction before/after applying this patch? Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2790
Re: Code completion using LSP and clangd
« Reply #443 on: June 23, 2024, 05:58:51 am »
Hi Pecan,

compile_commands.json is read and parsed every time a file is opened. This uses a lot of CPU, especially during the initial parsing of all files, where
 compile_commands.json is read and parsed as many times as the number of files in the project. Attached patch does some optimisation for this.
1. Save the parsed compile_commands.json until the first batch parsing is completed, cleared after that.
2. After initial batch processing, all the filesnames are stored in a vector, and only if the filename is not present in this vector, compile commands is parsed. This helps to avoid parsing of the compile_commands.json after editing and saving of the file.

Thanks, Christo

Thanks, I'll have a look and do some testing.

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 31
Re: Code completion using LSP and clangd
« Reply #444 on: June 23, 2024, 07:13:13 pm »
BTW: Can you show the CPU usage reduction before/after applying this patch? Thanks.
@ollydbg Attaching perf output without and with the optimisation. perf is captured until full codeblocks project is parsed.

Offline Grit Clef

  • Multiple posting newcomer
  • *
  • Posts: 69
  • Where there is a will, there is a way.
Re: Code completion using LSP and clangd
« Reply #445 on: June 24, 2024, 07:18:25 am »
Hi Pecan,
     Today I use GCC 14.1 with wx 3.2.5 to build CB, but I suddenly got some errors when building Clangd_client.
   
Code
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp||In member function 'bool Parser::LSP_GetSymbolsByType(json*, std::set<LSP_SymbolKind>&, std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, LSP_SymbolKind, int> >&)':|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp|3667|error: invalid user-defined conversion from 'wxString' to 'char' [-fpermissive]|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note: candidate is: 'wxString::operator const wchar_t*() const' (near match)|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note:   no known conversion from 'const wchar_t*' to 'char'|
W:\SoftwareDevelopmentTools\mingw32\include\c++\14.1.0\bits\basic_string.h|840|note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp||In member function 'void Parser::WalkDocumentSymbols(json&, wxString&, int&, std::set<LSP_SymbolKind>&, std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, LSP_SymbolKind, int> >&)':|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp|3879|error: invalid user-defined conversion from 'wxString' to 'char' [-fpermissive]|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note: candidate is: 'wxString::operator const wchar_t*() const' (near match)|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note:   no known conversion from 'const wchar_t*' to 'char'|
W:\SoftwareDevelopmentTools\mingw32\include\c++\14.1.0\bits\basic_string.h|840|note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
  How to fix this? Thanks.
  Edit: I just changed the 'name' in line 3667 and 3879 in parser.cpp to 'name.c_str()', and errors disappeared.
   I find that there are several other errors about the same; I remember that I did some changes in wx/msw/setup.h, maybe they influenced the compatibility of wxString and std::string.
« Last Edit: June 24, 2024, 09:00:05 am by Grit Clef »
-Windows 7, 32-bit
-CodeBlocks r13531, gcc 14.1.0, debug version

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2790
Re: Code completion using LSP and clangd
« Reply #446 on: June 25, 2024, 06:55:35 am »
Hi Pecan,
     Today I use GCC 14.1 with wx 3.2.5 to build CB, but I suddenly got some errors when building Clangd_client.
   
Code
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp||In member function 'bool Parser::LSP_GetSymbolsByType(json*, std::set<LSP_SymbolKind>&, std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, LSP_SymbolKind, int> >&)':|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp|3667|error: invalid user-defined conversion from 'wxString' to 'char' [-fpermissive]|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note: candidate is: 'wxString::operator const wchar_t*() const' (near match)|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note:   no known conversion from 'const wchar_t*' to 'char'|
W:\SoftwareDevelopmentTools\mingw32\include\c++\14.1.0\bits\basic_string.h|840|note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp||In member function 'void Parser::WalkDocumentSymbols(json&, wxString&, int&, std::set<LSP_SymbolKind>&, std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, LSP_SymbolKind, int> >&)':|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp|3879|error: invalid user-defined conversion from 'wxString' to 'char' [-fpermissive]|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note: candidate is: 'wxString::operator const wchar_t*() const' (near match)|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note:   no known conversion from 'const wchar_t*' to 'char'|
W:\SoftwareDevelopmentTools\mingw32\include\c++\14.1.0\bits\basic_string.h|840|note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
  How to fix this? Thanks.
  Edit: I just changed the 'name' in line 3667 and 3879 in parser.cpp to 'name.c_str()', and errors disappeared.
   I find that there are several other errors about the same; I remember that I did some changes in wx/msw/setup.h, maybe they influenced the compatibility of wxString and std::string.

I am also using mingw 14.1.0. with wxWidgets 3.2.5 (no modifications), but cannot reproduce this error.

Can you give us steps to reproduce the error?
I believe the Nightly is using the same without errors.
Do you get the error using the nightly build?
« Last Edit: June 25, 2024, 06:57:35 am by Pecan »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7624
    • My Best Post
Re: Code completion using LSP and clangd
« Reply #447 on: June 25, 2024, 11:46:48 am »
Hi Pecan,
     Today I use GCC 14.1 with wx 3.2.5 to build CB, but I suddenly got some errors when building Clangd_client.
   
Code
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp||In member function 'bool Parser::LSP_GetSymbolsByType(json*, std::set<LSP_SymbolKind>&, std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, LSP_SymbolKind, int> >&)':|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp|3667|error: invalid user-defined conversion from 'wxString' to 'char' [-fpermissive]|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note: candidate is: 'wxString::operator const wchar_t*() const' (near match)|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note:   no known conversion from 'const wchar_t*' to 'char'|
W:\SoftwareDevelopmentTools\mingw32\include\c++\14.1.0\bits\basic_string.h|840|note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp||In member function 'void Parser::WalkDocumentSymbols(json&, wxString&, int&, std::set<LSP_SymbolKind>&, std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, LSP_SymbolKind, int> >&)':|
J:\123\CodeBlocksNightlySrc\codeblocks_sfmirror\src\plugins\contrib\clangd_client\src\codecompletion\parser\parser.cpp|3879|error: invalid user-defined conversion from 'wxString' to 'char' [-fpermissive]|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note: candidate is: 'wxString::operator const wchar_t*() const' (near match)|
J:\123\wxWidgets-3.2.5-cb\include\wx\string.h|1635|note:   no known conversion from 'const wchar_t*' to 'char'|
W:\SoftwareDevelopmentTools\mingw32\include\c++\14.1.0\bits\basic_string.h|840|note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'|
  How to fix this? Thanks.
  Edit: I just changed the 'name' in line 3667 and 3879 in parser.cpp to 'name.c_str()', and errors disappeared.
   I find that there are several other errors about the same; I remember that I did some changes in wx/msw/setup.h, maybe they influenced the compatibility of wxString and std::string.

I am also using mingw 14.1.0. with wxWidgets 3.2.5 (no modifications), but cannot reproduce this error.

Can you give us steps to reproduce the error?
I believe the Nightly is using the same without errors.
Do you get the error using the nightly build?

I would check wxUSE_STL, wxUSE_STD_CONTAINERS_COMPATIBLY, and wxUSE_STD_CONTAINERS values.
And, of course wxUSE_UNICODE should be 1 unless you wish to have a nightmare trying to have it set to 0 and fixing all the problems.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline sodev

  • Lives here!
  • ****
  • Posts: 500
Re: Code completion using LSP and clangd
« Reply #448 on: June 25, 2024, 02:42:42 pm »
I would check wxUSE_STL, wxUSE_STD_CONTAINERS_COMPATIBLY, and wxUSE_STD_CONTAINERS values.

The error message looks like a string conversion error, none of these options affect string conversion.

And, of course wxUSE_UNICODE should be 1

I don't think it is possible to build a current wxWidgets without that, i think i saw that some setup headers forcefully set this define to 1 even if u manually set it to 0.

Either compatibility with previous wxWidgets versions has been disabled or more likely wxUSE_UNSAFE_WXSTRING_CONV was disabled. If it was the latter, it would be a good idea to update the code, because using this automatic conversion can lead to fancy errors.

Offline Grit Clef

  • Multiple posting newcomer
  • *
  • Posts: 69
  • Where there is a will, there is a way.
Re: Code completion using LSP and clangd
« Reply #449 on: June 26, 2024, 04:41:00 am »
Oh yes, as sodev said, I just disabled wxUSE_UNSAFE_WXSTRING_CONV. Those STL containers related options have been modified, too, but I don't think they really influence the conversion from wxString to std::string.
-Windows 7, 32-bit
-CodeBlocks r13531, gcc 14.1.0, debug version