Author Topic: an easy cpp language-server-protocol client(C++)  (Read 2346 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5295
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
an easy cpp language-server-protocol client(C++)
« on: December 08, 2020, 04:31:19 pm »
alextsao1999/lsp-cpp: an easy cpp language-server-protocol client

I found one project in github which can handle LSP in C++.

Maybe, we can use it as a new simple code-completion engine.  :)

This guy also has a similar interesting project: alextsao1999/ast-buffer: Fast incremental parsing using piece table and tree-sitter to generate syntax tree
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13007
    • Travis build status
Re: an easy cpp language-server-protocol client(C++)
« Reply #1 on: December 08, 2020, 08:39:55 pm »
Yes, but first you need to have a CC plugin which supports LSP.
Mine is in pretty experimental state and I'm not sure I'll be able to get to it in 2021. :(
Then you have plenty of options for LSP C++ support.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Online BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2863
Re: an easy cpp language-server-protocol client(C++)
« Reply #2 on: December 09, 2020, 01:38:13 am »
If i am not misunderstanding this, this IS a client? Or at least the base for a client?

[Edit:] Yes this is a client, and it looks quite compact. It is windows only, so we would have to adapt it, but the whole protocol handling could probably be taken from this (if the license is ok) and this would be a huge part less work...
« Last Edit: December 09, 2020, 01:48:48 am by BlueHazzard »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2278
Re: an easy cpp language-server-protocol client(C++)
« Reply #3 on: December 09, 2020, 07:02:36 am »
I have the alextsao1999/lsp-cpp working as a client CB plugin (on windows) using CCLS/clang as the server.

It works quite well. But I'm disappointed that it is not as fast as the CB CC plugin responding to code completions.

I think this is because CB CC looks up the results directly from its' tree of symbols and can respond nearly immediately.

Where as CB CCLS has to communicate via pipes to CCLS. So there's a 1/4 second (or less) lag between the ccmanagers event notification and the response from CCLS/clang.
« Last Edit: December 09, 2020, 07:08:34 am by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5295
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: an easy cpp language-server-protocol client(C++)
« Reply #4 on: December 09, 2020, 09:07:06 am »
I have the alextsao1999/lsp-cpp working as a client CB plugin (on windows) using CCLS/clang as the server.

It works quite well. But I'm disappointed that it is not as fast as the CB CC plugin responding to code completions.

I think this is because CB CC looks up the results directly from its' tree of symbols and can respond nearly immediately.

Where as CB CCLS has to communicate via pipes to CCLS. So there's a 1/4 second (or less) lag between the ccmanagers event notification and the response from CCLS/clang.
Wonderful job!

I think the time lag about 250ms is not that much. Maybe, we can use CodeLite's method, let user choose which code completion they need or make the CCLS as a fallback.
I see some of my friend are using visual studio code, it also use some clang related tool to do code completion, and he said it is slow especially for a prject which has 10 or 20 more cpp files.

The nice thing about CCLS is that it can do more things about code completion, such as variable rename, go to reference ...

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: 2278
Re: an easy cpp language-server-protocol client(C++)
« Reply #5 on: December 09, 2020, 07:12:42 pm »
...we can use CodeLite's method, let user choose which code completion they need or make the CCLS as a fallback.

I see some of my friend are using visual studio code, it also use some clang related tool to do code completion, and he said it is slow especially for a prject which has 10 or 20 more cpp files.

The nice thing about CCLS is that it can do more things about code completion, such as variable rename, go to reference ...

Agreed that we can use a method somewhat like CodeLites' to allow user code completion choices. But I'm still in the coding stage of adding all the current features of CB CC into the CB CCLS client.

RE: slowness of large projects:
CCLS has a nice way of getting around this problem.
It can be run as a standalone process that creates an indexed cache of all project files and symbols. It then can use/maintain this cache when a client sends didSave, didChange, didClose etc. requests and notifications.

Because it builds a file index/symbol cache as it's used, it gets faster with age. Since it does not have to ask for a clang parse on opening an already cached file, it's responsive immediately on project activation.

It's dependencies are a disadvantage because of size of distribution. To compile CCLS requires the clang includes and llvm dlls. CCLS must be at the same version level as clang/llvm.

For me, compiling CCLS on Windows required Msys2, clang, and some llvm dlls distributed with Msys2. All this because the Windows clang/llvm source is not distributed with all the needed clang headers. Sheesh :(
There must be some way around this since CodeLite does it. I need to explore how.
« Last Edit: December 09, 2020, 07:18:40 pm by Pecan »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13007
    • Travis build status
Re: an easy cpp language-server-protocol client(C++)
« Reply #6 on: December 10, 2020, 10:32:21 am »
In my test implementation of LSP plugin. The communication part wasn't a problem. The LSP server replied pretty fast for small test files.

p.s. A LSP client might feel slow, because it is using some modern json c++ library. All those are pretty slow, but of course they compile slowly. :)
« Last Edit: December 10, 2020, 10:36:10 am by oBFusCATed »
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Miguel Gimenez

  • Lives here!
  • ****
  • Posts: 595
Re: an easy cpp language-server-protocol client(C++)
« Reply #7 on: December 10, 2020, 12:35:03 pm »
LSP does not use a full fledged JSON, may be a reduced version written from scratch give better results.

Offline gh_origin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: an easy cpp language-server-protocol client(C++)
« Reply #8 on: December 12, 2020, 04:04:59 pm »
Everyone seemed to favor CodeLite much? The only thing I know about it code completion is here  >:(

https://forums.codelite.org/viewtopic.php?f=11&t=4653

https://forums.codelite.org/viewtopic.php?f=11&t=4611

CodeBlocks' code completion is not good but works (or partially works, I also annoyed by it much). But it served the needs of me and my students well enough. If I want an IDE that has code completion really works, I would download Visual Studio Community. The only downside of that is that thing is too bloated for the computers on our school to run it smoothly  >:(

Please don't follow CodeLite. CodeLite starting utilizing LSP, then today they make LSP the default method of code completion. And who knows someday they would rely completely on LSP and abandon their own code completion?

At least, make the LSP plugin not installed or enabled by default and let the users to install or turn it on as a fallback option when the standard CodeBlocks' code completion doesn't suite their needs.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13007
    • Travis build status
Re: an easy cpp language-server-protocol client(C++)
« Reply #9 on: December 13, 2020, 01:09:49 pm »
Please don't follow CodeLite. CodeLite starting utilizing LSP, then today they make LSP the default method of code completion. And who knows someday they would rely completely on LSP and abandon their own code completion?

At least, make the LSP plugin not installed or enabled by default and let the users to install or turn it on as a fallback option when the standard CodeBlocks' code completion doesn't suite their needs.
Unfortunately LSP is the path forward for CC in codeblocks.
I see no one actively maintaining the parser and it is lagging a lot at the moment.
Also given the features introduced in C++ with every new standard - it would be pretty hard task to keep it updated given our resources.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline gh_origin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: an easy cpp language-server-protocol client(C++)
« Reply #10 on: December 13, 2020, 02:37:58 pm »
Please don't follow CodeLite. CodeLite starting utilizing LSP, then today they make LSP the default method of code completion. And who knows someday they would rely completely on LSP and abandon their own code completion?

At least, make the LSP plugin not installed or enabled by default and let the users to install or turn it on as a fallback option when the standard CodeBlocks' code completion doesn't suite their needs.
Unfortunately LSP is the path forward for CC in codeblocks.
I see no one actively maintaining the parser and it is lagging a lot at the moment.
Also given the features introduced in C++ with every new standard - it would be pretty hard task to keep it updated given our resources.

I understand. Indeed, I don't care much. But my impression of LSP (the first experience) on CodeLite is it's just not work. So I prefer to be careful, not jumping to LSP by default too fast like CodeLite. But if CodeBlocks could get LSP working right, then who care if it's the standard code completion or LSP being used? Man, if you could get LSP working and CodeBlocks could have a code completion as good as VSCode (never used this editor, only saw on youtube videos), I support you with my whole heart.

Offline gh_origin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: an easy cpp language-server-protocol client(C++)
« Reply #11 on: December 13, 2020, 02:52:12 pm »
Why a full language server (clangd, ccls,...) but not only libclang? This IDE utilizes only libclang and some other individual tools (ctags, clang-format,...) but not a full language server, and it code completion IMHO is very good. Only tried it on Linux, but it supports Windows via MSYS2, too. BTW, it also supports language servers, but for other languages, not C++.

https://gitlab.com/cppit/jucipp

Could we learn from it? I really really don't trust language server. My experience with CodeLite was too bad.

Online BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2863
Re: an easy cpp language-server-protocol client(C++)
« Reply #12 on: December 13, 2020, 04:51:24 pm »
With language server you get a lot languages for free....
with clang you have only c/c++

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13007
    • Travis build status
Re: an easy cpp language-server-protocol client(C++)
« Reply #13 on: December 13, 2020, 07:19:14 pm »
With language server you get a lot languages for relatively cheap....
I've corrected this for you :)
From what I've seen the LSP client needs non-trivial changes for every LSP server. For VS.code it is easy, because they write everything in *script.

@gh_origin: I don't understand why you whine so much about some future C::B change based on 10 minute experience with another program. Calm down please. Also given you don't work on massive projects clangd would be quite an improvement for the "hello world" student type of projects. Especially if you pair clangd with clang and not gcc/mingw.

Also suggesting some other ways to do it doesn't help. Given the amount of work needed to do them is higher than LSP client. Also nothing stops anyone from porting the current CC to be a LSP server. Read this https://langserver.org/ for the idea behind LSP.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline gh_origin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: an easy cpp language-server-protocol client(C++)
« Reply #14 on: December 14, 2020, 03:58:47 pm »
With language server you get a lot languages for free....
with clang you have only c/c++

Which language does CodeBlocks being IDE for? C/C++.
Unless you want to be both an JavaScript, NodeJS and PHP IDE as CodeLite.

Offline gh_origin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: an easy cpp language-server-protocol client(C++)
« Reply #15 on: December 14, 2020, 04:00:21 pm »
@gh_origin: I don't understand why you whine so much about some future C::B change based on 10 minute experience with another program. Calm down please. Also given you don't work on massive projects clangd would be quite an improvement for the "hello world" student type of projects. Especially if you pair clangd with clang and not gcc/mingw.

Also suggesting some other ways to do it doesn't help. Given the amount of work needed to do them is higher than LSP client. Also nothing stops anyone from porting the current CC to be a LSP server. Read this https://langserver.org/ for the idea behind LSP.

Please pardon me for my stupidity but why don't just copy JuCiPP's code? It's all open source after all.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13007
    • Travis build status
Re: an easy cpp language-server-protocol client(C++)
« Reply #16 on: December 14, 2020, 05:18:58 pm »
Which language does CodeBlocks being IDE for? C/C++.
Unless you want to be both an JavaScript, NodeJS and PHP IDE as CodeLite.
Rust...

Please pardon me for my stupidity but why don't just copy JuCiPP's code? It's all open source after all.
Because I don't want to do it.
There is a phase in the product development called maintenance. It is quite annoying and time consuming part and we have enough to do.
Going against the industry for a small team/project is not a good idea.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline gh_origin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: an easy cpp language-server-protocol client(C++)
« Reply #17 on: December 20, 2020, 08:54:53 am »
Which language does CodeBlocks being IDE for? C/C++.
Unless you want to be both an JavaScript, NodeJS and PHP IDE as CodeLite.
Rust...

Please pardon me for my stupidity but why don't just copy JuCiPP's code? It's all open source after all.
Because I don't want to do it.
There is a phase in the product development called maintenance. It is quite annoying and time consuming part and we have enough to do.
Going against the industry for a small team/project is not a good idea.

It's sad but you are right. Even Eclipse CDT now is going for Clangd. LSP is indeed the future of code completion  :(

Offline gh_origin

  • Multiple posting newcomer
  • *
  • Posts: 48
Re: an easy cpp language-server-protocol client(C++)
« Reply #18 on: December 20, 2020, 09:12:14 am »
I don't know why but I have much less troubles using CodeBlocks on Linux. CodeLite, too. It code completion basically works on Linux. I have no idea why CodeLite's code completion not work on Windows. So my first bad impression of LSP with CodeLite on Windows was wrong.

Maybe Linux is just a better C++ development environment than Windows. I'm working with my personal project for fun with CodeBlocks on Linux  :)