Author Topic: Code completion using LSP and clangd  (Read 203647 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: 2788
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: 2788
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: Yesterday at 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: Today at 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: 2788
Re: Code completion using LSP and clangd
« Reply #443 on: Today at 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: Today at 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.