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

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 25
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #420 on: April 20, 2024, 09:02:48 pm »
After testing and tracing clangd_client and the miniAudio source I believe it will not be possible to pass that 4meg miniAudio.h file to clangd.

I have a relatively fast system, but clangd never finished parsing the header file before it crashed attempting to create a response file which would have been many times the size of the source file (about 24meg or more) after it formatted a response containing line/col/symbol/diagnostics/fix suggestions, etc.
If it didn't give out of memory, it sure would have caused Clangd_client to.

That header file will have to be broken up into multiple headers in order for clangd to handle it.

Note from opinionated self: I really do not consider creating a 4meg header file as acceptable software design. It's just going to create grief for anyone using it. If not now, certainly in the future.
yea that makes sense I guess. I think I'll have to break the miniaudio.h in like miniaudio1.h miniaudio2.h miniaudio3.h... for the plugin to not crash, no?

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Code completion using LSP and clangd
« Reply #421 on: April 20, 2024, 10:39:08 pm »
After testing and tracing clangd_client and the miniAudio source I believe it will not be possible to pass that 4meg miniAudio.h file to clangd.

I have a relatively fast system, but clangd never finished parsing the header file before it crashed attempting to create a response file which would have been many times the size of the source file (about 24meg or more) after it formatted a response containing line/col/symbol/diagnostics/fix suggestions, etc.
If it didn't give out of memory, it sure would have caused Clangd_client to.

That header file will have to be broken up into multiple headers in order for clangd to handle it.

Note from opinionated self: I really do not consider creating a 4meg header file as acceptable software design. It's just going to create grief for anyone using it. If not now, certainly in the future.
yea that makes sense I guess. I think I'll have to break the miniaudio.h in like miniaudio1.h miniaudio2.h miniaudio3.h... for the plugin to not crash, no?

Yes, breaking up that huge header into multiple headers should do the trick.


Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Code completion using LSP and clangd
« Reply #422 on: May 01, 2024, 05:28:21 pm »
On Windows 11 opening the project file itself in Windows (not directly through Codeblocks) does not parse the project on opening. Reparsing is needed to be done manually. Doing so through Codeblocks works fine.
Steps to reproduce:
1. Codeblocks not running
2. Double-click on any project file *.cbp

On Plugin wiki https://wiki.codeblocks.org/index.php/CB_Clangd_Client the first link to the plugin repository page is not working.

For information, there is a discussion of doxygen support for Clangd - https://github.com/clangd/clangd/issues/529
Re: Fixed Clangd and parser not parsing when user cold starts CB via DDE. Commit rev 13515

Offline blauzahn

  • Almost regular
  • **
  • Posts: 179
Re: Code completion using LSP and clangd
« Reply #423 on: May 03, 2024, 06:47:11 am »
svn13516 does not compile on my arch linux using wxWidgets trunk:

Quote
src/plugins/contrib/clangd_client/src/LSPclient/lspdiagresultslog.cpp:97:12: error: invalid use of incomplete type 'class wxListCtrl'

Probably a missing #include

Cheers

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Code completion using LSP and clangd
« Reply #424 on: May 03, 2024, 07:03:05 am »
svn13516 does not compile on my arch linux using wxWidgets trunk:

Quote
src/plugins/contrib/clangd_client/src/LSPclient/lspdiagresultslog.cpp:97:12: error: invalid use of incomplete type 'class wxListCtrl'

Probably a missing #include

Cheers

Thanks, corrected (I think) Head r13517.
Please test, because I have no access to Arch linux.

Offline blauzahn

  • Almost regular
  • **
  • Posts: 179
Re: Code completion using LSP and clangd
« Reply #425 on: May 03, 2024, 11:59:00 am »
Thank you.

I just compiled it on ubuntu linux without any compile-error. Arch I can do only in the evening. Since the configure args are the same and both use wxWidgets trunk, chances are, that the outcome will be the same on arch.

Offline blauzahn

  • Almost regular
  • **
  • Posts: 179
Re: Code completion using LSP and clangd
« Reply #426 on: May 03, 2024, 07:24:00 pm »
Head svn13517 compiles again without compile-error on arch linux as well.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #427 on: May 12, 2024, 03:47:22 pm »
When debugging, the current PC (program counter) marker is covered by the clangd_client marker.

See the image below, the first image is that the debugger hits the breakpoint at the line 2342, you see the current PC marker can't be seen

In the second image, you see that if the "next line" button get clicked, the current PC marker can be seen again.

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 blauzahn

  • Almost regular
  • **
  • Posts: 179
Re: Code completion using LSP and clangd
« Reply #428 on: May 12, 2024, 05:19:26 pm »
I'd favour hiding the clangd_client marker during debugging. I prefer them sharing the same space like they do now over wasting more real estate on the screen -- even on larger desktop screens.

Offline blauzahn

  • Almost regular
  • **
  • Posts: 179
Re: Code completion using LSP and clangd
« Reply #429 on: May 13, 2024, 04:12:48 pm »
Quote
svn13517:  - Clangd_client include "sdk.h" needed for lspdiagresultslog.cpp no matter what clangd says

FYI: The warning can be suppressed by issueing a pragma:

Code
#include <cmath> // IWYU pragma: keep

That reduces clutter in the clangd_client's LSP messages box in Code::Blocks. OTOH, in general, it makes sense to go the extra mile and remove unneded #include pretty much wherever you can.

In cases like these, cmath is needed to provide M_PI which clangd does not see.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2808
Re: Code completion using LSP and clangd
« Reply #430 on: May 13, 2024, 08:57:11 pm »
When debugging, the current PC (program counter) marker is covered by the clangd_client marker.

Fixed HEAD 13520
The clangd warning/error margin markers are remove when the debugger starts up.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #431 on: May 14, 2024, 02:40:07 am »
When debugging, the current PC (program counter) marker is covered by the clangd_client marker.

Fixed HEAD 13520
The clangd warning/error margin markers are remove when the debugger starts up.

Hi, pecan, thanks for the fix.
When I'm not debugging, I try to set some breakpoints, and I see the clangd's marker still covers the breakpoint's marker.
So, I think we still need to find a way to show both of the above mentioned markers.

EDIT:
Maybe, make the clangd_client's marker a big smaller?
« Last Edit: May 14, 2024, 02:44:22 am by ollydbg »
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 blauzahn

  • Almost regular
  • **
  • Posts: 179
Re: Code completion using LSP and clangd
« Reply #432 on: May 14, 2024, 07:09:21 am »
@Pecan: Thank you.

@ollydbg: Maybe it is bit of motivation to change the code for good, so that clangd does not show markers anymore -- at least if it is your own code you are free to change. The smaller a marker is, the harder it is to hit it with the mouse. Alternatively one might consider toggling the markers somehow.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #433 on: May 14, 2024, 02:22:45 pm »
@Pecan: Thank you.

@ollydbg: Maybe it is bit of motivation to change the code for good, so that clangd does not show markers anymore -- at least if it is your own code you are free to change. The smaller a marker is, the harder it is to hit it with the mouse. Alternatively one might consider toggling the markers somehow.

Maybe a combination marker for the "breakpoint" and "clangd_client".  ;)
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: 2808
Re: Code completion using LSP and clangd
« Reply #434 on: May 14, 2024, 06:59:09 pm »
When debugging, the current PC (program counter) marker is covered by the clangd_client marker.

Fixed HEAD 13520
The clangd warning/error margin markers are remove when the debugger starts up.

Hi, pecan, thanks for the fix.
When I'm not debugging, I try to set some breakpoints, and I see the clangd's marker still covers the breakpoint's marker.
So, I think we still need to find a way to show both of the above mentioned markers.

EDIT:
Maybe, make the clangd_client's marker a big smaller?

I can change it to a small right pointing arrow that fits inside any other marker, or I can code an option to turn off all clangd_client marker.

Which is preferred ?