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

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 25
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #405 on: April 10, 2024, 11:23:55 pm »
I should be the one thanking you for this amazing plugin ;D

In the coming Nightly, you will also be able to Alt-LeftMouseClick on the red/green warning/error box in the margin to apply any suggested fix.
Hmmm... I might have to keep an eye out for nightly build after this.

Offline MaxGaspa

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Code completion using LSP and clangd
« Reply #406 on: April 16, 2024, 12:02:56 pm »
Hi,

I'm writing to submit a (passible) bug report of the Code Completion plugin (LSP and Clangd).

When I load a project the plugin starts to parse all the project's files. I observe the log of parsing in the Code::Blocks  panel of the Logs window. In the meantime  I open a file, Application.cpp for example,  and  I select "Application:" to use the plugin (see image attached)...but...as soon as a new file is parsed the selection disappears....so I can't use the code completion till the full parsing of the projects. As soon as a new file parsing is completed the selection becomes blank.

Is this behavior expected?

Windows 10 , latest nightly , latest Mys2 clang 18.1.3-1

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2803
Re: Code completion using LSP and clangd
« Reply #407 on: April 16, 2024, 06:37:58 pm »
Hi,

I'm writing to submit a (passible) bug report of the Code Completion plugin (LSP and Clangd).

When I load a project the plugin starts to parse all the project's files. I observe the log of parsing in the Code::Blocks  panel of the Logs window. In the meantime  I open a file, Application.cpp for example,  and  I select "Application:" to use the plugin (see image attached)...but...as soon as a new file is parsed the selection disappears....so I can't use the code completion till the full parsing of the projects. As soon as a new file parsing is completed the selection becomes blank.

Is this behavior expected?

Windows 10 , latest nightly , latest Mys2 clang 18.1.3-1

Would you please give steps to re-create and trace the problem, i.e.,
1) do this
2) now do that

Offline MaxGaspa

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Code completion using LSP and clangd
« Reply #408 on: April 16, 2024, 08:05:51 pm »

Would you please give steps to re-create and trace the problem, i.e.,
1) do this
2) now do that

1) open a project with multiple source file, so the whole parsing process takes time (more than few seconds)
2) During the parsing process open a source file
3) Select in the box (shown in the attached e-mail) a choice
4) When the parsing of a file is completed the box is cleared (made empty).

In case I can make a video....

Max

Offline MaxGaspa

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Code completion using LSP and clangd
« Reply #409 on: April 16, 2024, 10:43:40 pm »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2803
Re: Code completion using LSP and clangd
« Reply #410 on: April 17, 2024, 07:09:19 pm »
Hi,

I'm writing to submit a (passible) bug report of the Code Completion plugin (LSP and Clangd).

When I load a project the plugin starts to parse all the project's files. I observe the log of parsing in the Code::Blocks  panel of the Logs window. In the meantime  I open a file, Application.cpp for example,  and  I select "Application:" to use the plugin (see image attached)...but...as soon as a new file is parsed the selection disappears....so I can't use the code completion till the full parsing of the projects. As soon as a new file parsing is completed the selection becomes blank.

Is this behavior expected?

Windows 10 , latest nightly , latest Mys2 clang 18.1.3-1

Thanks for the video. It cleared up (in my head) what box you were trying to point out.

That box is called the Clangd_client (or CodeCompletion) toolbar.

It is only active when an editor has been activated. It shows the classes and the functions that the editors cursor is positioned within. I.e., the cursor must have clicked in an
editor at least once (activate) to fill in the choice boxes.

The left hand side (the one you were clicking in) displays the classes in an active editor file, and the right hand choice box shows all functions within the class.

You can cause the editor to position on a class/function by clicking in the left hand choice box to choose the class, then click in the right choice box and choosing what function to position to.

What's happening in your video is that you never activated the editor by clicking into it. So the choice boxes were never populated.

Regards

« Last Edit: April 17, 2024, 07:21:01 pm by Pecan »

Offline MaxGaspa

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Code completion using LSP and clangd
« Reply #411 on: April 17, 2024, 11:28:29 pm »

It is only active when an editor has been activated. It shows the classes and the functions that the editors cursor is positioned within. I.e., the cursor must have clicked in an
editor at least once (activate) to fill in the choice boxes.

What's happening in your video is that you never activated the editor by clicking into it. So the choice boxes were never populated.


Thank you for your answer but....

...it seems that the issue is still the same even if I'm clicking the editor.

Hereafter another video in which it should be very clear that I'm activating (clicking) the editor but the "left choice" still disapperar.

If I'm so quick (very quick) to select something in the "right choice" before the "left choice" is blanked .... then the "left choice" is no longer disappearing. But it's difficult...I need to be very quick. Basically I need to wait for the parsing completion before using the plugin.

https://drive.google.com/file/d/1ntVkrxRg9YccNJBByNuHaBKE-SgX3Xwn/view?usp=sharing

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2803
Re: Code completion using LSP and clangd
« Reply #412 on: April 18, 2024, 01:03:08 am »

It is only active when an editor has been activated. It shows the classes and the functions that the editors cursor is positioned within. I.e., the cursor must have clicked in an
editor at least once (activate) to fill in the choice boxes.

What's happening in your video is that you never activated the editor by clicking into it. So the choice boxes were never populated.


Thank you for your answer but....

...it seems that the issue is still the same even if I'm clicking the editor.

Hereafter another video in which it should be very clear that I'm activating (clicking) the editor but the "left choice" still disapperar.

If I'm so quick (very quick) to select something in the "right choice" before the "left choice" is blanked .... then the "left choice" is no longer disappearing. But it's difficult...I need to be very quick. Basically I need to wait for the parsing completion before using the plugin.

https://drive.google.com/file/d/1ntVkrxRg9YccNJBByNuHaBKE-SgX3Xwn/view?usp=sharing

I cannot reproduce this. So would you start CB with the -d or /d parameter so that the Code::Blocks Debug log is produced.

Before you load your project be sure that the "CodeBlocks Debut" log tab is focused.

Do as you have done to cause the bug, then right-click the Code::Blocks Debug tab and choose copy "contents to clipboard", Paste it into a message here between code tags (the # icon above a forum reply box).

Thanks for your patience with this.
It's really peculiar.

BTW: after the new file is parsed and clicked into, can you even perform a Mainmenu/Search/goto function, (Ctrl-Shift-G for me.)
It tells me if if the bug is in the plugin interface to the editor code or the toobar code.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2803
Re: Code completion using LSP and clangd
« Reply #413 on: April 18, 2024, 01:18:54 am »

It is only active when an editor has been activated. It shows the classes and the functions that the editors cursor is positioned within. I.e., the cursor must have clicked in an
editor at least once (activate) to fill in the choice boxes.

What's happening in your video is that you never activated the editor by clicking into it. So the choice boxes were never populated.


Thank you for your answer but....

...it seems that the issue is still the same even if I'm clicking the editor.

Hereafter another video in which it should be very clear that I'm activating (clicking) the editor but the "left choice" still disapperar.

If I'm so quick (very quick) to select something in the "right choice" before the "left choice" is blanked .... then the "left choice" is no longer disappearing. But it's difficult...I need to be very quick. Basically I need to wait for the parsing completion before using the plugin.

https://drive.google.com/file/d/1ntVkrxRg9YccNJBByNuHaBKE-SgX3Xwn/view?usp=sharing

I just watched the video again.
I see that you're not clicking either inside a class or a function.
Do this, after the clicked file has parsed, click inside a function, not at the top of an editor file.
Tell me if you still get the bug.

If you get the bug, send me the Code::Blocks Debug log as specified in the previous messgage.

Thanks
« Last Edit: April 18, 2024, 06:20:24 am by Pecan »

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 25
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #414 on: April 18, 2024, 08:17:02 am »
hey @Pecan
sorry to bother you again but I have encounter an unusual behavior.
I was trying to use a large single file libraryhttps://github.com/mackron/miniaudio.
It has a single headerfile: miniaudio.h <--- 62k lines

when I try to open the header file or search for declaration through the main.c, whole code blocks freezes for solid 1-2 mins, weanwhile the mouse gradually becomes unresponsive until it's completely frozen and the screen turns black. Throws an error that Clangd_Cliet has stopped at the end.

I not sure if it's because my laptop isn't powerful enough. because the plugin usually worked smooth with other large libraries.

Apart from this single instance the plugin works fine and it has been very helpful.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2803
Re: Code completion using LSP and clangd
« Reply #415 on: April 18, 2024, 06:21:12 pm »
hey @Pecan
sorry to bother you again but I have encounter an unusual behavior.
I was trying to use a large single file libraryhttps://github.com/mackron/miniaudio.
It has a single headerfile: miniaudio.h <--- 62k lines

when I try to open the header file or search for declaration through the main.c, whole code blocks freezes for solid 1-2 mins, weanwhile the mouse gradually becomes unresponsive until it's completely frozen and the screen turns black. Throws an error that Clangd_Cliet has stopped at the end.

I not sure if it's because my laptop isn't powerful enough. because the plugin usually worked smooth with other large libraries.

Apart from this single instance the plugin works fine and it has been very helpful.

I'll have a look at it.
Please attach your .cbp file for the project and your main.c  to a forum reply, so I can mirror what's happening.
Thanks for the report.

« Last Edit: April 18, 2024, 06:40:22 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2803
Re: Code completion using LSP and clangd
« Reply #416 on: April 18, 2024, 11:16:15 pm »
hey @Pecan
sorry to bother you again but I have encounter an unusual behavior.
I was trying to use a large single file libraryhttps://github.com/mackron/miniaudio.
It has a single headerfile: miniaudio.h <--- 62k lines

when I try to open the header file or search for declaration through the main.c, whole code blocks freezes for solid 1-2 mins, weanwhile the mouse gradually becomes unresponsive until it's completely frozen and the screen turns black. Throws an error that Clangd_Cliet has stopped at the end.

I not sure if it's because my laptop isn't powerful enough. because the plugin usually worked smooth with other large libraries.

Apart from this single instance the plugin works fine and it has been very helpful.

I'll have a look at it.
Please attach your .cbp file for the project and your main.c  to a forum reply, so I can mirror what's happening.
Thanks for the report.

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.
« Last Edit: April 19, 2024, 04:05:11 am by Pecan »

Offline MaxGaspa

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Code completion using LSP and clangd
« Reply #417 on: April 19, 2024, 11:24:34 am »
I see that you're not clicking either inside a class or a function.
Do this, after the clicked file has parsed, click inside a function, not at the top of an editor file.

Yes, clicking inside a function or class works. Thanks

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 25
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #418 on: April 20, 2024, 08:39:17 pm »
I'll have a look at it.
Please attach your .cbp file for the project and your main.c  to a forum reply, so I can mirror what's happening.
Thanks for the report.
(sorry for the late reply, I lost track of time)
I had to change the file extension since the anything other than image and txt file isn't accepted. Miniaudio.txt is cbp and main.txt is main.c

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 25
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #419 on: April 20, 2024, 08:51:21 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... no?