Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Code completion using LSP and clangd

<< < (62/85) > >>

Pecan:
@ Trigger
Your fix applied in head rev 13271. Thanks.

Pecan:
Continuation of discussion from:
https://forums.codeblocks.org/index.php/topic,25383.msg173164.html#msg173164


--- Quote from: myztmy on June 07, 2023, 10:13:11 am ---
--- Quote from: Pecan on June 07, 2023, 06:45:52 am ---Can you write a short example that we can use to re-create your problems?
For me, clangd_client does indeed provide the info you are having problems with.
With an example from you, we might be able to either show you how to get the info, or fix the problem.

--- End quote ---

My os is win7 , clangd.exe is  from latest version LLVM-16.0.5-win64 which  full installed ,compiler is winlibs-x86_64-mcf-seh-gcc-13.1.0-mingw-w64ucrt-11.0.0-r1,no msys . In CB , compiler settings is right  ,  search directories  is right .

My Project to test  clangd_client  is simplest  "hello world" , add several varialbes and simple classes , the program is normally compiling and running . clangd_client can jump to class( I defines myself) declaration and implementation rightly.  But  it  don't  give the right hint of member funtions , and a varialbe of string type it give a hint that is a int type.

if there is any setting and step I omit please instruct me .

Below is a part  info  of LSP messages

--- Code: ---LSP diagnostics: main.cpp|:|----Time: 15:16:19.218---- (5 diagnostics)|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|1|note:'iostream' file not found|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|8|warning:Using directive refers to implicitly-defined namespace 'std'|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|12|note:Unknown type name 'string'|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|25|note:Use of undeclared identifier 'cout'|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|25|note:Use of undeclared identifier 'endl'|
LSP diagnostics: Test1.h|:|----Time: 15:16:20.533---- (0 diagnostics)|
LSP diagnostics: Test.h|:|----Time: 15:16:21.815---- (0 diagnostics)|
LSP diagnostics: Test.cpp|:|----Time: 15:16:22.844---- (4 diagnostics)|
E:\workspace\testcode\test1\HelloMingw64\src\Test.cpp|2|note:'iostream' file not found|
E:\workspace\testcode\test1\HelloMingw64\src\Test.cpp|4|warning:Using directive refers to implicitly-defined namespace 'std'|
E:\workspace\testcode\test1\HelloMingw64\src\Test.cpp|18|note:Use of undeclared identifier 'cout'|
E:\workspace\testcode\test1\HelloMingw64\src\Test.cpp|18|note:Use of undeclared identifier 'endl'|
LSP diagnostics: main.cpp|:|----Time: 15:19:41.802---- (5 diagnostics)|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|1|note:'iostream' file not found|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|8|warning:Using directive refers to implicitly-defined namespace 'std'|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|12|note:Unknown type name 'string'|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|26|note:Use of undeclared identifier 'cout'|
E:\workspace\testcode\test1\HelloMingw64\main.cpp|26|note:Use of undeclared identifier 'endl'|
LSP diagnostics: main.cpp|:|----Time: 15:19:51.121---- (12 diagnostics)|
......
......

--- End code ---

--- End quote ---

@ myztmy

In order to be precise, we'll need you to paste your source code here between code tags. Paste the main.cpp code in your response using the "#" icon  above the face icons. For example the "#" icon produces code tags that look like this:
[ code ] your main.cpp source[/ code ] (without the spaces around "code".
The "#" icon and face icons appear when you  click on the "Reply" or "Quote" buttons.

I see that there are enough compile errors and warnings that it would confuse clangd. I think you're missing some #include statements. But we need to see your code first.

Regards

myztmy:

--- Quote from: Pecan on June 07, 2023, 06:26:06 pm ---@ myztmy

In order to be precise, we'll need you to paste your source code here between code tags. Paste the main.cpp code in your response using the "#" icon  above the face icons. For example the "#" icon produces code tags that look like this:
[ code ] your main.cpp source[/ code ] (without the spaces around "code".
The "#" icon and face icons appear when you  click on the "Reply" or "Quote" buttons.

I see that there are enough compile errors and warnings that it would confuse clangd. I think you're missing some #include statements. But we need to see your code first.

Regards


--- End quote ---
I've been struggling with "clangd"  for a whole day!

With another win7 machine I install "GCC 13.1.0 (with POSIX threads) + LLVM/Clang/LLD/LLDB 16.0.5 + MinGW-w64 11.0.0 (UCRT) - release 5" which Clang and Mingw are in the same  bin directory . This time , "clangd" can find the standard lib header files , add a string type variable it can identify the correct type and give the right hint. But it just made me happy for a few seconds. After using class wizzard add a simple class , clangd don't konw the new class and then don't give correct hint ,everything has become a mess again.

Go back to my MinGW-w64 and LLVM separate installation win7 machine , I try to throw clangd.exe into MinGW-w64 bin directory ,  the C::B always Pop up dialog box complain "can't dectect clangd.exe" . Placing clangd.exe in any other directory is no problem. In this machine clangd  although can find user class but can't find standard lib class, also not working properly.

Most of the existing bugs now of "clangd"  also existed  in  "Code completion" of C::B(win) 20.03 release ,  but the latest nightly builds version have fixed "Code completion" almost all bugs except freeze  (I only have used C::B for ten days, and only tested those two C::B versions ). "clangd" seems like "Yesterday Once More" . I guess "clangd" has referenced some code from "Code completion" of older versions. 

Now that you mention "#", let me show you a "funny" image(I really know what you mean ,but the imge explains everything, I don't think I need use "#" icon to post my so simplest source code :P ).

Regards

 

Pecan:

--- Quote from: myztmy on June 09, 2023, 09:53:36 am ---I've been struggling with "clangd"  for a whole day!

With another win7 machine I install "GCC 13.1.0 (with POSIX threads) + LLVM/Clang/LLD/LLDB 16.0.5 + MinGW-w64 11.0.0 (UCRT) - release 5" which Clang and Mingw are in the same  bin directory . This time , "clangd" can find the standard lib header files , add a string type variable it can identify the correct type and give the right hint. But it just made me happy for a few seconds. After using class wizzard add a simple class , clangd don't konw the new class and then don't give correct hint ,everything has become a mess again.

Go back to my MinGW-w64 and LLVM separate installation win7 machine , I try to throw clangd.exe into MinGW-w64 bin directory ,  the C::B always Pop up dialog box complain "can't dectect clangd.exe" . Placing clangd.exe in any other directory is no problem. In this machine clangd  although can find user class but can't find standard lib class, also not working properly.

Most of the existing bugs now of "clangd"  also existed  in  "Code completion" of C::B(win) 20.03 release ,  but the latest nightly builds version have fixed "Code completion" almost all bugs except freeze  (I only have used C::B for ten days, and only tested those two C::B versions ). "clangd" seems like "Yesterday Once More" . I guess "clangd" has referenced some code from "Code completion" of older versions. 

Now that you mention "#", let me show you a "funny" image(I really know what you mean ,but the imge explains everything, I don't think I need use "#" icon to post my so simplest source code :P ).

Regards

--- End quote ---

Since you will not provide us with your code in a form that we can copy and paste in order to re-create the errors, I'm going to step away from this conversation.

clangd cannot correctly provide you with good information when your code is full of errors.
You will have to read the errors provided by clangd and correct your code before popup info is reliable.

Secondly, moving clangd into arbitrary folders is asking for trouble. The clangd_client plugin provides clangd server with both the location of the clangd executable along with the location of its matching resources. Causing a miss match of these locations also causes clangd to issue incorrect info.

Good luck.

myztmy:

--- Quote from: Pecan on June 10, 2023, 07:09:46 pm ---
Since you will not provide us with your code in a form that we can copy and paste in order to re-create the errors, I'm going to step away from this conversation.

clangd cannot correctly provide you with good information when your code is full of errors.
You will have to read the errors provided by clangd and correct your code before popup info is reliable.

Secondly, moving clangd into arbitrary folders is asking for trouble. The clangd_client plugin provides clangd server with both the location of the clangd executable along with the location of its matching resources. Causing a miss match of these locations also causes clangd to issue incorrect info.

Good luck.

--- End quote ---

Following is my codes

main.cpp


--- Code: ---//main.cpp
#include <iostream>
#include "test.h"

using namespace std;

int main()
{
    test t;
    t.SetCounter(100);
    t.GetCounter();
    cout << "Hello world!" << endl;
    return 0;
}

--- End code ---

test.h

--- Code: ---#ifndef TEST_H
#define TEST_H
class test
{
    public:
        test();
        virtual ~test();
        unsigned int GetCounter();
        void SetCounter(unsigned int val);
    protected:
    private:
        unsigned int m_Counter;
};
#endif // TEST_H
--- End code ---

test.cpp

--- Code: ---#include "test.h"

test::test()
{
    //ctor
}

test::~test()
{
    //dtor
}

unsigned int test::GetCounter() { return m_Counter; }
void test::SetCounter(unsigned int val) { m_Counter = val; }

--- End code ---
Please refer to the attached image in my previous post for the project structure ,in fact that image have shown  nealy all code .

I feel very sorry for publishing such simple code too late, but if it is useful to you, I hope it can retain your step 8).

Regards




Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version