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

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2812
Re: Code completion using LSP and clangd
« Reply #180 on: September 25, 2022, 05:21:33 pm »
I have a question:

LSP_ParseSemanticTokens(), what does this function used for?

The fastest way to satisfy a code completion request is to request the clangd "textDocument/DocumentSymbol" response.

However, that response does not have enough information to satisfy a code completion for a variable, enumeration, etc.

So clangd_client requests and parses the "textDocument/semanticTokens" record which does have variable info.
That response is very memory and process expensive. So we only use it when necessary (such as filling html Document popup info).

That particular response provides entries that need teasing out further info. The old CodeCompletion plugin has code to do that. I plan to use more of the old CodeCompletion parsing code in the future when needed.
 
« Last Edit: September 25, 2022, 06:51:01 pm by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #181 on: September 26, 2022, 08:09:30 am »
Thanks for the explanation, I some times get error message like below when using clangd_client plugin:

Quote
[Window Title]
Assert(non fatal)

[Content]
Trying to DoParse recursion in DoHandleClass():2028

[OK]

So, DoParse() is a function from old code completion plugin.  :)
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: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #182 on: September 28, 2022, 07:39:59 am »
Quote
1) The HtmlDocumentationPopup gets stuck showing and cannot be closed.
2) The user did a double-click to select from the AutocompPopup, the HtmlDocumentationPopup got left showing and CB is frozen (and may crash).
3) The AutocompPopup and the HtmlPopup are showing, the user unfocused CB then re-focused CB and CB is frozen and must be killed.
4) The user has unChecked Documentation popup in options and now AutocompPopups cannot be scrolled.
5) The AutocompPopup only is stuck showing and cannot be closed.

Hi, Pecan, good work! I see issue5 many times randomly in my daily work, but it is hard to reproduce, I even don't know how to reproduce this issue. The popup window shown on top of every application, and even CB is not focused, the popup window is still showing. What I have to do is kill the C::B process from the task manager.

Hope your fix will solve those issues, thanks!

I'm using the C::B svn rev12908, and the latest clangd_client plugin rev78, but I see the issue "popup(tooltip) window shown on top of every application" still happens.  :(
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: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #183 on: September 28, 2022, 07:56:53 am »
I see another issus is that not the full tooltip window is shown, see the image shot as attachment.

I see only a very small portion of the tooltip window is shown, and the right side of the window is hidden.
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: 2812
Re: Code completion using LSP and clangd
« Reply #184 on: September 28, 2022, 04:52:16 pm »
I see another issus is that not the full tooltip window is shown, see the image shot as attachment.

I see only a very small portion of the tooltip window is shown, and the right side of the window is hidden.

This is not a clangd_client problem. Only ccManager has control  over the popup(s) appearances.
Change Settings/Editor/OtherEditorSettings(tab)/Technology:(choice list) to Direct write.
« Last Edit: September 28, 2022, 04:54:27 pm by Pecan »

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2812
Re: Code completion using LSP and clangd
« Reply #185 on: September 29, 2022, 12:36:37 am »
I'm using the C::B svn rev12908, and the latest clangd_client plugin rev78, but I see the issue "popup(tooltip) window shown on top of every application" still happens.  :(

Do you mean the popup when you hover over a function name or function parameters ?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #186 on: September 29, 2022, 03:59:58 am »
I'm using the C::B svn rev12908, and the latest clangd_client plugin rev78, but I see the issue "popup(tooltip) window shown on top of every application" still happens.  :(

Do you mean the popup when you hover over a function name or function parameters ?

yes

sent from my phone
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: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #187 on: September 29, 2022, 04:24:22 am »
I see another issus is that not the full tooltip window is shown, see the image shot as attachment.

I see only a very small portion of the tooltip window is shown, and the right side of the window is hidden.

This is not a clangd_client problem. Only ccManager has control  over the popup(s) appearances.
Change Settings/Editor/OtherEditorSettings(tab)/Technology:(choice list) to Direct write.

This does not solve the issue.

The issue happens in both options, whether it is the Direct2D or the default option.
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: 2812
Re: Code completion using LSP and clangd
« Reply #188 on: September 29, 2022, 07:06:29 am »
I see another issus is that not the full tooltip window is shown, see the image shot as attachment.

I see only a very small portion of the tooltip window is shown, and the right side of the window is hidden.

This is not a clangd_client problem. Only ccManager has control  over the popup(s) appearances.
Change Settings/Editor/OtherEditorSettings(tab)/Technology:(choice list) to Direct write.

This does not solve the issue.

The issue happens in both options, whether it is the Direct2D or the default option.

I'll enter the problem into the clangd_client ticket system and investigate.

Thanks for reporting.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #189 on: September 29, 2022, 08:24:11 am »
I see another issus is that not the full tooltip window is shown, see the image shot as attachment.

I see only a very small portion of the tooltip window is shown, and the right side of the window is hidden.

This is not a clangd_client problem. Only ccManager has control  over the popup(s) appearances.
Change Settings/Editor/OtherEditorSettings(tab)/Technology:(choice list) to Direct write.

This does not solve the issue.

The issue happens in both options, whether it is the Direct2D or the default option.

I'll enter the problem into the clangd_client ticket system and investigate.

Thanks for reporting.
Thanks.

I disabled the clangd_client, and re-enabled the old CC plugin, and I don't see this issue in old CC plugin.

So, my guess it is caused by the clangd_client code.

EDIT:

Maybe, the wrong CCCallTip

Code
        /** Structure representing an individual calltip with an optional highlighted range */
        struct CCCallTip
is returned from the clangd_client plugin?


EDIT2, this is the code to fill the m_SignatureTokens, which is the collection of CCCallTip.

Code
    // ----------------------------------------------------------------------------
    // SignatureHelp event
    // ----------------------------------------------------------------------------
    else if ( evtString.StartsWith("textDocument/signatureHelp"))
    {
        Parser* pParser = (Parser*)GetParseManager()->GetParserByProject(pProject);
        pParser->OnLSP_SignatureHelpResponse(event, m_SignatureTokens, m_HoverLastPosition);
    }
« Last Edit: September 29, 2022, 09:14:16 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 MaxGaspa

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Code completion using LSP and clangd
« Reply #190 on: September 29, 2022, 11:01:19 pm »
Dear Pecan,

I'd like to highlight a possible issue with the new clangd pluging.

Look at the attached picture.

The function

void MainFrame::OnWriteA0( wxCommandEvent& event)

is reported (in both clangd toolbar and symbol browser) as

OnWriteA0wxCommandEvent & : void


without any separation character between OnWriteA0   and   wxCommandEvent

Not a big problem but a little bit confusing. Is it possible to insert a space (for example) between the name of the function and the parameter?



Offline MaxGaspa

  • Multiple posting newcomer
  • *
  • Posts: 37
Re: Code completion using LSP and clangd
« Reply #191 on: September 29, 2022, 11:11:45 pm »
This does not solve the issue.

I had the same problem but setting Direct Write fixed it completely, I'm no longer observing the issue in several days of use....I'm using "Source Code Pro" font and the option "LCD Optimized" but my guess is that the font and optimization doesn't matter

(win7 pro and Win10 Entreprise, latest nightly and latest clangd plugin)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #192 on: September 30, 2022, 03:31:06 am »
This does not solve the issue.

I had the same problem but setting Direct Write fixed it completely, I'm no longer observing the issue in several days of use....I'm using "Source Code Pro" font and the option "LCD Optimized" but my guess is that the font and optimization doesn't matter

(win7 pro and Win10 Entreprise, latest nightly and latest clangd plugin)

Hi, thanks for the reply.

I just tried it again. I have enabled the Direct Write, and I changed to many kinds of fonts, and the issue still happens.
This also happens when I disable the Direct Write in the Editor option.

The interesting thing is, when the first time I hover the variable, I got this black rectangle(see the attachment). I just tried several times, and the tip messages are all black rectangles, and it start to show a white rectangle about 5 or 6 times later.

Please note that not the all tooltip window has such issue, it only happens on a specify member variables. I guess that the text try to shown in the tip window masses the tip window, but not the other variables' tip message.





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: 2812
Re: Code completion using LSP and clangd
« Reply #193 on: September 30, 2022, 06:15:35 am »
This does not solve the issue.

I had the same problem but setting Direct Write fixed it completely, I'm no longer observing the issue in several days of use....I'm using "Source Code Pro" font and the option "LCD Optimized" but my guess is that the font and optimization doesn't matter

(win7 pro and Win10 Entreprise, latest nightly and latest clangd plugin)

Hi, thanks for the reply.

I just tried it again. I have enabled the Direct Write, and I changed to many kinds of fonts, and the issue still happens.
This also happens when I disable the Direct Write in the Editor option.

The interesting thing is, when the first time I hover the variable, I got this black rectangle(see the attachment). I just tried several times, and the tip messages are all black rectangles, and it start to show a white rectangle about 5 or 6 times later.

Please note that not the all tooltip window has such issue, it only happens on a specify member variables. I guess that the text try to shown in the tip window masses the tip window, but not the other variables' tip message.

What is the variable(s) or name(s) that cause the issue. So that I can try to catch it in the debugger.

Can you give me some code that causes the issue.
So far, I have not been able to re-create the problem.
« Last Edit: September 30, 2022, 06:17:19 am by Pecan »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6034
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #194 on: September 30, 2022, 07:21:58 am »

What is the variable(s) or name(s) that cause the issue. So that I can try to catch it in the debugger.

Can you give me some code that causes the issue.
So far, I have not been able to re-create the problem.

See a minimal code below:

Code
#include <iostream>
#include <fstream>

using namespace std;

// this file is not used any more?
// std::ofstream txtFile;                                 ///< txt信息
std::ofstream m_TcpFile;                                  ///< TCP接收的数据

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}


My guess is that it is an encoding/decoding error?

Here is the screen shot in attachment.


EDIT

It looks like the comment after the variable definition cause this issue:

Code
///< TCP接收的数据

If I remove this comment, the tooltip showns correctly.


The minimal sample can be simplified to:

Code
int m_TcpFile;  ///< TCP接收的数据

int main()
{
    return 0;
}

« Last Edit: September 30, 2022, 07:26:11 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.