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

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Code completion using LSP and clangd
« Reply #390 on: April 07, 2024, 06:18:16 pm »
- "Find declaration of: ..." does not work for me.
- "Reparse this project" has become a must so that the menu entry "Find declaration of: ..." appears.

What is going wrong ?

OS : Windows 7 with SP1 x64
C::B : Nightly build 13496
clangd : 18.1.2

Not enough info.
Can you give us a simple example (code) to recreate the problem?
What steps can we perform to recreate the problem?

Here is my C::B project
Note that if I revert to using Code Completion back, then "Find declaration of: ..." starts working as expected.

@tomay3000
Thanks for providing the source.

Responses from Clangd are dependent on the symbols produced by the compiler being used.

Your project is using what looks like a 32 bit mingw compiler.
Where did you obtain that compiler so I can mirror your environment.

Using my default gcc 64 bit compiler gets a slew of compiler errors which means I won't get the same errors you do.

Also, what declaration are you trying to display so I can attempt to mimic the error.

Offline tomay3000

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Code completion using LSP and clangd
« Reply #391 on: April 08, 2024, 06:55:47 am »
- "Find declaration of: ..." does not work for me.
- "Reparse this project" has become a must so that the menu entry "Find declaration of: ..." appears.

What is going wrong ?

OS : Windows 7 with SP1 x64
C::B : Nightly build 13496
clangd : 18.1.2

Not enough info.
Can you give us a simple example (code) to recreate the problem?
What steps can we perform to recreate the problem?

Here is my C::B project
Note that if I revert to using Code Completion back, then "Find declaration of: ..." starts working as expected.

@tomay3000
Thanks for providing the source.

Responses from Clangd are dependent on the symbols produced by the compiler being used.

Your project is using what looks like a 32 bit mingw compiler.
Where did you obtain that compiler so I can mirror your environment.

Using my default gcc 64 bit compiler gets a slew of compiler errors which means I won't get the same errors you do.

Also, what declaration are you trying to display so I can attempt to mimic the error.
The compiler I am using is: https://github.com/tomay3000/mingw-builds-binaries/releases/download/13.2.0-rt_v11-rev1/i686-13.2.0-release-posix-sjlj-ucrt-rt_v11-rev1.7z

Any declaration gives an error.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Code completion using LSP and clangd
« Reply #392 on: April 09, 2024, 06:30:42 am »
@ tomay3000

I'll install that compiler and see what's going on.

BTW: what clangd.exe did you setup in Clangd_client and where can I get it to also mirror your environment?

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Code completion using LSP and clangd
« Reply #393 on: April 09, 2024, 07:48:48 pm »
Hello sir, I tried to install your plugin but the plugin gets disabling upon resart. I am following this https://wiki.codeblocks.org/index.php/CB_Clangd_Client#Windows:_Compiler_Clangd.2FLLVM_Package_Installerguide.

I installed a nightly build of Code blocks, from 16th December 2023.
And downloaded,installed clang.exe with the following command: "pacman -S mingw-w64-clang-x86_64-clang-tools-extra".
And disabled the "code completion" plugin, then enabled "Clangd_Client".
Set my default compiler to clang.exe in code blocks compiler setting.

But after restarting code blocks, clangd_client remains disabled and there is no option of "clangd_client" on the left of editor settings.
I am not sure if following ONLY the "Configuring clangd_client" and "Windows: Compiler Clangd/LLVM Package Installer" section of the guide has led to this error or am I misinterpreting the instruction about setting a compiler before restarting.

I've moved this message here from personal msgs so that we all can proffer from the solution.
 @ kakas

I'd suggest that you uninstall (or remove) that old nightly 16 December 2023 and install this the April 1, 2024 version instead since it has many additions and fixes over last years version.
https://forums.codeblocks.org/index.php/topic,25755.msg175319.html#msg175319

You don't actually "install" it. You just download and unzip the three zips into a newly made folders.
cbNightly   <-- new main nightly folder
  codeblocks <-- contains all the codeblocks zips except the compiler zip.
  mngw64    <-- contains the compiler contents

Start a command session click the windows key then type "cmd" and enter key.
From with the cmd window "cd cbNightly\codeblocks
Type: codeblocks.exe /d
Question: Does codeblocks show ok?
If so, Check that the compilers tool chain is set to the download mingw64 executables.
Click mainMenu/Settings/Compiler/Toolchain executables
See second image below.
 
Please excuse me if I insult your intelligents. I just want to get the basics out of the way so we have approximately the same setup to work with.

A few questions so I can get a picture of your system setup.
1) Are you actually compiling with Clang.exe or with mingw64 or mingw32.
2) Do you work in 32 bit C++ or 64bit C++ ?
3) After installing the nightly, click on mainmenu/plugins/manage plugins.
Is clangd_client listed. See image below.
Is codecompletion disabled? Is clangd_client enabled?
« Last Edit: April 09, 2024, 08:41:49 pm by Pecan »

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 23
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #394 on: April 09, 2024, 08:23:11 pm »
 :D thank you for the reassuring reply.
about the issue. There's another thing I would like to add.
when enabling the the plugin, A pop up message appears on the bottom right of the screen.
« Last Edit: April 09, 2024, 08:32:55 pm by kakas »

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 23
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #395 on: April 09, 2024, 08:31:19 pm »
A few questions so I can get a picture of your system setup.
1) Are you actually compiling with Clang.exe or with mingw64 or mingw32.
2) Do you work in 32 bit C++ or 64bit C++ ?
3) After installing the nightly, click on mainmenu/plugins/manage plugins.
Is clangd_client listed. See image below.
Is codecompletion disabled? Is clangd_client enabled?

1) My default compiler is mingw64
2) I am not really sure what this means(but I use 64 bit version of everything whenever possible, just cuz of the paranoia that things might not work, I also have built for only 64bit systems)
3) Yes it's same as displayed in the image
(about the nightly build, I haven't tried April 1st built yet.)
« Last Edit: April 09, 2024, 08:57:46 pm by kakas »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Code completion using LSP and clangd
« Reply #396 on: April 09, 2024, 08:49:00 pm »
Something happened and I lost this post.
So I'm reposting.

Hello sir, I tried to install your plugin but the plugin gets disabling upon resart. I am following this https://wiki.codeblocks.org/index.php/CB_Clangd_Client#Windows:_Compiler_Clangd.2FLLVM_Package_Installerguide.

I installed a nightly build of Code blocks, from 16th December 2023.
And downloaded,installed clang.exe with the following command: "pacman -S mingw-w64-clang-x86_64-clang-tools-extra".
And disabled the "code completion" plugin, then enabled "Clangd_Client".
Set my default compiler to clang.exe in code blocks compiler setting.

But after restarting code blocks, clangd_client remains disabled and there is no option of "clangd_client" on the left of editor settings.
I am not sure if following ONLY the "Configuring clangd_client" and "Windows: Compiler Clangd/LLVM Package Installer" section of the guide has led to this error or am I misinterpreting the instruction about setting a compiler before restarting.

I've moved this message here from personal msgs so that we all can proffer from the solution.
 @ kakas

I'd suggest that you uninstall (or remove) that old nightly 16 December 2023 and install this the April 1, 2024 version instead since it has many additions and fixes over last years version.
https://forums.codeblocks.org/index.php/topic,25755.msg175319.html#msg175319

You don't actually "install" it. You just download and unzip the three zips into a newly made folders.
cbNightly   <-- new main nightly folder
  codeblocks <-- contains all the codeblocks zips except the compiler zip.
  mngw64    <-- contains the compiler contents

Start a command session click the windows key then type "cmd" and enter key.
From with the cmd window "cd cbNightly\codeblocks
Type: codeblocks.exe /d
Question: Does codeblocks show ok?
If so, Check that the compilers tool chain is set to the download mingw64 executables.
Click mainMenu/Settings/Compiler/Toolchain executables
See second image below.
 
Please excuse me if I insult your intelligents. I just want to get the basics out of the way so we have approximately the same setup to work with.

A few questions so I can get a picture of your system setup.
1) Are you actually compiling with Clang.exe or with mingw64 or mingw32.
2) Do you work in 32 bit C++ or 64bit C++ ?
3) After installing the nightly, click on mainmenu/plugins/manage plugins.
Is clangd_client listed. See image below.
Is codecompletion disabled? Is clangd_client enabled?
« Last Edit: April 09, 2024, 08:50:59 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Code completion using LSP and clangd
« Reply #397 on: April 09, 2024, 08:52:57 pm »
A few questions so I can get a picture of your system setup.
1) Are you actually compiling with Clang.exe or with mingw64 or mingw32.
2) Do you work in 32 bit C++ or 64bit C++ ?
3) After installing the nightly, click on mainmenu/plugins/manage plugins.
Is clangd_client listed. See image below.
Is codecompletion disabled? Is clangd_client enabled?

1) My default compiler is mingw64
2) 64bit C++ (I use 64 bit version of everything whenever possible, just cuz of the paranoia that things might not work)
3) Yes it's same as displayed in the image
(about the nightly build, I haven't tried April 1st built yet.)

Good , then we're both on the same page.
So now, remove the old December CodeBlocks and download the April one as noted in my last post.
We'll start from there to straighten thing out.

Oh, BTW be sure to close and restart CB after disabling CodeCompletion and re-enabling Clangd_client.
Else all sorts of weirdness happens.
« Last Edit: April 09, 2024, 08:58:01 pm by Pecan »

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 23
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #398 on: April 09, 2024, 09:14:46 pm »
hmm. I haven't actually moved the compiler inside the code blocks folder(the one that I made for nightly build). will it have any effect?
(my compile is in, C:\msys64\mingw64\bin)

I Installed the April 1st build.
I disabled "Code_Completion" and than enabled "Clangd_Client".
closed Code Blocks. restarted it again.
open up plugin manager.
And see "Clangd_Client" is disabled.
Basically no difference

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Code completion using LSP and clangd
« Reply #399 on: April 10, 2024, 07:26:23 am »
hmm. I haven't actually moved the compiler inside the code blocks folder(the one that I made for nightly build). will it have any effect?
(my compile is in, C:\msys64\mingw64\bin)

I Installed the April 1st build.
I disabled "Code_Completion" and than enabled "Clangd_Client".
closed Code Blocks. restarted it again.
open up plugin manager.
And see "Clangd_Client" is disabled.
Basically no difference

Your compiler is just fine where it is.
But for the time being lets use the one in the April 1 nightly so we both are in sync with each other.
You can change it later if you wish.

The Clangd_client is not enabling itself because CB did not find a default compiler. Go to mainMenu/Setting/Compiler/Toolchain executable and set the compiler location as show in the second image below but using your compiler location of course.

Restart CB and you'll see that Clangd_client is now enabled.

Go to mainMenu/Settings/Editor/Clangd_client/C/C++ parser (the second tab) and  put the location of your ...\msys64\mingw64\bin\clangd.exe into the "specify clangd executable to use" search slot. Click ok at bottom.
See the first image below.
Close and restart CB.


Important:
You have to use the clangd.exe under the mingw64 folder. Not the clang64 folder.
Using the wrong clangd.exe is what was causing all the diagnostic errors.

Now do us a favor. Open a cmd window and cd to the folder that contains your ...\msys64\mingw64\bin\clangd.exe and type: (without the quotes)
"clangd.exe --version" and tell us what it printed.
Also type: "c++.exe --version" and tell us what it printed.

Regards
« Last Edit: April 10, 2024, 07:51:31 am by Pecan »

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 23
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #400 on: April 10, 2024, 08:11:43 am »
Important:
You have to use the clangd.exe under the mingw64 folder. Not the clang64 folder.
Using the wrong clangd.exe is what was causing all the diagnostic errors.

oh I think this is causing the problem. I have no clangd.exe or clang.exe in my mingw64 folder. It's only present in clang64 folder.
Is there another command that I should be running from the msys terminal to download the correct clangd.exe? because I remember running only a single command from the guide.

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 23
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #401 on: April 10, 2024, 09:28:47 am »
ran the other command from the guide "pacman -S mingw-w64-x86_64-clang-tools-extra" which downloaded the executables to mingw64 folder instead of clang64.
sorry I got mixed up by the commands in the guide at first (attached screenshot of command prompt showing version details of clangd.exe and c++.exe)

Went through the enabling plugin procedure again to see if it fixed the issue. But no pogress.

Despite the "To run Clangd_Client, restart CodeBlocks after setting up a compiler...." error,
Code blocks seems to compile files just fine. Compiler installation directory(contains clangd.exe and clang.exe) C:\msys64\mingw64.
So I am not sure if the problem comes from CB not finding a default compiler.

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 23
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #402 on: April 10, 2024, 09:40:46 am »
Your compiler is just fine where it is.
But for the time being lets use the one in the April 1 nightly so we both are in sync with each other.
You can change it later if you wish.

???
wait a minute. the zip file of the nightly build(from 1st April) that I downloaded didn't had any compiler in it, just a folder named "shared"
« Last Edit: April 10, 2024, 10:26:10 am by kakas »

Offline kakas

  • Multiple posting newcomer
  • *
  • Posts: 23
  • potatoes are tasty(not the raw ones)
Re: Code completion using LSP and clangd
« Reply #403 on: April 10, 2024, 10:24:19 am »
SOLVEDDD

I had to set the default compiler to *No-compiler*
before enabling or disabling any plugin.

this time(having no-compiler as default) it didn't gave the error pop-up on the bottom right when enabling the Clangd_Client plugin, but said CB needs to restart for the plugin to function properly.

After setting up the clangd.exe path in the editor settings and restarting again, the plugin works. And it's awesome  ;D ;D ;D
« Last Edit: April 10, 2024, 10:28:55 am by kakas »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: Code completion using LSP and clangd
« Reply #404 on: April 10, 2024, 05:43:01 pm »
Your compiler is just fine where it is.
But for the time being lets use the one in the April 1 nightly so we both are in sync with each other.
You can change it later if you wish.

???
wait a minute. the zip file of the nightly build(from 1st April) that I downloaded didn't had any compiler in it, just a folder named "shared"

Actually, there is a URL on the Nightly announcement that can be used to download the compiler that was used to make the Nightly CodeBlocks.

But you've solved your setup problems already.
Thanks for your patience and your persistence.
This has informed me on what can go awry and how to improve the instructions on setting up Clangd_client.

You might want to go through the list of plugins (mainmenu/plugins/manage plugins) and disable or uninstall the plugins that you do not use.  It'll unclutter your logs section.

If you haven't found it yet, the "LSP messages" tab in the  log section is the one that contains the output from Clangd/Clangd_client  and may have suggestions on how to correct syntax or symbol references.
If you see a message that contains "(fix available)" you can right-mouseClick on the message and apply the fix automatically if you agree with the suggested fix.

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.
But you might have to update to mingw64/clangd.exe version 18 (when it becomes available in msys64) before you can take full advantage of this.

Regards
« Last Edit: April 10, 2024, 06:14:26 pm by Pecan »