Author Topic: clangd code completion  (Read 8187 times)

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
clangd code completion
« on: October 11, 2024, 07:38:40 am »
hello, first time here.
I followed the wiki page to enable the Clangd plugin, but the code completion is not working.
Is there something I am missing?
I'm using build 13539 on windows.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7696
    • My Best Post
Re: clangd code completion
« Reply #1 on: October 11, 2024, 03:03:16 pm »
These directions? https://wiki.codeblocks.org/index.php/CB_Clangd_Client

Which compiler toolchain did you install/use?
Which clangd did you install/use?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #2 on: October 11, 2024, 07:22:59 pm »
thx for the reply.
yes, I use the LLVM win64.exe one.
I'm not sure what compiler toolchain you mentioned means, but if it's compiler used in cb, it's gnu gcc compiler.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7696
    • My Best Post
Re: clangd code completion
« Reply #3 on: October 11, 2024, 10:22:24 pm »
thx for the reply.
yes, I use the LLVM win64.exe one.
I'm not sure what compiler toolchain you mentioned means, but if it's compiler used in cb, it's gnu gcc compiler.

Without knowing the compiler toolchain you are using I cannot help you.
And, I feel too bad today to explain where to find the info.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2813
Re: clangd code completion
« Reply #4 on: October 12, 2024, 03:24:16 am »
hello, first time here.
I followed the wiki page to enable the Clangd plugin, but the code completion is not working.
Is there something I am missing?
I'm using build 13539 on windows.

I'll try to help here. But first, let me come up with some questions that will put us on the same page to determine what you mean by "is not working". We need some clues.
I'll reply tomorrow.

Thanks for your patients.
« Last Edit: October 12, 2024, 06:35:19 am by Pecan »

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #5 on: October 12, 2024, 12:30:47 pm »
thx for the reply.

When I type 3 letters, the classic code completion will list the possible candidates. By "not working", I mean that the list will not show.

Offline Михаил Агарков

  • Multiple posting newcomer
  • *
  • Posts: 22
  • Highly sensitive programmer. ☮☯
    • Website
Re: clangd code completion
« Reply #6 on: October 12, 2024, 01:35:54 pm »
thx for the reply.
yes, I use the LLVM win64.exe one.
I'm not sure what compiler toolchain you mentioned means, but if it's compiler used in cb, it's gnu gcc compiler.

Run these commands:
Code
clangd --version
Code
gcc --version
to get the versions.

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #7 on: October 12, 2024, 02:57:34 pm »

Run these commands:
Code
clangd --version
Code
gcc --version
to get the versions.

thx for the reply.
the clangd version is 18.1.8
as for the gcc version, I don't know why the terminal says it can't identify "gcc". If I don't have it, how did I compile in cb?

Offline Михаил Агарков

  • Multiple posting newcomer
  • *
  • Posts: 22
  • Highly sensitive programmer. ☮☯
    • Website
Re: clangd code completion
« Reply #8 on: October 12, 2024, 03:13:30 pm »

Run these commands:
Code
clangd --version
Code
gcc --version
to get the versions.

thx for the reply.
the clangd version is 18.1.8
as for the gcc version, I don't know why the terminal says it can't identify "gcc". If I don't have it, how did I compile in cb?

GCC used by C::B is located in settings (see screenshot), did you install GCC seperately or did you install C::B bundled with it?

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #9 on: October 12, 2024, 03:55:56 pm »

GCC used by C::B is located in settings (see screenshot), did you install GCC seperately or did you install C::B bundled with it?

thx for the reply.

I install cb with the compiler.

Offline Михаил Агарков

  • Multiple posting newcomer
  • *
  • Posts: 22
  • Highly sensitive programmer. ☮☯
    • Website
Re: clangd code completion
« Reply #10 on: October 12, 2024, 04:03:46 pm »

GCC used by C::B is located in settings (see screenshot), did you install GCC seperately or did you install C::B bundled with it?

thx for the reply.

I install cb with the compiler.

Go to C:\Program Files\CodeBlocks\MinGW\bin and run:
Code
gcc --version

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #11 on: October 12, 2024, 04:17:37 pm »

Go to C:\Program Files\CodeBlocks\MinGW\bin and run:
Code
gcc --version

thx for the reply.
It's 8.1.0

Offline Михаил Агарков

  • Multiple posting newcomer
  • *
  • Posts: 22
  • Highly sensitive programmer. ☮☯
    • Website
Re: clangd code completion
« Reply #12 on: October 12, 2024, 04:21:15 pm »

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #13 on: October 12, 2024, 04:46:13 pm »
I think your problem might be the same as in https://forums.codeblocks.org/index.php/topic,24357.msg169412.html#msg169412

thx for the reply.

so my clangd.exe is in "C:\Program Files\LLVM\bin\clangd.exe"
is that the problem? how do I fix it, like how do i get the file in the right path?

Offline Михаил Агарков

  • Multiple posting newcomer
  • *
  • Posts: 22
  • Highly sensitive programmer. ☮☯
    • Website
Re: clangd code completion
« Reply #14 on: October 12, 2024, 05:21:12 pm »
AFAIK you need to use MSYS2 and install GCC and Clang together in the same environment and use "mingw-w64-clang-x86_64-clang-tools-extra" for it to work properly.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2813
Re: clangd code completion
« Reply #15 on: October 12, 2024, 11:49:07 pm »
I think your problem might be the same as in https://forums.codeblocks.org/index.php/topic,24357.msg169412.html#msg169412

thx for the reply.

so my clangd.exe is in "C:\Program Files\LLVM\bin\clangd.exe"
is that the problem? how do I fix it, like how do i get the file in the right path?

What have you got set at MainMenu/settings/Editor/Clangd_client/C/C++ parser (tab) as the path to clangd.exe ?

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #16 on: October 13, 2024, 03:15:27 am »
I think your problem might be the same as in https://forums.codeblocks.org/index.php/topic,24357.msg169412.html#msg169412

thx for the reply.

so my clangd.exe is in "C:\Program Files\LLVM\bin\clangd.exe"
is that the problem? how do I fix it, like how do i get the file in the right path?

What have you got set at MainMenu/settings/Editor/Clangd_client/C/C++ parser (tab) as the path to clangd.exe ?

thx for the reply.

it's "C:\Program Files\LLVM\bin\clangd.exe".


AFAIK you need to use MSYS2 and install GCC and Clang together in the same environment and use "mingw-w64-clang-x86_64-clang-tools-extra" for it to work properly.

that is a method listed on the wiki. And so is the LLVM one. They are both supposed to work right...?

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2813
Re: clangd code completion
« Reply #17 on: October 13, 2024, 06:29:40 am »

so my clangd.exe is in "C:\Program Files\LLVM\bin\clangd.exe"
thx for the reply.

it's "C:\Program Files\LLVM\bin\clangd.exe".

that is a method listed on the wiki. And so is the LLVM one. They are both supposed to work right...?

I'm going to guess the problem is caused by the space in "Program Files".

Clangd is essentially a Linux program which cannot handle spaces in file names.

We now need to determine if that is actually the problem.

First: Tell us how you start CodeBlocks so that we can then tell you how to turn the clangd_client logs on.

Then we can read the log to see what Clangd_client thinks the problem is.

Thanks for your patients.
« Last Edit: October 13, 2024, 06:40:06 am by Pecan »

Offline wtfisgoingoff

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: clangd code completion
« Reply #18 on: October 13, 2024, 09:11:49 am »

so my clangd.exe is in "C:\Program Files\LLVM\bin\clangd.exe"
thx for the reply.

it's "C:\Program Files\LLVM\bin\clangd.exe".

that is a method listed on the wiki. And so is the LLVM one. They are both supposed to work right...?

I'm going to guess the problem is caused by the space in "Program Files".

Clangd is essentially a Linux program which cannot handle spaces in file names.

We now need to determine if that is actually the problem.

First: Tell us how you start CodeBlocks so that we can then tell you how to turn the clangd_client logs on.

Then we can read the log to see what Clangd_client thinks the problem is.

Thanks for your patients.

Does  clangd code completion  list  those keywords  candidates ?   [ for while switch ...
The classic code completion dose. When I using classic code completion, after I typing  whi the whole while will be listed .  This happens to [for switch .. ] too.
But when I using clang_client,  I have to type whole switch [for while] by myself. 


default compiler: GNU GCC Compiler (msys2/ucrt64/bin/)
my projects' path has no spaces
Specify clangd executable to use: msys2/ucrt64/bin/cland.exe
gcc -v:          gcc version 14.2.0 (Rev1, Built by MSYS2 project)
clang -version: 18.1.8 

my settings  [attachments]

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #19 on: October 13, 2024, 10:07:46 am »


I'm going to guess the problem is caused by the space in "Program Files".

Clangd is essentially a Linux program which cannot handle spaces in file names.

We now need to determine if that is actually the problem.

First: Tell us how you start CodeBlocks so that we can then tell you how to turn the clangd_client logs on.

Then we can read the log to see what Clangd_client thinks the problem is.

Thanks for your patients.

thx for the reply.

So I unzip the 3 .7z file (CB_20240807_rev13539_win64, wxmsw32u_gcc_cb_wx325_2D_gcc1410-mingw64, Mingw64dlls14.1.0)
 into the same folder and start codeblocks.exe in it.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2813
Re: clangd code completion
« Reply #20 on: October 13, 2024, 06:11:00 pm »
thx for the reply.

So I unzip the 3 .7z file (CB_20240807_rev13539_win64, wxmsw32u_gcc_cb_wx325_2D_gcc1410-mingw64, Mingw64dlls14.1.0)
 into the same folder and start codeblocks.exe in it.

So I guess you start Codeblocks by just typing "Codeblocks" or "Codeblocks.exe".

Good, so from now on type "codeblocks /d" to turn on the codeblocks debugger tab at the bottom.

Then go to Settings/Editor/clangd_client/ C/C++ parser(adv.)
Enable check boxes entitled "Enable plugin info logging" and "Enable plugin Debug logging".

Close CodeBlocks and restart it with the /d parameter to turn on those logs.

Load a project you'd normally load for editing.
Wait until the "Code::Blocks Debug" tab at the bottom stops scrolling information.

Right click on the "Code::Blocks Debug" tab at the bottom and choose "Copy contents to clipboard".

Now choose from the main menu, File/New/EmptyFile and say no if asked to add the file to the project.

Select and move the mouse into that empty file and paste into it (ctrl-z key). You should see the log now pasted into that empty editor file.

Save that file to %tmp%/Juxin5ClangdLog.txt, (or any folder that's convenient to you). %tmp% is the same as your C:\Temp  or C:/tmp folder.

Zip it up so that you can attach it to a reply to this message.

Thanks for your patients.
And forgive me if I insult your intelligence.
« Last Edit: October 13, 2024, 06:28:47 pm by Pecan »

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #21 on: October 14, 2024, 08:18:43 am »

So I guess you start Codeblocks by just typing "Codeblocks" or "Codeblocks.exe".

Good, so from now on type "codeblocks /d" to turn on the codeblocks debugger tab at the bottom.

Then go to Settings/Editor/clangd_client/ C/C++ parser(adv.)
Enable check boxes entitled "Enable plugin info logging" and "Enable plugin Debug logging".

Close CodeBlocks and restart it with the /d parameter to turn on those logs.

Load a project you'd normally load for editing.
Wait until the "Code::Blocks Debug" tab at the bottom stops scrolling information.
...



thx for the reply.

I think I found where the problem is. A project needed to be loaded for the clangd client to work properly. When only open the .cpp file, it will give the following error:

Code
GetLSPclient: param pProject is missing

attached file is the log when loading single file.

I'm not sure if it's intended behavior but either way it's not convenient for me because sometimes I just want to edit a single file. Also classic code completion would work fine in such scenario.

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #22 on: October 14, 2024, 08:23:27 am »
I forgot to say that clangd does work fine when I load a project, meaning the code completion works fine, while also has the issue user "wtfisgoingoff" mentioned.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2813
Re: clangd code completion
« Reply #23 on: October 14, 2024, 04:33:22 pm »
I forgot to say that clangd does work fine when I load a project, meaning the code completion works fine, while also has the issue user "wtfisgoingoff" mentioned.

This guy has got to be a troll. He has wasted a lot of good peoples time.

He said in the beginning that Clangd_client didn't work, now he says it worked fine all along.

hello, first time here.
I followed the wiki page to enable the Clangd plugin, but the code completion is not working.
Is there something I am missing?
I'm using build 13539 on windows.
« Last Edit: October 14, 2024, 04:35:32 pm by Pecan »

Offline juxin5

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: clangd code completion
« Reply #24 on: October 14, 2024, 08:34:49 pm »

He said in the beginning that Clangd_client didn't work, now he says it worked fine all along.

have you really read what I said? It does not work when I open files without a project.

You really think it works fine when it literally works worse than the classic code completion in this scenario?