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

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2718
Re: Code completion using LSP and clangd
« Reply #345 on: November 16, 2023, 08:05:15 pm »
The  TU information is available to the user, for each activated (referenced) TU, about as fast as your cpu can run the Clangd parser. My Win10 system (an Intel i7/8 core) parses most TUs in 2 seconds or less. Giving Clangd more than 1 core makes for a speedy throughput since that allows Clangd to parse multiple TUs in parallel. I seldom have to wait for info.
clangd use local network? If that's the case, then clang can't run faster than the native way.
Google gave a result in the search, to what extent do you agree with what is described there about the negative facts of clang use.
https://www.eclipsecon.org/sites/default/files/slides/EclipseCon2018-cpp-lsp_0.pdf

Depends on what you mean by a local network.
Clangd_client and Clangd LSP server are all in the same machine communicating with pipes.

I'm not interested in arguments about clang use.
Clangd uses the parser, not the compiler.
CodeBlocks needs a modern parser for C++11 and beyond.
You don't have to use it.
« Last Edit: November 16, 2023, 08:16:27 pm by Pecan »

Offline omlk

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Code completion using LSP and clangd
« Reply #346 on: November 16, 2023, 08:27:07 pm »
Now it will be necessary to monitor what and how clang transmits over the network  :)
Wireshark now officially support msys2 to compile in Windows https://www.wireshark.org/news/20231115b.html
https://omlk.itch.io
from: Ukraine, Ivano-Frankivs`k  https://w.wiki/7vBe

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5897
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #347 on: November 18, 2023, 08:56:50 am »
Hi, Pecan, thanks. I appreciate your work on the clangd_client plugin.
I'm using the rev 13397 for about 6 hours, and I haven't see a crash here till now. :)
I came across the post, and I wonder if you were able to implement what you wrote about?
https://forums.codeblocks.org/index.php?topic=17543.0

And I also wonder how much faster the clang_client works compared to the standard codecompletion (because my codecompletion in some cases does not see the classes, I changed the order of the included header files and disabled others, but there are still problems)?

ollydbg will have to answer your question about COW strings.
It applies to legacy CodeCompletion but not so much to Clangd_Cllient.


@omlk

The COW strings issue. If I member correctly, recent GCC's std::string and wxString do not use the COW(copy on write). So, I think this issue is gone. Because the COW has many issue on multiple thread environment.

About the old legecy CodeCompletion plugin, the parser in this plugin has all hand written. But the modern C++'s grammar is very complex to parse, the parser failed to parse the source files if those files have many advanced C++ code.

Clangd is a compiler level parser, so it parse the source file correctly.
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 omlk

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Code completion using LSP and clangd
« Reply #348 on: November 18, 2023, 01:38:12 pm »
@ollydbg
Thanks for the answer. Then, if you know where to find information that will help improve code completion to a modern level, please let me know. Previously, someone wrote a code completion, but now - no one is capable of it?
The problem here is not to write the code, but to understand how it works, you can say the algorithm of actions.
« Last Edit: November 18, 2023, 01:44:06 pm by omlk »
https://omlk.itch.io
from: Ukraine, Ivano-Frankivs`k  https://w.wiki/7vBe

Offline blauzahn

  • Almost regular
  • **
  • Posts: 153
Re: Code completion using LSP and clangd
« Reply #349 on: November 19, 2023, 10:36:58 am »
I second the remark by @ollydbg. Modern C++ has gotten extremely complex to parse. Even before C++11 it was complex. Recent standards like C++20 have added a ton of additional complexity and are continuing to do so.

Have you ever met a C++-compiler or -library programmer? It is a humbling experience.

It would be a lot more useful to help solving problems already reported in the bugtracker. Thank you for offering help.

Offline DigitalSpaceDotName

  • Single posting newcomer
  • *
  • Posts: 5
Re: Code completion using LSP and clangd
« Reply #350 on: December 28, 2023, 02:25:02 pm »
@ myztmy

Here's my compile of your source.
What's the problem you're presenting?
Please be aware that you have to correct the errors presented by clangd (in the LSP messages log) before clangd can give you proper analysis of your code.

Hi Pecan,

the issue he wanted to mention is that entering char # as described in the screenshot will offer in popup menu the class member method what make no sense in this location. But maybe I'm missing some idea?

I reproduced this issue.

Btw. I am unable to have working pre-processor code completion with clangd plugin from the beginning.
I'm not sure if it is nightly build intent, that not complete pre-processor statements or it is bug. I'm under latest windows 11.

In any case I'm forced to use auto launch typing 1 letter due missing prediction for shorter names than auto-launch in the code.
This is not really issue, but it is only mention.

In all the case very good work guys.


« Last Edit: December 28, 2023, 02:40:05 pm by DigitalSpaceName »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2718
Re: Code completion using LSP and clangd
« Reply #351 on: December 30, 2023, 08:23:45 pm »
Hi Pecan,

the issue he wanted to mention is that entering char # as described in the screenshot will offer in popup menu the class member method what make no sense in this location. But maybe I'm missing some idea?

I reproduced this issue.

Btw. I am unable to have working pre-processor code completion with clangd plugin from the beginning.
I'm not sure if it is nightly build intent, that not complete pre-processor statements or it is bug. I'm under latest windows 11.

In any case I'm forced to use auto launch typing 1 letter due missing prediction for shorter names than auto-launch in the code.
This is not really issue, but it is only mention.

In all the case very good work guys.
... quote snipped by pecan ....

Fixed head rev 13422.
Thanks for reporting and the clarification.

You also no longer have to set the launch at 1 char.

Note that clangd does not offer a list of prior defined names or macros. It offers only a pattern of preprocessor statements.
« Last Edit: December 30, 2023, 08:44:23 pm by Pecan »

Offline DigitalSpaceDotName

  • Single posting newcomer
  • *
  • Posts: 5
Re: Code completion using LSP and clangd
« Reply #352 on: January 01, 2024, 07:58:02 pm »
Great job.

It works for preprocesor as expected and maybe more better than expected.


Thank you.
« Last Edit: January 01, 2024, 09:03:31 pm by DigitalSpaceName »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5897
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #353 on: January 10, 2024, 10:31:40 am »
I noticed that this plugin(the latest revision) can have the #include <xxxx> code completion for the header files, this is a really nice feature.
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.