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

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2802
Re: Code completion using LSP and clangd
« Reply #315 on: September 25, 2023, 09:54:59 pm »
Well, another question is:

In the suggestion list, does it need an icon for each item?

Here is the screen shot of mine, it looks like I just only have texts in the suggestion list after I press the "dot", see image shot below:

This looks like the .zip resources are missing. The images are in the .zip file. I just don't use them.
We've been using clangd_client for a year or more without icons.
I'd rather not use them if we don't have to.

The assert says that it occured at platwx.cpp 2582. There's no code there.
You might consider rebuilding CodeBlocks and contribs again.
 
« Last Edit: September 25, 2023, 10:06:27 pm by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6023
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #316 on: September 26, 2023, 02:41:12 am »
I see an alert when I enabled the Clangd_client, and when I hit the dot after I type an object name.
Could you copy the Clangd_client from devel32_64 to output32_64 and see if you get the crash again.
This will give us a line number.
The .RPT is useless without a line number.
OK, I will do that. Thanks.

Quote
Also, can you give an example code so I can reproduce the error.
I can't reproduce it yet.

I will try to minimize the project, my project is huge. Currently I can't reproduce this bug easily.  :(
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6023
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #317 on: September 26, 2023, 02:43:37 am »
Well, another question is:

In the suggestion list, does it need an icon for each item?

Here is the screen shot of mine, it looks like I just only have texts in the suggestion list after I press the "dot", see image shot below:

This looks like the .zip resources are missing. The images are in the .zip file. I just don't use them.
We've been using clangd_client for a year or more without icons.
I'd rather not use them if we don't have to.

The assert says that it occured at platwx.cpp 2582. There's no code there.
You might consider rebuilding CodeBlocks and contribs again.

I use C::B for development day by day for many years.  :)

If we have iron shown, I think we can distinguish between member variables and member functions.

About the line 2582 issue, let me rebuild the whole C::B again.



EDIT:

I may have some local patch here for Windows font related issue.

Code
void ListBoxImpl::Append(const wxString& text, int type) {
    long count  = GETLB(wid)->GetItemCount();
    long itemID  = GETLB(wid)->InsertItem(count, wxEmptyString);
    long idx = -1;
    GETLB(wid)->SetItem(itemID, 1, text);
    maxStrWidth = wxMax(maxStrWidth, text.length());
    if (type != -1) {
        wxCHECK_RET(imgTypeMap, wxT("Unexpected NULL imgTypeMap"));
        idx = imgTypeMap->Item(type);
    }
    GETLB(wid)->SetItemImage(itemID, idx, idx);
}

I see the line 2582 is the line above, the line begins with "wxCHECK_RET".
« Last Edit: September 26, 2023, 02:46:51 am by ollydbg »
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: 2802
Re: Code completion using LSP and clangd
« Reply #318 on: September 26, 2023, 07:03:26 am »
@ ollydbg

For me, platwx.cpp liine 2582 is blank.
Head rev 13361

Can you make the problem occur with the -g version of clangd_client.dll ?
It would show us exactly what's happening, even with your modified code.
« Last Edit: September 26, 2023, 07:12:19 am by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2802
Re: Code completion using LSP and clangd
« Reply #319 on: September 26, 2023, 05:41:33 pm »
@ollydbg

Note the code below: has only two calls to Append(...)
The first has a definition that defaults type=-1, and the second, when called, has a hard coded type=-1 (platWX.cpp line:2571) set by SetList() before the calling Append().

So it appears that an additional call has been added to your code that sets type to something other than -1 before calling the first Append(...) which calls the second Append().

Maybe that will help find it.
« Last Edit: September 26, 2023, 05:47:25 pm by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6023
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #320 on: September 27, 2023, 04:54:19 pm »
Oh, thanks for the help. I looked at my local commits, and this is the only change I made to PlatWX.cpp, which I try to enable the font smooth. I don't have other changes to scintilla related code.

Code
diff --git a/src/sdk/wxscintilla/src/PlatWX.cpp b/src/sdk/wxscintilla/src/PlatWX.cpp
index 247b558c..66d64375 100644
--- a/src/sdk/wxscintilla/src/PlatWX.cpp
+++ b/src/sdk/wxscintilla/src/PlatWX.cpp
@@ -198,7 +198,30 @@ void Font::Create(const FontParameters &fp) {
         false,
         sci2wx(fp.faceName),
         encoding);
+
+#ifdef __WXMSW__
+    // enable the smooth font on Windows by default
+    // font rendering issue when using C::B under windows remote desktop
+    // https://forums.codeblocks.org/index.php/topic,25146.msg171484.html#msg171484
+
+    wxString nativeDesc = font.GetNativeFontInfoDesc();
+    int index = 0;
+    for (size_t pos = 0, start = 0; pos <= nativeDesc.length(); )
+    {
+        pos = nativeDesc.find(";", start);
+        index++;
+        if (index == 14) // the index 14 for wx 3.2.1
+        {
+            // enable the cleartype option of the font
+            nativeDesc.replace(start, pos - start, "5");
+            bool result = font.SetNativeFontInfo(nativeDesc);
+            break;
+        }
+        start = pos+1;
+    }
+#endif // __WXMSW__
     wxFontWithAscent* newFont = new wxFontWithAscent(font);
+
     fid = newFont;
 
 #ifdef HAVE_DIRECTWRITE_TECHNOLOGY
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: 2802
Re: Code completion using LSP and clangd
« Reply #321 on: September 27, 2023, 06:10:35 pm »
Oh, thanks for the help. I looked at my local commits, and this is the only change I made to PlatWX.cpp, which I try to enable the font smooth. I don't have other changes to scintilla related code.

Code
diff --git a/src/sdk/wxscintilla/src/PlatWX.cpp b/src/sdk/wxscintilla/src/PlatWX.cpp
index 247b558c..66d64375 100644
--- a/src/sdk/wxscintilla/src/PlatWX.cpp
+++ b/src/sdk/wxscintilla/src/PlatWX.cpp
@@ -198,7 +198,30 @@ void Font::Create(const FontParameters &fp) {
         false,
         sci2wx(fp.faceName),
         encoding);
+
+#ifdef __WXMSW__
+    // enable the smooth font on Windows by default
+    // font rendering issue when using C::B under windows remote desktop
+    // https://forums.codeblocks.org/index.php/topic,25146.msg171484.html#msg171484
+
+    wxString nativeDesc = font.GetNativeFontInfoDesc();
+    int index = 0;
+    for (size_t pos = 0, start = 0; pos <= nativeDesc.length(); )
+    {
+        pos = nativeDesc.find(";", start);
+        index++;
+        if (index == 14) // the index 14 for wx 3.2.1
+        {
+            // enable the cleartype option of the font
+            nativeDesc.replace(start, pos - start, "5");
+            bool result = font.SetNativeFontInfo(nativeDesc);
+            break;
+        }
+        start = pos+1;
+    }
+#endif // __WXMSW__
     wxFontWithAscent* newFont = new wxFontWithAscent(font);
+
     fid = newFont;
 
 #ifdef HAVE_DIRECTWRITE_TECHNOLOGY

@ollydbg
After many hours, I cannot re-create the error.

Then the only action left is to run both CodeBlocks and clangd_client in "-g" mode in order to catch the assert/crash.

Just copy the devel32_64 versions of them to your release folder after running update32_64.bat.

When the assert happens, click continue and you should get a .RPT with all the line numbers in the backtrace.
« Last Edit: September 27, 2023, 06:13:39 pm by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6023
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #322 on: October 22, 2023, 04:32:21 am »
I see an issue which I guess it comes from the BrowseTracker plugin when using Clangd_Client plugin.

When I right click on a symbol(such as a function name), and select "goto definition" in the context menu, the Clangd_Client plugin did bring me to the function definition, that's good.

But when I click the toolbar(the toolbar from BrowseTracker plugin) Jump back, it does not go back to the place where I did the right click. I have to click the Jump back button several times to go back to the original place.

Do you guys see such issue?

Thanks.
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: 2802
Re: Code completion using LSP and clangd
« Reply #323 on: October 22, 2023, 06:39:56 am »
I see an issue which I guess it comes from the BrowseTracker plugin when using Clangd_Client plugin.

When I right click on a symbol(such as a function name), and select "goto definition" in the context menu, the Clangd_Client plugin did bring me to the function definition, that's good.

But when I click the toolbar(the toolbar from BrowseTracker plugin) Jump back, it does not go back to the place where I did the right click. I have to click the Jump back button several times to go back to the original place.

Do you guys see such issue?

Thanks.


Yes, I've experienced this. But it may not have anything to do with Clangd_client.
I think it's a problem in BrowseTracker itself.
I'll look into it.

Thanks for the report.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2802
Re: Code completion using LSP and clangd
« Reply #324 on: October 23, 2023, 06:34:24 pm »
@ ollydbg

I see an issue which I guess it comes from the BrowseTracker plugin when using Clangd_Client plugin.

When I right click on a symbol(such as a function name), and select "goto definition" in the context menu, the Clangd_Client plugin did bring me to the function definition, that's good.

But when I click the toolbar(the toolbar from BrowseTracker plugin) Jump back, it does not go back to the place where I did the right click. I have to click the Jump back button several times to go back to the original place.

Do you guys see such issue?

Thanks.

@ ollydbg
Would you place the following "return;" mod in JumpTracker.cpp and see if it solves this problem for you.

Code
Index: JumpTracker.cpp
===================================================================
--- JumpTracker.cpp (revision 13374)
+++ JumpTracker.cpp (working copy)
@@ -458,6 +458,11 @@
 void JumpTracker::OnEditorActivated(CodeBlocksEvent& event)
 // ----------------------------------------------------------------------------
 {
+    // This is causing the new activated editor to enter it's current line location //(ph 2023/10/22)
+    // before entering the clangd_client target of "Find declaration" causing the next
+    // jump back to jump to an out of sequence location.
+    return; //(ph 2023/10/23)
+
     // Record this activation event and place activation in history
     // NB: Editor Activated is not called on project loading.
     //  So we miss the first activated editor

The point of this test is to stop OnEditorActivated() from entering the current location of the activated editor before BrowseTracker gets to enters the location of the Clangd_client response.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6023
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #325 on: October 24, 2023, 02:18:32 am »

@ ollydbg
Would you place the following "return;" mod in JumpTracker.cpp and see if it solves this problem for you.

Code
Index: JumpTracker.cpp
===================================================================
--- JumpTracker.cpp (revision 13374)
+++ JumpTracker.cpp (working copy)
@@ -458,6 +458,11 @@
 void JumpTracker::OnEditorActivated(CodeBlocksEvent& event)
 // ----------------------------------------------------------------------------
 {
+    // This is causing the new activated editor to enter it's current line location //(ph 2023/10/22)
+    // before entering the clangd_client target of "Find declaration" causing the next
+    // jump back to jump to an out of sequence location.
+    return; //(ph 2023/10/23)
+
     // Record this activation event and place activation in history
     // NB: Editor Activated is not called on project loading.
     //  So we miss the first activated editor

The point of this test is to stop OnEditorActivated() from entering the current location of the activated editor before BrowseTracker gets to enters the location of the Clangd_client response.

Thanks, I just tested your patch, and it solved my reported jump issue, that's great!
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: 2802
Re: Code completion using LSP and clangd
« Reply #326 on: October 24, 2023, 06:19:59 pm »
Thanks, I just tested your patch, and it solved my reported jump issue, that's great!
Fix applied 2023/10/24 for BrowseTracker head rev 13378

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6023
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #327 on: October 25, 2023, 07:40:56 am »
Thanks, I just tested your patch, and it solved my reported jump issue, that's great!
Fix applied 2023/10/24 for BrowseTracker head rev 13378

Good work! Thanks!
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 gd_on

  • Lives here!
  • ****
  • Posts: 799
Re: Code completion using LSP and clangd
« Reply #328 on: October 26, 2023, 05:42:13 pm »
@pecan
Quote
The images are in the .zip file. I just don't use them.
We've been using clangd_client for a year or more without icons.
I'd rather not use them if we don't have to.

Neverthess, it could be nice if you could reintroduce those icons as it was in legacy codecompletion). For me, looking at the icons, quickly indicates if it's a variable or a method, also with the color, quickly indicates if it's public, private, protected... I have the feeling that some code are still there (in your codecompletion* or parsemanager*) but not activated by AddToImageList and GetImage(...) or code in comments.
May be, for those who don't like those icons, you could set a checkbox in the clangd plugin configuration.
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.5 (tests with 3.3), Msys2 Compilers 14.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2802
Re: Code completion using LSP and clangd
« Reply #329 on: October 28, 2023, 06:02:38 pm »
<snipped>
Neverthess, it could be nice if you could reintroduce those icons as it was in legacy codecompletion). For me, looking at the icons, quickly indicates if it's a variable or a method, also with the color, quickly indicates if it's public, private, protected... I have the feeling that some code are still there (in your codecompletion* or parsemanager*) but not activated by AddToImageList and GetImage(...) or code in comments.
May be, for those who don't like those icons, you could set a checkbox in the clangd plugin configuration.

I'll have a look at it.
It'll take some time. Clangd reports types (kinds) entirely differently from legacy CodeCompletion. I don't yet know how to map Clangd kinds to the legacy icons.