Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: Pecan on February 20, 2021, 09:13:50 pm

Title: Code completion using LSP and clangd
Post by: Pecan on February 20, 2021, 09:13:50 pm
I have developed a clangd CB plugin client using Language Server Protocol (LSP).

It's working well.
However, it requires clangd version 12 to work even better.

What is the CodeBlocks policy of distributing an executable, say, clangd.exe v12 with the usual CodeBlock distribution.

CodeLite also distributes clangd with its LSP plugin.

Request for Comments.
Title: Re: Code completion using LSP and clangd
Post by: oBFusCATed on February 20, 2021, 11:33:10 pm
Shipping clangd is a windows thing. I don't think we should do it. Just detect the LLVM installation and use it. Or prompt the user to install it.
Title: Re: Code completion using LSP and clangd
Post by: oBFusCATed on February 20, 2021, 11:34:07 pm
What is the purpose of this LSP plugin? Just provide faster error messages?
In my experience implementing a CC plugin with LSP doesn't work well (don't remember the details).
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 21, 2021, 01:24:00 am
Hi, Pecan, good work!

For me, I think distribute a clangd.dll is OK, or we can distribute a separate plugin package(include the plugin and the clangd.dll). Then the user can just download and unpack it.

If I remember correctly, there is an option in CodeLite IDE, which can let user select which clangd.dll it will use.

Do you have a code repo which others can build/test this plugin?

What is the purpose of this LSP plugin? Just provide faster error messages?
In my experience implementing a CC plugin with LSP doesn't work well (don't remember the details).
Using the LSP, I think at least code completion list will be more precise than the native CC.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 22, 2021, 05:22:56 pm
Shipping clangd is a windows thing. I don't think we should do it. Just detect the LLVM installation and use it. Or prompt the user to install it.

Just detecting the installation and using its clangd does not work. I've already tried that. The llvm's versions up to version 8 have no reliable clangd for a CB plugin.

The clangd in llvm versions 8 through 11 are so different from  version 12 that the plugin using them would require two separate plugins or spaghetti code to support them.

CB will have to pick some version between 10 through 12 and program towards that.

I've chosen to work with clangd v12. It can reload the compile commands database without having to kill/restart the LSP server when a user opens a new file.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 22, 2021, 05:27:11 pm
What is the purpose of this LSP plugin? Just provide faster error messages?
In my experience implementing a CC plugin with LSP doesn't work well (don't remember the details).

Using  LSP "workspace/publishDiagnostics" with clangd is working well for me. I'ts halved my development time. I no longer have to compile the code to find the errors. They're presented to me as I enter the code or save it.

Clangd supports all the LSP calls plus it's own extensions. So far, I've implemented all CB CC's features via LSP calls except the Symbols browser. Though that's possible to do.

LSP/Clangd is primarily focused on the translation unit (TU). But its still possible to provide a bigger picture by asking for workspace symbols. I haven't tried that (yet).
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 22, 2021, 05:38:30 pm
...<snip>...
If I remember correctly, there is an option in CodeLite IDE, which can let user select which clangd.dll it will use.

Do you have a code repo which others can build/test this plugin?
...<snip>...

CodeLite allows the user to choose the clang to use, but it prioritizes using clangd v10, which it distributes in dir Runtime/lsp.
Later versions of clangd are very independent of llvm/clang. For example clangd v12 can use many llvm/clang versions.

I don't have a repository yet. Things are still very experimental. But I'll work on that.
Title: Re: Code completion using LSP and clangd
Post by: oBFusCATed on February 22, 2021, 06:05:26 pm
For the record the latest version of clang is 11.1. clang/llvm 12 is some night build. This would fail dramatically on linux if you base your development on this version at least until clang/llvm 12 is actually released in the summer.

Clangd supports all the LSP calls plus it's own extensions. So far, I've implemented all CB CC's features via LSP calls except the Symbols browser. Though that's possible to do.
I know that, CC features required changes to the CCManager API last time I've tried to do it. At least if you want to provide good experience.
I don't think implementing the diagnostics in another info pane tab is a good idea, but this requires another CCManager change which would allow in-editor-notifications.

Also I don't know how is using a mix of clang/gcc these days, but it was a problem in the past.
Also I'm not sure if it is a good idea to base your LSP plugin on only one implementation. If you're going to do it name it clangd-lsp. :)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 22, 2021, 06:21:33 pm
For the record the latest version of clang is 11.1. clang/llvm 12 is some night build. This would fail dramatically on linux if you base your development on this version at least until clang/llvm 12 is actually released in the summer.

I know that, CC features required changes to the CCManager API last time I've tried to do it. At least if you want to provide good experience.
I don't think implementing the diagnostics in another info pane tab is a good idea, but this requires another CCManager change which would allow in-editor-notifications.

Also I don't know how is using a mix of clang/gcc these days, but it was a problem in the past.
Also I'm not sure if it is a good idea to base your LSP plugin on only one implementation. If you're going to do it name it clangd-lsp. :)

In the furture, I'm sure we can generalize to a LSP UI. For the time being, I'm coding a plugin to concentrate learning and experimentation. I'll be happy to name it clangd-lsp. That's a good name.
 
Good to know clangd v12 rc1 may be out in the summer. I don't expect this plugin will be ready to publish any sooner.
Title: Re: Code completion using LSP and clangd
Post by: Lazauya on May 02, 2021, 05:02:42 am
Do you have a public repo? I'm super interested in contributing to this plugin.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on May 02, 2021, 06:34:47 am
Do you have a public repo? I'm super interested in contributing to this plugin.

I do not yet have a public repo.
The current code is very experimental and in a raw combination of both used and deprecated code, full of unreleasable log writes.

I will make a repo when I can clean up the code  and after I do more debugging.
I'm working hard at it.

But thanks for the offer. 
Title: Re: Code completion using LSP and clangd
Post by: Lazauya on May 02, 2021, 06:46:02 pm
The current code is very experimental and in a raw combination of both used and deprecated code, full of unreleasable log writes.

I will make a repo when I can clean up the code  and after I do more debugging.

I don't mind. I could definitely help in debugging, test writing, code cleaning, etc. This is the kind of thing I've been looking for, and I'd very much like to accelerate development of it as much as possible, if you would let me.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 07, 2022, 06:58:50 am
@ AndrewCot:

What is your concurrently processing threads set to at
Settings->clangd_client-> C/C++parser ->Concurrently parsing threads.

It might not be there. I don't know when I implementd that.

Clangd seems to need 3-4 seconds to index a 2-3k line file, but it's very fast at the user response level once a file is indexed

In the new implementation (not uploaded yet) I set clangd parsing the active editor first, then the other open editors, then recently modified files, then all the others.

That way, you do not have to wait to begin using clangd. Just open the editor you want to work in. It gets sent to the front of the line, and it's should be parsed and indexed in 3 or 4 seconds.

Clangd can parse, Goto (decls and defs), find references, rename symbols etc. etc. all at the same time. No need to wait. Just open the file.

You do not need to wait for files to parse like the older CodeCompletion. Just activate the file you want to work in. The non-opened files parse in another address space at their own pace. If you switch editors, clangd-client knows whether it's been parsed or not. If it hasn't been, it's send immediately to clangd which parses it ahead of any background files.

This works great as long as at least one clangd thread is available.

The trick I found was to set the clangd threads to no more than 1/2 of the system (cpu) threads (hard coded in client allocation). I've given clangd 4 threads of my i7's 8 , and set concurrent parsing threads to 2. That usually guarantees that a thread will be available for priority (active editor) parses.  I'm able to compile, background parse, GoTo, Find references, code complete, show function, etc all at the same time.

My parsing times look 1/2 of yours.
What's your hardware look like? What cpu, how many threads?

But all of this will come to light with testing and discussion (as you are doing now). Thanks.

Go easy on me for a little longer. I'm running into problems.
Clangd is passing back 3 byte UTF8 chars during code completions, crashing json parses. I'm stalled trying to fix that. I found the culprit today, Hopefully I can fix it tomorrow .

@pecan
It appears that processing the files is slow as per the logged info shown below:

Opening D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\CodeBlocks_wx31_64.cbp
Done.
cbProject::Open took: 0.725 seconds.
ProjectManager::SetProject took: 1.686 seconds.
ProjectManager::LoadProject took: 2.732 seconds.
ParseManager::CreateParser: Finish creating a new parser for project 'Code::Blocks wx3.1.x (64 bit)'
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\plugins\clangd_client\src\LSPclient\include\protocol.h (1441 ms) (496 more)
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\plugins\clangd_client\src\codecompletion\parser\LSP_tokenizer.h (3194 ms) (495 more)
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\plugins\clangd_client\src\codecompletion\codecompletion.cpp (4342 ms) (494 more)
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\plugins\clangd_client\src\LSPclient\include\client.cpp (3738 ms) (493 more)
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\include\compilerfactory.h (660 ms) (492 more)
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\plugins\clangd_client\src\asyncprocess\asyncprocess.cpp (2228 ms) (491 more)
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\sdk\configmanager-revision.cpp (3543 ms) (490 more)
LSP opened editor parse finished for D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\sdk\cygwin.cpp (3534 ms) (489 more)
LSP background parsing finished for: D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller\src\src\environmentsettingsdlg.cpp (3262 ms) (488 more)

Is there a way of speeding this up? Any ideas on where to look or what to check or do?
I am using MSYS2 with the latest updates as of a few hours ago (this resulted in waht looked like a big MinGW 64 9.00 run time update) and GCC 11.2.0.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 07, 2022, 08:06:13 am
Does anyone know of a good UTF8 char validator.
Clangd is handing back (occasionally) a 3 byte utf8 char.
It's blowing nlohmann json parser out of the water.

I'd like to scan the clangd stdout responses for invalid UTF8.
They're weird. \xE2\x80\xA6 right in the middle of an empty function() param area. Also that strange period half way up the middle of a char area. Like an item list indicator. \xE2\x80\xA2.

When, in the initialization, we tell clangd to use "Only UTF8", it's supposed to mean 8 bits only, not 24 bits. And evidently they don't know it, because they set the response length as if all chars are 8bit.

Thanks
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 07, 2022, 08:26:32 am
@pecan.

I am not trying to be a PITA, but trying to give feedback and what I have seen when I see it so I do not forget. Even as it is now it's still a big improvement on the existing codecompletion code. The changes I have made are in the https://github.com/acotty/codeblocks_sf/tree/AC-WindowsInstaller branch if you need or want to look at what I have done.

My setup is:
    Windows 10 21H2 with latest updates (checked last night and it was up to date)
    32GB DDR4 3600Mhz ram (2x16gb sticks)
    AMD Ryzen 7 5700G (8 core plus 8 HT for a total of 16, base 3800 Mhz boost 4650)
    No separate GPU
    C: & D: are on a Samsung SSD 980 pro.
    MSYS2 MinGW64 GCC 11.2.0
   C: has the MSYS 2 compiler on it.
   D: has the CB and other source code on it.
 
I had 1 concurrent parsing thread setup, but changed this about 2 hours ago to 8 and it speed up the overall time, but the time shown per file was still about the same.

As for the UTF8 I have no idea, but will do some searching after dinner (OZ Sydney time).
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 07, 2022, 04:35:18 pm
@pecan.

I am not trying to be a PITA, but trying to give feedback and what I have seen when I see it so I do not forget....snipped...

I understand. And I really appreciate your doing all this work. I really need to set up some sort of bug tracking.
I'll work on it.
Thanks.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 09, 2022, 01:55:05 am
@pecan
I have updated to the r8 code and it works better than the r5 as expected. As expected it's working allot better than the r5.  It's probably worth putting up on the SF repo the plugin binary/zip file so people can test it with the nightly build. As for bug tracking can you enable the tickets tab in SF?

Below is my updated list of things (queries, potential to do items, work I did ) for the plugin

Queries I have:
1) What is the clangd_client toolbar for? It is greyed out when I enable it and neither drop down is populated/enabled.


Changes that still need to be done that I spotted are:
1) Fix one compiler warning left (when built as a core plugin):
    src\plugins\clangd_client\src\LSPclient\lspdiagresultslog.cpp:10:25:
        warning: .objs31_64\include/sdk_precomp.h.gch: not used because `EXPORT_LIB' not defined [-Winvalid-pch]
        10 | #include "sdk_precomp.h"
2) Add support for building under Linux, Mac and Windows x64 & x86 as a core plugin.
3) Add plugin files to the Debain, Mac and windows installer scripts/process.
4) Test installers works and the plugin works after installing using installer
5) With r8 the setup requires you to specify the C:\msys64\clang64\bin\clangd.exe , not the direxctory it is in.
    The wxwidget group text needs to change to match this change.
6) The LSP plugin column widths do not take up the full width of the lopg dialog on my FDH screen (1920 x 1080). The
    other logs also have this issue, so it may not be easy to fix.

The changes done to incorporate plug as a core plugin follow that may/will need to be incorporated at some stage:
1. Included the SF src in the src\plugins\clangd_client directory (same level as the codecompletion core plugin)
2. Incorporate the windows cpb into the src\CodeBlocks_wx31_64.cbp with changes
3. Update code for use with PCH as per src\CodeBlocks_wx31_64.cbp (client.cpp and codecompletion.cpp changed)
4. Updated my unofficial NSIS installer to add the plugin

The following is what is needed to get the plugin working with MSYS2:
1) Install MSYS 2  clang packages:
    pacman -S mingw-w64-clang-x86_64-toolchain
2) Configure for use:
    a) In the Settings->editor select Clangd_Client settings.
    b) In the C/C++ parser tab change the "LLVM directory" to specify the clangd.exe you have installed:
            C:\msys64\clang64\bin\clangd.exe
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 09, 2022, 11:21:31 am
FYI. The following tickets have a codecompletion tag and are currently open, so when finished hopefully a heck of allot of these will get resolved:

Ticket#    Summary
1057   Code completion header search path disrespect build target/platform
1028   Tab Code Completion bug
859   "Implementation of" is searching in all projects instead of current one
820   "Find references of" doesn't always work
793   Code completion stop working with enum defined inside function body
790   Code Completion lacks cstdint typedefs when prefixed with std::
788   Code completion doesn't account for shared_ptr, unique_ptr, etc
716   Code::Blocks 17.12 CodeCompletion slows down the editor dramatically
692   Intellisense not working unless include paths provided plus CB slash auto-conversion in paths
679   Right-click on <header.h>: CB looks in GCC path first regardless of chosen compiler
576   Add case sensitivity for header/source search under case-sensitive systems
518   Source parser error (SVN 11087
498   Parsing of the doxygen comment "see also" command error
474   Autocompletion does not work by using const pointer
388   Code completition doesn't work if used C++11 raw string literal
298   Code completion only works in gcc projects
286   CC crash when closing workspace
283   Bug e Outros 15.xx Brasil C++ Previso Erros
281   Let's CC support Conditional Code :: Blocks. highlighting in the editor
237   CC will not show all members in the namespace std
236   No code completion in array-of-struct
224   Duplication in documentation tooltip
213   ParserThread::GetBaseArgs function need to be refactored
212   space in Tokenizer::ReadParentheses issue
197   thread safty issue of CodeCompletion plugin
193   running cctest is too slow
177   Code completion fails with enum variables defined/declared along with the enum types
172   code completion doesn-t work with auto key word
156   CC failed parsing the char (*varname)[7]; (a pointer to an array of characters) definition
145   Code completion ignores parameters of catch-clauses
127   Code completion fails with complex declarations/definitions
88   Code completion mouse hover tooltip is always active
83   codecompletion's setting not saved correctly
47   Show call tip of the constructor function
43   Code complete - keyword final
31   restrict keyword and auto-completion
159   Code Completion fails for C++ functions marked "override"
158   Code completion fails with the "using Alias = Type" syntax in C++11
33   C++11 Initializer lists fool code completion
211   CCTest for the parser logic
313   CB hangs when loading a project for the first time after new launch
256   CC's Toolbar does not show function correctly inside the namespace scope
312   CC's symbol tree does not show correctly unless collapse and expand again
438   Popup hint for std::vector::end() causes Codeblocks to freeze
311   C::B hangs when exits
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 09, 2022, 05:49:04 pm
@pecan
I have updated to the r8 code and it works better than the r5 as expected. As expected it's working allot better than the r5.  It's probably worth putting up on the SF repo the plugin binary/zip file so people can test it with the nightly build. As for bug tracking can you enable the tickets tab in SF?
FYI. The following tickets have a codecompletion tag and are currently open, so when finished hopefully a heck of allot of these will get resolved:

@AndrewCot

Damn !! Thanks for all this hard work.
I'll start working on this today.

I'm not sure right now, but I think I have to enable tickets user by user. I seem to remember a lot of ads showing up in the tickets if it's opened for everyone. I could be wrong.

Would you send me a private message with your SourceForge login ID. (not your password). I'll find a way to authorize you for tickets. (i"m still not very adept at "SorceForging".

Title: Re: Code completion using LSP and clangd
Post by: killerbot on January 09, 2022, 07:51:02 pm
I would suggest to add it to the opfficial Cb repo at location next to the current cc.
Title: Re: Code completion using LSP and clangd
Post by: sodev on January 10, 2022, 06:13:05 pm
Does anyone know of a good UTF8 char validator.
Clangd is handing back (occasionally) a 3 byte utf8 char.
It's blowing nlohmann json parser out of the water.

I'd like to scan the clangd stdout responses for invalid UTF8.
They're weird. \xE2\x80\xA6 right in the middle of an empty function() param area. Also that strange period half way up the middle of a char area. Like an item list indicator. \xE2\x80\xA2.

When, in the initialization, we tell clangd to use "Only UTF8", it's supposed to mean 8 bits only, not 24 bits. And evidently they don't know it, because they set the response length as if all chars are 8bit.

Thanks

I'm not sure if i fully understand what you have written, but it seems you are mixing some things. UTF8 is a variable length encoding, while each of its code units is 8 bit, a valid encoding can be comprised of 1 to 6 code units. Such a sequence gets decoded to a 32 bit code point, which i think you refer to as character. Both your mentioned sequences above are totally valid UTF8.
Title: Re: Code completion using LSP and clangd
Post by: BlueHazzard on January 10, 2022, 08:04:49 pm
i was curious what symbol it is:
https://www.compart.com/en/unicode/U+2026

ps.: I can not post the symbol here, it seems the forum software is not utf8 conform :)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 10, 2022, 09:44:51 pm
A clangd_client plugin cbPlugin package is available for the 31 December nightly at:
https://sourceforge.net/projects/cb-clangd-client/files/

Download the clangd_client.cbplugin file.

In CodeBlocks MainMenu=>plugins=>Manage plugin=> disable CodeCompletion .

Navigate to the downloaded file (clangd_client_plugin.zip) and unzip it to a temporary folder.
Copy the clangd_client.zip file to the CodeBlocks nightly ...\share\CodeBlocks\ folder.
Copy the clangd_client.dll file to the CodeBlocks nightly ...\share\Codeblocks\plugins\ folder
Restart the nightly CodeBlocks.

To uninstall, delete the above files from the CodeBlocks Nightly folders.

If you uninstall it using the "Manage plugins" menu , a crash may occur if a workspace is active.
Close the workspace first before uninstalling to avoid the crash.
We'll apply a fix for that soonest.

If you previously installed the clangd_client.cbplugin version, delete it with the commands:
 del %APPDATA%\CodeBlocks\share\codeblocks\plugins\clangd_client.dll
 del %APPDATA%\CodeBlocks\share\codeblocks\clangd_client.zip
The .cbplugin version became entirely too invasive.

Thanks to AndrewCot.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 12, 2022, 06:52:25 am
Due to incompatibilities between plugins built with the latest MSYS2 and the nightly releases that cause then plugin to not load (unless you update the Mingw64 DLL's) there is an update of the plugin available that has been built using Mingw64 8.1.0. This update works with the nightly builds and also locally build C::B built with MSYS2 at:
    https://sourceforge.net/projects/cb-clangd-client/files/

The install docs have been updated with a bunch of options for both the plugin and the clangd.exe.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 12, 2022, 12:01:57 pm
Due to incompatibilities between plugins built with the latest MSYS2 and the nightly releases that cause then plugin to not load (unless you update the Mingw64 DLL's) there is an update of the plugin available that has been built using Mingw64 8.1.0. This update works with the nightly builds and also locally build C::B built with MSYS2 at:
    https://sourceforge.net/projects/cb-clangd-client/files/

The install docs have been updated with a bunch of options for both the plugin and the clangd.exe.

There is a typo in the file: https://sourceforge.net/projects/cb-clangd-client/files/Plugin_Install_Package/Windows_x64/0.2.5%20-%2012JAN2022/Windows-LLVM-ClangD-Install-Readme.txt/download

Quote
instructions below for the specific compiler you haev installed:



Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 12, 2022, 12:20:11 pm
File in SVN has been updated, so the next update will include the typo fixed.

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 12, 2022, 04:07:20 pm
File in SVN has been updated, so the next update will include the typo fixed.

There is another typo:

Quote
Windows Clangd-Client Plugin install process:
============================================
1) Install the LLVM or Clangd.exe as documented in the following file:
    Windows-LLVM-ClangD-Install-Readme.txt
2) Disable the Code completion plugin as follows:
    a) Open the Plugin manager via the Code::Blocks "MainMenu=>Plugins=>Manage plugins..." menu
    b) In the Manage Plugin dialog do the following:
       i) Find and select the "Code completion" plugin via it's title
       ii) Press the "Disable" button on the right near the top
       iii) If you get any errors please try again.
3) Install the Clangd-Client Plugin using one of the following options, which are documneted later in this readme file:
    a) Install via the Plugin Manager
    b) Manaully install the plugin files
3) Configure the Clangd-Client Plugin for use as follows:
    a) Select the "MainMenu=>Settings->Editor..." menu
    b) In the list on the left click/select the "clangd_client" option.
    c) In the "C/C++ parser" tab change the "Specify clangd executable to use" to reference the clangd.exe you installed via step 1) above.
         Some examples of this could be:
            C:\msys64\clang64\bin\clangd.exe
            C:\msys64\clang32\bin\clangd.exe
            C:\LLVM\bin\clangd.exe
            C:\comilers\cmang\clangd.exe

You can see there are two "3)" sub-sections.

BTW:

I download the package: clangd_client.zip (https://sourceforge.net/projects/cb-clangd-client/files/Plugin_Install_Package/Windows_x64/0.2.5%20-%2012JAN2022/clangd_client.zip/download), but when I try to "install" the plugin by the plugin manager, it need a file "*.cbplugin", while I see only this zip file, so I need to rename the file extension?
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on January 12, 2022, 04:22:10 pm
File clangd_client.zip is a mess, it contains two levels of older copies of itself.

You just need the DLL and a zip containing the resources.
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on January 12, 2022, 05:56:44 pm
I have just created a wiki entry for the .cbplugin file format: https://wiki.codeblocks.org/index.php/Code::Blocks_Plugins#Format_of_.cbplugin_files (https://wiki.codeblocks.org/index.php/Code::Blocks_Plugins#Format_of_.cbplugin_files)

It is a draft based on the source code, if somebody has more information or spots an error please edit it.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 13, 2022, 07:58:01 am
@ollydbg In the plugin manager you specify the zip file instead of a .cbplugin and it works

@Miguel Thanks for the info. I need mod the project file to check and delete the zip file otherwise you get the zip file stored in it multiple times (probably recursive until I delete the zip file).

As for the .cbplugin format please can you modify the page you did and remove the info as it is duplicated on the following page along with allot more info for a developer:
http://wiki.codeblocks.org/index.php/Managing_Plug-in_Resources

I would suggest on the page you modify the General section where the If you are developing plugins to the following as is has a few issues:
If you are developing plugins:
* Please read the "http://wiki.codeblocks.org/index.php/Managing_Plug-in_Resources" page for creating and producing a plugin.
* You will need to store the source code for the plugin for other developers to have access to it. You can do this on SourceForge or Github or your favorite source code repository web site.
* Setup your own webpage on a file sharing platform that can be used for documenting and distribution of the plugin. This will allow users to download the plugin to install on their Code::Blocks installation.

Once you have a working and production ready plugin for other developers to use then you can do the following:
* Read the "https://wiki.codeblocks.org/index.php/Announcement_for_plugins/patches" page for information on how to announce you have a plugin on the Code::Blocks forum.
* In your announcement in the "https://forums.codeblocks.org/index.php/board,14.0.html" forum please also ask for your plugin to be added to the Code::Blocks "https://wiki.codeblocks.org/index.php?title=Code::Blocks_Plugins" wiki page with the details you would like to see on the page.



One issue with this is that the referenced pages are not up to date either, so when do you stop..... Also it seems that some of the info is on multiple pages or it may be very similar info which is not right as later if one page gets updated and not the other then there may be issues.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 13, 2022, 10:49:17 am
Repackaged plugin is available from the following page:
https://sourceforge.net/projects/cb-clangd-client/files/Plugin_Install_Package/Windows_x64/0.2.6%20-%2013JAN2022/ (https://sourceforge.net/projects/cb-clangd-client/files/Plugin_Install_Package/Windows_x64/0.2.6%20-%2013JAN2022/)
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on January 13, 2022, 11:47:05 am
I have updated the Wiki with your suggestions
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 13, 2022, 12:21:43 pm
@ollydbg In the plugin manager you specify the zip file instead of a .cbplugin and it works

I have rename the .zip file to .cbplugin, because I can't select a zip file in the plugin manager to install the new plugin(NO zip files will be shown in the file select dialog).


In the Windows-LLVM-ClangD-Install-Readme.txt

Quote
MSYS2 Compiler - MinGW64
-------------------------
a) Install MSYS 2 clang packages via the msys2.exe bash shell:
    pacman -S mingw-w64-clang-x86_64-toolchain

Run this command, I got this:

Code
# pacman -S mingw-w64-clang-x86_64-toolchain
:: There are 22 members in group mingw-w64-clang-x86_64-toolchain:
:: Repository clang64
   1) mingw-w64-clang-x86_64-clang  2) mingw-w64-clang-x86_64-clang-analyzer
   3) mingw-w64-clang-x86_64-clang-tools-extra
   4) mingw-w64-clang-x86_64-compiler-rt  5) mingw-w64-clang-x86_64-crt-git
   6) mingw-w64-clang-x86_64-headers-git  7) mingw-w64-clang-x86_64-libc++
   8) mingw-w64-clang-x86_64-libc++abi  9) mingw-w64-clang-x86_64-libmangle-git
   10) mingw-w64-clang-x86_64-libunwind
   11) mingw-w64-clang-x86_64-libwinpthread-git  12) mingw-w64-clang-x86_64-lld
   13) mingw-w64-clang-x86_64-lldb  14) mingw-w64-clang-x86_64-llvm
   15) mingw-w64-clang-x86_64-make  16) mingw-w64-clang-x86_64-mlir
   17) mingw-w64-clang-x86_64-openmp  18) mingw-w64-clang-x86_64-pkgconf
   19) mingw-w64-clang-x86_64-polly  20) mingw-w64-clang-x86_64-tools-git
   21) mingw-w64-clang-x86_64-winpthreads-git
   22) mingw-w64-clang-x86_64-winstorecompat-git

Enter a selection (default=all):


Do I need to only select the option 1?
Or do I need to use the all?


EDIT:

clangd is contained in mingw-w64-clang-x86_64-clang-tools-extra, so normally we should use option 3.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 13, 2022, 01:16:30 pm
I also see the "LSP_DidOpen() error: [json.exception.type_error.316] invalid UTF-8 byte at index 1019: 0xB5" message box.

A quick search gives this related discussion:

[json.exception.type_error.316] invalid UTF-8 byte at index 1: 0xC3 Issue #1383 nlohmann/json (https://github.com/nlohmann/json/issues/1383)

Invalid UTF-8 byte at index 1: 0x65 Issue #1831 nlohmann/json (https://github.com/nlohmann/json/issues/1831)

I'm not sure how we pass the source file to clangd, maybe the file is not encoded in UTF8, but you pass the file to clangd as a UTF8 format file, and in this case, clangd return a string which is not encoded in UTF8.  And finally we get the exception message box.
Title: Re: Code completion using LSP and clangd
Post by: BlueHazzard on January 13, 2022, 06:10:45 pm
What is the encoding of your source file?
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 13, 2022, 08:57:58 pm
What is the encoding of your source file?

The data sent to clangd comes directly from the editors' wxTextctrl.
The encoding in the status bar for my CB shows windows-1252.
This problem only occurs on the incoming textDocument/completion response.
The data going out never gets a json exception. Only the data coming in.

How can I determine what the encoding is for the outgoing data?

Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 13, 2022, 10:11:47 pm
For the time being, I've coded a hack for the illegal utf8 problem.

It clears the illegal utf8 char and continues with the code completion.
The completion suggestions are correct so I'm ok with it.
I'll figure it out some other time.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 15, 2022, 04:08:33 am
I see your latest commit here in rev 27

* clangd_client - Code to remove invalid utf8 chars from clangd responses; cf., client.cpp/h DoValidateUTF8data() (https://sourceforge.net/p/cb-clangd-client/code/27/)

I will test it, thanks!

EDIT updated:

The illegal utf8 problem still exits in rev 27.   :(
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 15, 2022, 06:53:26 am
I see your latest commit here in rev 27

* clangd_client - Code to remove invalid utf8 chars from clangd responses; cf., client.cpp/h DoValidateUTF8data() (https://sourceforge.net/p/cb-clangd-client/code/27/)

I will test it, thanks!

EDIT updated:

The illegal utf8 problem still exits in rev 27.   :(

Can you give me some guidance as to how you created the problem. I can't make it happen here.

What source are you using that got a utf8 invalid char?

What symbol were you trying to code complete.

What indication are you getting that there was an invalid utf8 char. A wxMessageBox or an error shown in the cb debug log?

If a message was in the CB debug log, what did it say?

Did you use the repo source or the download file ?
In plugin management, what is the version you see for clangd_client?

I don't think the download files have been updated yet.

Thanks for testing.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 15, 2022, 07:29:43 am
The plugin download does not have the fix in it.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 15, 2022, 02:15:44 pm
Hi, I try to debug this plugin, but I have always have this line hit:

Code
// ----------------------------------------------------------------------------
void CodeCompletion::OnAttach()
// ----------------------------------------------------------------------------
{
    AppVersion appVersion;
    appVersion.m_AppName = "clangd_client";
    // Set current plugin version
PluginInfo* pInfo = (PluginInfo*)(Manager::Get()->GetPluginManager()->GetPluginInfo(this));
pInfo->version = appVersion.GetVersion();

    // ccmanager's config obtained from Menu=>Settings=>Editor=>Code Completion (sub panel)
    // Get the CB config item that enables CodeCompletion
    ConfigManager* ccmcfg = Manager::Get()->GetConfigManager(_T("ccmanager"));
    m_CodeCompletionEnabled = ccmcfg->ReadBool(_T("/code_completion"), false);
    if (not m_CodeCompletionEnabled)
    {
        pInfo->version = pInfo->version.BeforeFirst(' ') + " Inactive";
        return;
    }


I have always get the m_CodeCompletionEnabled is false, and I have no idea how to enable it.

What I did is like below:

1, I have build a normal cbp:

Code
D:\code\cb\cb_sf_git\cccrash2019\src\CodeBlocks_wx31_64.cbp

I just build it.

2, I just open the downloaded clangd_client project, and I changed some build options:

In the build option custom variables, I set the variable:  TARGET_DEVEL_DIR
as the value: D:\code\cb\cb_sf_git\cccrash2019, which is the root folder of my local C::B git/svn

3, I changed the output filename as:
Code
$(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\plugins\clangd_client.dll

which means the build target(clangd_client.dll) will be put in the same folder as the other core plugins.

4,  I set the Execution working dir as:

Code
$(TARGET_DEVEL_DIR)\src\devel31_64

Which is the folder where codeblocks.exe locates.

5,  I change the post build script as:

Code
cmd /c if not exist $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks mkdir $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks
zip -jq9 $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/manifest.xml src/resources/*.xrc
zip -r9  $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/images > nul

This means I make a clangd_client.zip, and put it in the destination devel31_64 folder.




Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 15, 2022, 06:59:46 pm
Hi, I try to debug this plugin, but I have always have this line hit:


I have always get the m_CodeCompletionEnabled is false, and I have no idea how to enable it.

What I did is like below:

1, I have build a normal cbp:

Code
D:\code\cb\cb_sf_git\cccrash2019\src\CodeBlocks_wx31_64.cbp

I just build it.

2, I just open the downloaded clangd_client project, and I changed some build options:

In the build option custom variables, I set the variable:  TARGET_DEVEL_DIR
as the value: D:\code\cb\cb_sf_git\cccrash2019, which is the root folder of my local C::B git/svn

3, I changed the output filename as:
Code
$(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\plugins\clangd_client.dll

which means the build target(clangd_client.dll) will be put in the same folder as the other core plugins.

4,  I set the Execution working dir as:

Code
$(TARGET_DEVEL_DIR)\src\devel31_64

Which is the folder where codeblocks.exe locates.

5,  I change the post build script as:

Code
cmd /c if not exist $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks mkdir $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks
zip -jq9 $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/manifest.xml src/resources/*.xrc
zip -r9  $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/images > nul

This means I make a clangd_client.zip, and put it in the destination devel31_64 folder.

The variable m_CodeCompletionEnabled should,in fact, be false.
Note that the line:     m_CodeCompletionEnabled = ccmcfg->ReadBool(_T("/code_completion"), false);

is asking if the old code_completion is enabled. It not asking if "/clangd_client" is enabled.
"/code_completion" must be disabled for clangd_client to run.
I'll change the comments to make that clearer.

Edit: 2022/01/15 10:30
I might be wrong about this. I'll do more checking.

The .cbp you've created look good.

Just a little more information.

Run or debug the CB you created the plugin for.
In the menu for the running debugged/run CB
Go to MainMenu=>Plugins=>Manage Plugins and tell us what the clangd_client plugin version is:

(https://forums.codeblocks.org/index.php?action=dlattach;topic=24357.0;attach=11062;image)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 15, 2022, 09:51:15 pm
@ollydbg

When you run the debugger, CB  ordinary uses the personality "default" which, for you, I'm guessing has CodeCompletion plugin enabled.

You should use a separate personality for debugging so that you can disable CodeCompletion in the debugged CB without disabling it in your production CB.

For me, in CB main menu/project/SetProgramArgument I have:
--debug-log --no-dde --no-check-associations --multiple-instance --no-splash-screen --verbose /p cbDebug315

Then I can disable CodeCompletion in the debugged CB MainMenu/plugins/managePlugins without it affecting the main CB personality "default".

I'd still like to see the "manage plugins" status of both clangd_client and Code Completion plugins to determine why your m_CodeCompletionEnabled variable is false.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 15, 2022, 10:32:40 pm
@ollydbg

m_CodeCompletionEnabled variable refers to Settings/Editor/Code completion checkbox.

For your debugged CB, it must be currently unchecked which means neither Code completion nor clangd_client can run.


Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 02:10:21 am
@ollydbg

m_CodeCompletionEnabled variable refers to Settings/Editor/Code completion checkbox.

For your debugged CB, it must be currently unchecked which means neither Code completion nor clangd_client can run.

I have screen shots, see below as in attachment.

I have Settings/Editor/Code completion checkbox checked. If I member correctly this checkbox does not mean we should "disable" the plugin, instead, it means we don't show the suggestion prompt when we are editing.

The other screen shot shows the version latest version I'm using.

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 02:24:36 am
@ollydbg

When you run the debugger, CB  ordinary uses the personality "default" which, for you, I'm guessing has CodeCompletion plugin enabled.

You should use a separate personality for debugging so that you can disable CodeCompletion in the debugged CB without disabling it in your production CB.

For me, in CB main menu/project/SetProgramArgument I have:
--debug-log --no-dde --no-check-associations --multiple-instance --no-splash-screen --verbose /p cbDebug315

Then I can disable CodeCompletion in the debugged CB MainMenu/plugins/managePlugins without it affecting the main CB personality "default".

I'd still like to see the "manage plugins" status of both clangd_client and Code Completion plugins to determine why your m_CodeCompletionEnabled variable is false.

I'm using the same CB personality cbDebug315 as yours. Because I'm running the debugger from the clangd_client_wx31_64.cbp.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 16, 2022, 02:34:34 am
@ollydbg

m_CodeCompletionEnabled variable refers to Settings/Editor/Code completion checkbox.

For your debugged CB, it must be currently unchecked which means neither Code completion nor clangd_client can run.

I have screen shots, see below as in attachment.

I have Settings/Editor/Code completion checkbox checked. If I member correctly this checkbox does not mean we should "disable" the plugin, instead, it means we don't show the suggestion prompt when we are editing.

The other screen shot shows the version latest version I'm using.

I'll look into the historical usage of the Settings/Editor/Code completion box.

Are these snapshots form the debugger or the debuggee ?
I think your debugged CB (the debuggee) has that box unchecked.
Would you give us a snapshot of your debugged CB Settings/Editor/Code completion box while the debugger is running?

Thanks for testing. It helps.
 
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 02:39:10 am
@ollydbg

m_CodeCompletionEnabled variable refers to Settings/Editor/Code completion checkbox.

For your debugged CB, it must be currently unchecked which means neither Code completion nor clangd_client can run.

I have screen shots, see below as in attachment.

I have Settings/Editor/Code completion checkbox checked. If I member correctly this checkbox does not mean we should "disable" the plugin, instead, it means we don't show the suggestion prompt when we are editing.

The other screen shot shows the version latest version I'm using.

I'll look into the historical usage of the Settings/Editor/Code completion box.

Are these snapshots form the debugger or the debuggee ?

debugee.






Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 03:08:27 am
This is the whole patch I'm using:

Code
 clangd_client/clangd_client_wx31_64.cbp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/clangd_client/clangd_client_wx31_64.cbp b/clangd_client/clangd_client_wx31_64.cbp
index 1af073c..eb3e6d4 100644
--- a/clangd_client/clangd_client_wx31_64.cbp
+++ b/clangd_client/clangd_client_wx31_64.cbp
@@ -6,8 +6,8 @@
  <Option compiler="gcc" />
  <Build>
  <Target title="Clangd_Client-uw">
- <Option output="bin/Clangd_Client" prefix_auto="1" extension_auto="1" />
- <Option working_dir="bin31_64" />
+ <Option output="$(TARGET_DEVEL_DIR)/src/devel31_64/share/CodeBlocks/plugins/clangd_client" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="$(TARGET_DEVEL_DIR)/src/devel31_64" />
  <Option object_output=".objs31_64" />
  <Option external_deps="$(CODEBLOCKS)/libcodeblocks.a;" />
  <Option type="3" />
@@ -50,12 +50,13 @@
  <Add before="cmd /c @echo CODEBLOCKS: $(CODEBLOCKS)" />
  <Add before="cmd /c @echo TARGET_DEVEL_DIR: $(TARGET_DEVEL_DIR)" />
  <Add before="g++ --version" />
- <Add after="cmd /c MakeRepoUpload.bat" />
+ <Add after="cmd /c if not exist $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks mkdir $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks" />
+ <Add after="zip -jq9 $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/manifest.xml src/resources/*.xrc" />
+ <Add after="zip -r9  $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/images" />
  <Mode after="always" />
  </ExtraCommands>
  <Environment>
- <Variable name="TARGET_DEVEL_DIR" value="$(CODEBLOCKS)\..\.." />
- <Variable name="TARGET_DEVEL_DIR_AC" value="D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller" />
+ <Variable name="TARGET_DEVEL_DIR" value="D:\code\cb\cb_sf_git\cccrash2019" />
  </Environment>
  </Target>
  <Environment>


Note that the post build command has changed, I just removed the last " > nul", which causes some warning.

Code
zip -r9  $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/images
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 16, 2022, 03:17:19 am
@ollydbg.

Well, I'm at a loss to figure out why that variable is false for you.

Somehow, clangd_client is seeing Setting/Editor/Code completion as unchecked in your  CB .conf file.

This has nothing to do with your .cbp file. It's the contents of the .conf file that the debugger is using that's causing this problem.

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 03:24:31 am
@ollydbg.

Well, I'm at a loss to figure out why that variable is false for you.

Somehow, clangd_client is seeing Setting/Editor/Code completion as unchecked in your  CB .conf file.

This has nothing to do with your .cbp file. It's the contents of the .conf file that the debugger is using that's causing this problem.

Hi, Pecan, thanks for the help, I will try to debug this issue and see what happens in the code.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 03:45:19 am
I see some code:

Code
    wxString fileURI = fileUtils.FilePathToURI(infilename); //(ph 2022/01/5)
    fileURI.Replace("\\", "/");
    DocumentUri docuri = DocumentUri(fileURI.c_str());
    cbStyledTextCtrl* pCntl = pcbEd->GetControl();
    if (not pCntl) return false;

    // save current length of the file
    m_FileLinesHistory[pcbEd] = pCntl->GetLineCount();

    wxString strText = pCntl->GetText();
    const char* pText = strText.mb_str();           //works

    writeClientLog(wxString::Format("<<< LSP_DidOpen:%s", docuri.c_str()) );

    try { DidOpen(docuri, string_ref(pText, strText.Length()) ); }
    catch(std::exception &err)
    {
        //printf("read error -> %s\nread -> %s\n ", e.what(), read.c_str());
        wxString errMsg(wxString::Format("\nLSP_DidOpen() error: %s\n%s", err.what(), docuri.c_str()) );
        writeClientLog(errMsg);
        cbMessageBox(errMsg);
        return false;
    }

My guess is that:

Code
const char* pText = strText.mb_str(); 

Is this correct?

From my point of view, it should be:

Quote
Final word of caution: most of these functions may return either directly the pointer to internal string buffer or a temporary wxCharBuffer or wxWCharBuffer object. Such objects are implicitly convertible to char and wchar_t pointers, respectively, and so the result of, for example, wxString::ToUTF8() can always be passed directly to a function taking const char*. However code such as

Code
const char *p = s.ToUTF8();
...
puts(p); // or call any other function taking const char *


This is from wx document here:  https://docs.wxwidgets.org/trunk/overview_unicode.html

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 04:53:58 am
I make a clean git svn clone, and it looks like the clangd_client can be active now. I'm not sure why.

I see that the changes in my previous post did solve the error message issue. Here is the whole patch I use.

Code
 clangd_client/clangd_client_wx31_64.cbp    | 11 ++++++-----
 clangd_client/src/LSPclient/src/client.cpp |  4 ++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/clangd_client/clangd_client_wx31_64.cbp b/clangd_client/clangd_client_wx31_64.cbp
index 1af073c..eb3e6d4 100644
--- a/clangd_client/clangd_client_wx31_64.cbp
+++ b/clangd_client/clangd_client_wx31_64.cbp
@@ -6,8 +6,8 @@
  <Option compiler="gcc" />
  <Build>
  <Target title="Clangd_Client-uw">
- <Option output="bin/Clangd_Client" prefix_auto="1" extension_auto="1" />
- <Option working_dir="bin31_64" />
+ <Option output="$(TARGET_DEVEL_DIR)/src/devel31_64/share/CodeBlocks/plugins/clangd_client" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="$(TARGET_DEVEL_DIR)/src/devel31_64" />
  <Option object_output=".objs31_64" />
  <Option external_deps="$(CODEBLOCKS)/libcodeblocks.a;" />
  <Option type="3" />
@@ -50,12 +50,13 @@
  <Add before="cmd /c @echo CODEBLOCKS: $(CODEBLOCKS)" />
  <Add before="cmd /c @echo TARGET_DEVEL_DIR: $(TARGET_DEVEL_DIR)" />
  <Add before="g++ --version" />
- <Add after="cmd /c MakeRepoUpload.bat" />
+ <Add after="cmd /c if not exist $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks mkdir $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks" />
+ <Add after="zip -jq9 $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/manifest.xml src/resources/*.xrc" />
+ <Add after="zip -r9  $(TARGET_DEVEL_DIR)\src\devel31_64\share\CodeBlocks\clangd_client.zip src/resources/images" />
  <Mode after="always" />
  </ExtraCommands>
  <Environment>
- <Variable name="TARGET_DEVEL_DIR" value="$(CODEBLOCKS)\..\.." />
- <Variable name="TARGET_DEVEL_DIR_AC" value="D:\Andrew_Development\WorkingOnThese\AC-WindowsInstaller" />
+ <Variable name="TARGET_DEVEL_DIR" value="D:\code\cb\cb_sf_git\cccrash2019" />
  </Environment>
  </Target>
  <Environment>
diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 3aa6956..6ae6afa 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -1053,7 +1053,7 @@ bool ProcessLanguageClient::DoValidateUTF8data(std::string& data)
             char invChar = data[invloc]; // **debugging**
             data[invloc] = ' '; //clear the invalid utf8 char
             wxString msg = "Error: Removed clangd response invalid utf8 char:";
-            msg << "\'" << invChar << "\'";
+            msg << "\'" << wxString::Format("%x", invChar ) << "\'";
             Manager::Get()->GetLogManager()->DebugLog(msg);
         }
     }
@@ -1562,7 +1562,7 @@ bool ProcessLanguageClient::LSP_DidOpen(cbEditor* pcbEd)
     m_FileLinesHistory[pcbEd] = pCntl->GetLineCount();
 
     wxString strText = pCntl->GetText();
-    const char* pText = strText.mb_str();           //works
+    const char* pText = strText.ToUTF8();           // ollydbg 2022-01-16
 
     writeClientLog(wxString::Format("<<< LSP_DidOpen:%s", docuri.c_str()) );
 


Note the change in :

Code
msg << "\'" << wxString::Format("%x", invChar ) << "\'";

is also try to suppress a message alert box(an ascii char to wxString convert, but the invChar value is bigger than 127)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 16, 2022, 07:14:00 am
@ollydbg

Thanks for working on that. I'll give those changes a test tomorrow.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 16, 2022, 12:09:08 pm
I have another patch, it looks like this code should be enabled:
Code
 clangd_client/src/LSPclient/src/client.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 6ae6afa..88f5f8f 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -2443,7 +2443,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
 
     // Assure text is UTF8 before handing to DidChange()
     didChangeEvent.text = edText;
-    // didChangeEvent.text = edText.ToUTF8(); Trying to find bad utf8 problem
+    didChangeEvent.text = edText.ToUTF8(); //Trying to find bad utf8 problem
     std::vector<TextDocumentContentChangeEvent> tdcce{didChangeEvent};
     DocumentUri docuri = DocumentUri(fileURI.c_str());
     // **debugging**
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 17, 2022, 12:32:16 pm
I see there are many pch files in the folder such as:

C:\Users\[myusername]\AppData\Local\Temp\preamble-c7460b.pch

I think those files is created by clangd, and are there any way to automatically delete them when exit C::B?

EDIT:

clangd writes too much disk : CPP-19402 (https://youtrack.jetbrains.com/issue/CPP-19402)

This discussion looks like the pch can keep in "memory". :)
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 17, 2022, 01:14:47 pm
I see some error message comes from this function call, but I'm not sure why, this happens when I'm editing source file in the C::B editor.

Code
int ProcessLanguageClient::ReadLSPinputLength()
// ----------------------------------------------------------------------------
{
    // this function is driven by readJson() via the thread in transport::loop()
    // and the incoming data is locked.
    // thread was started in constructor and called from readJason() after locking the buffer

    // "Content-Length: <digits>\r\n\r\n"

    if (Has_LSPServerProcess() and m_std_LSP_IncomingStr.length())
    {
        // search for LSP header
        size_t hdrPosn = m_std_LSP_IncomingStr.find("Content-Length: ");
        if (hdrPosn == std::string::npos)
            return wxNOT_FOUND;
        else //have incoming text
        {
            if (hdrPosn != 0)   // verify LSP header is at beginning of buffer
            {
                // Error: header is not at beginning of buffer. Try to fix it.
                // usually caused by clangd invalid utf8 sequence
                wxString msg(wxString::Format("ERROR:%s(): buffLength (%d): Position of content header %d.\n",
                             __FUNCTION__, int(m_std_LSP_IncomingStr.length()), int(hdrPosn)) );
                msg += "Buffer contents written to client log.";
                #if defined(cb_DEBUG)
                    wxSafeShowMessage("Input Buffer error",msg);
                #endif
                msg += "LSP_IncomingStrBuf:\n" + m_std_LSP_IncomingStr + "\n";
                writeClientLog(msg);
                // adjust the data buf to get clangd header at buff beginning
                m_std_LSP_IncomingStr = m_std_LSP_IncomingStr.substr(hdrPosn);
            }

I just enabled the log file, and see the log message(in C:\Users\[myusername]\AppData\Local\Temp\CBclangd_client-1332.log

And the content of the log file are:

Code
19:45:09.758 ERROR:ReadLSPinputLength(): buffLength (549): Position of content header 112.
Buffer contents written to client log.LSP_IncomingStrBuf:
":{"newText":"wxConvAuto($0)","range":{"end":{"character":16,"line":94},"start":{"character":12,"line":94}}}}]}}Content-Length: 414



{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"category":"Parse Issue","code":"expected_unqualified_id","codeActions":[],"message":"Expected unqualified-id","range":{"end":{"character":14,"line":97},"start":{"character":12,"line":97}},"relatedInformation":[],"severity":1,"source":"clang"}],"uri":"file:///F:/test/Config.cpp","version":1}}
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 17, 2022, 02:56:17 pm
I see there are many pch files in the folder such as:

C:\Users\[myusername]\AppData\Local\Temp\preamble-c7460b.pch

I think those files is created by clangd, and are there any way to automatically delete them when exit C::B?

EDIT:

clangd writes too much disk : CPP-19402 (https://youtrack.jetbrains.com/issue/CPP-19402)

This discussion looks like the pch can keep in "memory". :)

Here is the patch to fix this pch file issue:

Code
 clangd_client/src/LSPclient/src/client.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 88f5f8f..f6b5eb9 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -266,6 +266,10 @@ ProcessLanguageClient::ProcessLanguageClient(const cbProject* pProject, const ch
 
     command += " --limit-results=20";              // Limit the number of results returned by clangd. 0 means no limit (default=100)
 
+    // clangd writes too much disk : CPP-19402 https://youtrack.jetbrains.com/issue/CPP-19402
+    // "-pch-storage=memory"
+    command += " -pch-storage=memory";
+
     if (wxDirExists(clangResourceDir))
         command += " --resource-dir=" + clangResourceDir;  // Directory for system includes
 
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 18, 2022, 12:35:08 pm
I see there are some code snippet like:

Code
m_MutexInputBufGuard.Lock;

m_MutexInputBufGuard.Unlock();

But in the code, we have to carefully handle the unlocking the wxMutex when return the function body, especially when there are multiply returns.

Is it possible to use the wxMutexLocker, and check the IsOK() function for checking whether it get locked or not.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 18, 2022, 08:23:19 pm
I see some error message comes from this function call, but I'm not sure why, this happens when I'm editing source file in the C::B editor.

Code
int ProcessLanguageClient::ReadLSPinputLength()
// ----------------------------------------------------------------------------
{
    // this function is driven by readJson() via the thread in transport::loop()
    // and the incoming data is locked.
    // thread was started in constructor and called from readJason() after locking the buffer

    // "Content-Length: <digits>\r\n\r\n"

    if (Has_LSPServerProcess() and m_std_LSP_IncomingStr.length())
    {
        // search for LSP header
        size_t hdrPosn = m_std_LSP_IncomingStr.find("Content-Length: ");
        if (hdrPosn == std::string::npos)
            return wxNOT_FOUND;
        else //have incoming text
        {
            if (hdrPosn != 0)   // verify LSP header is at beginning of buffer
            {
                // Error: header is not at beginning of buffer. Try to fix it.
                // usually caused by clangd invalid utf8 sequence
                wxString msg(wxString::Format("ERROR:%s(): buffLength (%d): Position of content header %d.\n",
                             __FUNCTION__, int(m_std_LSP_IncomingStr.length()), int(hdrPosn)) );
                msg += "Buffer contents written to client log.";
                #if defined(cb_DEBUG)
                    wxSafeShowMessage("Input Buffer error",msg);
                #endif
                msg += "LSP_IncomingStrBuf:\n" + m_std_LSP_IncomingStr + "\n";
                writeClientLog(msg);
                // adjust the data buf to get clangd header at buff beginning
                m_std_LSP_IncomingStr = m_std_LSP_IncomingStr.substr(hdrPosn);
            }

I just enabled the log file, and see the log message(in C:\Users\[myusername]\AppData\Local\Temp\CBclangd_client-1332.log

And the content of the log file are:

Code
19:45:09.758 ERROR:ReadLSPinputLength(): buffLength (549): Position of content header 112.
Buffer contents written to client log.LSP_IncomingStrBuf:
":{"newText":"wxConvAuto($0)","range":{"end":{"character":16,"line":94},"start":{"character":12,"line":94}}}}]}}Content-Length: 414



{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"category":"Parse Issue","code":"expected_unqualified_id","codeActions":[],"message":"Expected unqualified-id","range":{"end":{"character":14,"line":97},"start":{"character":12,"line":97}},"relatedInformation":[],"severity":1,"source":"clang"}],"uri":"file:///F:/test/Config.cpp","version":1}}

This is caused by clangd sending a message (usually a code completion response) with an illegal utf8 char. Clangd sets the message with a header specifying the wrong length which eats up the content-header for the following message.


I have to correct the situation by searching for the content-header.
I have now commented out that message box. The code works to correct the situation so we don't need that anymore.

Thanks for testing and finding these "gotchas" I've forgotten about.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 18, 2022, 08:30:01 pm
I see there are many pch files in the folder such as:

C:\Users\[myusername]\AppData\Local\Temp\preamble-c7460b.pch

I think those files is created by clangd, and are there any way to automatically delete them when exit C::B?

EDIT:

clangd writes too much disk : CPP-19402 (https://youtrack.jetbrains.com/issue/CPP-19402)

This discussion looks like the pch can keep in "memory". :)

Here is the patch to fix this pch file issue:

Code
 clangd_client/src/LSPclient/src/client.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 88f5f8f..f6b5eb9 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -266,6 +266,10 @@ ProcessLanguageClient::ProcessLanguageClient(const cbProject* pProject, const ch
 
     command += " --limit-results=20";              // Limit the number of results returned by clangd. 0 means no limit (default=100)
 
+    // clangd writes too much disk : CPP-19402 https://youtrack.jetbrains.com/issue/CPP-19402
+    // "-pch-storage=memory"
+    command += " -pch-storage=memory";
+
     if (wxDirExists(clangResourceDir))
         command += " --resource-dir=" + clangResourceDir;  // Directory for system includes
 

Thanks for that.

I've added code to remove preamble-*.tmp and preamble-*.pch files when the project closes.

I'll later add an option to keep the .pch in memory. (For me, I'd rather keep them on disk and remove them at project close time).

As an aside: Windows does not allow me to remove files that are open and being used. But Linux does. Do you know of a way to tell Linux NOT to allow me to delete open files?
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 18, 2022, 08:54:19 pm
I see there are some code snippet like:

Code
m_MutexInputBufGuard.Lock;

m_MutexInputBufGuard.Unlock();

But in the code, we have to carefully handle the unlocking the wxMutex when return the function body, especially when there are multiply returns.

Is it possible to use the wxMutexLocker, and check the IsOK() function for checking whether it get locked or not.

There are only 2 locks in the code that can cause any trouble. The lock on the input buffer. One to write to the buffer, and one to get the next clangd response out of the buffer. And neither affect the UI thread.

I tried wxMutexLocker first before giving up on it.
I want to be able to unlock the input buffer and then do more work in the function.
When I unlocked the mutex before the function ended,  wxWidgets gave me errors about the mutex. I lost confidence that I could mix a wxMutexLocker and manual unlocks.

In fact, I removed all locks on the main UI thread and used idle time callbacks instead.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 20, 2022, 08:07:39 am
I see there are some code snippet like:

Code
m_MutexInputBufGuard.Lock;

m_MutexInputBufGuard.Unlock();

But in the code, we have to carefully handle the unlocking the wxMutex when return the function body, especially when there are multiply returns.

Is it possible to use the wxMutexLocker, and check the IsOK() function for checking whether it get locked or not.

There are only 2 locks in the code that can cause any trouble. The lock on the input buffer. One to write to the buffer, and one to get the next clangd response out of the buffer. And neither affect the UI thread.

I tried wxMutexLocker first before giving up on it.
I want to be able to unlock the input buffer and then do more work in the function.
When I unlocked the mutex before the function ended,  wxWidgets gave me errors about the mutex. I lost confidence that I could mix a wxMutexLocker and manual unlocks.

In fact, I removed all locks on the main UI thread and used idle time callbacks instead.

Yes, there are only There are only 2 locks in the code. Sometimes, I got error message about lock failed, I'm not sure why.

BTW: since the console pipe is connected with clangd.exe, I'm not sure why the locker is needed. Since the content is from a thread to the main GUI thread by the Event, when you got the Event, you were already in the main GUI thread, and the content in the Event(wxThreadEvent) is already deep copied. So, I think the locker is not necessary, am I correct?

Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 20, 2022, 11:49:52 pm

BTW: since the console pipe is connected with clangd.exe, I'm not sure why the locker is needed. Since the content is from a thread to the main GUI thread by the Event, when you got the Event, you were already in the main GUI thread, and the content in the Event(wxThreadEvent) is already deep copied. So, I think the locker is not necessary, am I correct?

There are two non main UI threads accessing the clangd input buffer. The pipe thread and the ReadJson thread. Without the lock I assume the ReadJason thread could remove data at the same time the pipe "ProcessEvent" was writing to the (UI client.h) std::string buffer.

the "locks failed" messages could be coming from attempts to lock the symbols tree (comsuming). But it's ok. If the symbols tree update thread can't get the lock. Its ok to block.

If the lock fails in :LSP_ParseDocumentSymbols (stows symbols in tree), it just requeues itself for an idle time callback. It does not block. 
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 21, 2022, 02:50:10 am

BTW: since the console pipe is connected with clangd.exe, I'm not sure why the locker is needed. Since the content is from a thread to the main GUI thread by the Event, when you got the Event, you were already in the main GUI thread, and the content in the Event(wxThreadEvent) is already deep copied. So, I think the locker is not necessary, am I correct?

There are two non main UI threads accessing the clangd input buffer. The pipe thread and the ReadJson thread. Without the lock I assume the ReadJason thread could remove data at the same time the pipe "ProcessEvent" was writing to the (UI client.h) std::string buffer.

the "locks failed" messages could be coming from attempts to lock the symbols tree (comsuming). But it's ok. If the symbols tree update thread can't get the lock. Its ok to block.

If the lock fails in :LSP_ParseDocumentSymbols (stows symbols in tree), it just requeues itself for an idle time callback. It does not block.

Hi, Pecan. Thanks for the explanation.

I'm surprised to find that you implemented the symbol tree. This is really a good job!

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 22, 2022, 08:32:18 am
FYI:

I have make a simple wiki page:

CB Clangd Client - Code::Blocks (https://wiki.codeblocks.org/index.php/CB_Clangd_Client)

 ;)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 22, 2022, 07:48:04 pm
FYI:

I have make a simple wiki page:

CB Clangd Client - Code::Blocks (https://wiki.codeblocks.org/index.php/CB_Clangd_Client)

 ;)

Thanks, Someday I'll get a chance to add more info.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 23, 2022, 12:47:55 pm
CB Clangd Client / Code / Commit [r32] (https://sourceforge.net/p/cb-clangd-client/code/32/)

Please note that in this revision.
I'm using the Windows clangd_client_wx31_64.cbp
The generated dll file name is:  Clangd_Client.dll
And the zip file name is: clangd_client.zip

Do you think the name should be the same? I mean to keep the case consistent.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 23, 2022, 03:58:56 pm
I see an alert from this code snippet, and here is the fix:

Code
 clangd_client/src/LSPclient/src/client.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index 459b809..e03730d 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -1073,7 +1073,7 @@ bool ProcessLanguageClient::DoValidateUTF8data(std::string& data)
             std::string invStr(&data[invloc], 1);
             //unsigned int invInt = (unsigned int)data[invloc];
             unsigned char invChar(invStr[0]);
-            wxUniChar uniChar(invChar);
+            wxUniChar uniChar((unsigned int)invChar);
 
             // clangd response:
             // {"id":"textDocument/completion","jsonrpc":"2.0","result":{


When debugging, I see that the "invChar" is 161(dec), and it cause the alert from wx.
So, we have to first convert to "unsigned int".

See the document from: wxWidgets: wxUniChar Class Reference (https://docs.wxwidgets.org/3.0/classwx_uni_char.html#a8838f0ebdf714f804cbeaf70aabb4f77)


Quote
wxUniChar::wxUniChar    (    unsigned char     c   )    

Create a character from the 8-bit character value c using the current locale encoding.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 23, 2022, 09:59:29 pm
CB Clangd Client / Code / Commit [r32] (https://sourceforge.net/p/cb-clangd-client/code/32/)

Please note that in this revision.
I'm using the Windows clangd_client_wx31_64.cbp
The generated dll file name is:  Clangd_Client.dll
And the zip file name is: clangd_client.zip

Do you think the name should be the same? I mean to keep the case consistent.

I do, but others did not. Wasn't worth quibbling about to me.

Thanks for the wxUniChar fix.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on January 23, 2022, 10:43:26 pm
The plugin spec says they need to be the same. I cannot remember which OS or if it was the plugin, but case differences have caused me problems. I missed this one when comparing CodeBlocks_wx31_64.cbp and clangd_client_wx31_64.cbp changes for the plugin as my CodeBlocks_wx31_64.cbp has the following line for the output:

                <Option output="devel31_64/share/CodeBlocks/plugins/clangd_client" prefix_auto="1" extension_auto="1" />

Title: Re: Code completion using LSP and clangd
Post by: Pecan on January 23, 2022, 11:46:27 pm
@ ollydbg

This change didn't work for me. (Message #69)

I want the codepoint. I don't get any asserts.

With "wxUniChar uniChar(invChar);" I get:
Code
Error: Removed clangd response invalid utf8 char:position(3665), hex(85), U(2026), <cant post> ResponseID:textDocument/completion
Note that I get the codepoint U(2026) back.

With "wxUniChar uniChar(unsigned int(invChar));" I get:

Code
Error: Removed clangd response invalid utf8 char:position(6899), hex(85), U(85), ,<cant post on sf>. ResponseID:textDocument/completion
Here I get only the hex value.

So I changed the wxString::Format to:
Code
msg += wxString::Format("position(%d), hex(%02hhX), U(%x), \'%s\'", invloc, (unsigned int)invChar, (int)uniChar.GetValue(), invStr );
Note the "(int)uniChar.GetValue()"

I'm using wx3.1.5 on windows and wx3.0 on linux.
Works with no asserts.
Does it work for you

Note: it took me 45 minutes to post this. Don't try and post a msg with an invalid utf8 char.  It's a PITA
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 24, 2022, 02:08:15 am
The plugin spec says they need to be the same. I cannot remember which OS or if it was the plugin, but case differences have caused me problems. I missed this one when comparing CodeBlocks_wx31_64.cbp and clangd_client_wx31_64.cbp changes for the plugin as my CodeBlocks_wx31_64.cbp has the following line for the output:

                <Option output="devel31_64/share/CodeBlocks/plugins/clangd_client" prefix_auto="1" extension_auto="1" />

For generated files, I prefer the lower case file name format. Since you have the commit right to the svn repo, can you fix them?

BTW:

The custom variables in build options can be improved from my point of view:

1,  I see "TARGET_DEVEL_DIR_AC" and "TARGET_DEVEL_DIR_PECAN" and "TARGET_DEVEL_DIR" in custom variables. Can we just keep only one variable? I mean we can use a "global variable" in the Menu->Settings->Global variables. This way, we can set those variables by our own setting.

2, the name TARGET_DEVEL_DIR is not correct here. I think "DEVEL_DIR" mainly refer to a folder named "devel31_64" which store the built exe or dlls. So, a better name could be "CB_SOURCE_ROOT" which refer the the root of the svn/git source code root folder.

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 24, 2022, 03:07:08 am
@ ollydbg

This change didn't work for me. (Message #69)

I want the codepoint. I don't get any asserts.

With "wxUniChar uniChar(invChar);" I get:
Code
Error: Removed clangd response invalid utf8 char:position(3665), hex(85), U(2026), <cant post> ResponseID:textDocument/completion
Note that I get the codepoint U(2026) back.

With "wxUniChar uniChar(unsigned int(invChar));" I get:

Code
Error: Removed clangd response invalid utf8 char:position(6899), hex(85), U(85), ,<cant post on sf>. ResponseID:textDocument/completion
Here I get only the hex value.

So I changed the wxString::Format to:
Code
msg += wxString::Format("position(%d), hex(%02hhX), U(%x), \'%s\'", invloc, (unsigned int)invChar, (int)uniChar.GetValue(), invStr );
Note the "(int)uniChar.GetValue()"

I'm using wx3.1.5 on windows and wx3.0 on linux.
Works with no asserts.
Does it work for you

In my computer, it works differently than yours.

I did a simple test:

Code
    unsigned char invChar = 0x83;
    wxUniChar uniChar(invChar);

    wxString msg = wxString::Format("hex(%02hhX), U(%x)", (unsigned int)invChar, uniChar.GetValue());

    wxLogMessage(msg);

With the above code, the program just pop up an alert (see screen shot in attachment)

While, with below code, it works OK without the alert.

Code
    unsigned char invChar = 0x83;
    wxUniChar uniChar((unsigned int)invChar);

    wxString msg = wxString::Format("hex(%02hhX), U(%x)", (unsigned int)invChar, uniChar.GetValue());

    wxLogMessage(msg);

Please note that "Create a character from the 8-bit character value c using the current locale encoding.", which means in my locale encoding, a 0x83 is not a valid Unicode code point, I mean maybe we need two bytes or three bytes to convert it to a Unicode code point.

I'm not sure why in your test case, a 0x83 will becomes a larger value code point U(2026). Maybe, you have different locale encoding as mine. I'm on Windows 7 64bit Chinese language edition, so my local encoding maybe some Chinese language.



Quote
Note: it took me 45 minutes to post this. Don't try and post a msg with an invalid utf8 char.  It's a PITA
I also meet this kind of forum error from time to time. So bad.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on January 24, 2022, 03:14:55 am
This is a code format fix:

Code
 clangd_client/src/LSPclient/src/client.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clangd_client/src/LSPclient/src/client.cpp b/clangd_client/src/LSPclient/src/client.cpp
index fadcb51..459b809 100644
--- a/clangd_client/src/LSPclient/src/client.cpp
+++ b/clangd_client/src/LSPclient/src/client.cpp
@@ -702,9 +702,9 @@ void ProcessLanguageClient::OnLSP_Terminated(wxThreadEvent& event_pipedprocess_t
     wxCommandEvent terminatedEvt(wxEVT_COMMAND_MENU_SELECTED, XRCID("idLSP_Process_Terminated"));
     terminatedEvt.SetEventObject((wxObject*)m_pCBProject);
     terminatedEvt.SetInt(processExitCode);
-    Manager::Get()->GetAppFrame()->GetEventHandler()->ProcessEvent(terminatedEvt)
+    Manager::Get()->GetAppFrame()->GetEventHandler()->ProcessEvent(terminatedEvt);
 
-;    if (processExitCode != 0)
+    if (processExitCode != 0)
     {
         wxString msg = "Unusual termination of LanguageProcessClient(LSP) occured.";
         if (lspClientLogFile.IsOpened() )
Title: Re: Code completion using LSP and clangd
Post by: kipade on February 01, 2022, 10:28:07 am
It works fine for my first try. Its so cool.
My local environment:
wx 3.1.6
gcc 11.2
newest cb
Thanks your GREAT job!
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on February 02, 2022, 09:37:22 am
The changes in commit r12689 may apply to this plugin.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on February 02, 2022, 10:15:12 am
Thanks. I created a ticket in the SF clangd_client project so that it gets tested and checked when time permits.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 02, 2022, 09:06:47 pm
The changes in commit r12689 may apply to this plugin.

Applied to clangd_client rev 39/40; Thanks Miguel and Andrew
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 03, 2022, 03:33:41 pm
Hi, Pecan, I see some code snippet:

Code
        ConfigManager *cfgApp = Manager::Get()->GetConfigManager(_T("app"));
        bool i18n = cfgApp->ReadBool(_T("/locale/enable"), false);

I think the i18n is not a correct variable to check whether the later "(unsigned int)invChar" should be casted.
I think the i18n is used to identify whether a custom language translation is used for the GUI. For me, this value is false, because I use the default English version.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 03, 2022, 04:03:39 pm
One issue I see when using this plugin to parse the "Code::Blocks wx3.1.x (64bit)" cbp file.

In my computer, it takes more than 15 minutes, but from the "Code::Blocks Debug" log, I still see there are more than 280 more files need to be parsed. I see the "clangd.exe" eat about 75% of my cpu usage.

Is there option that we can only parse the active cpp files? Or active target source files. It looks like parsing the whole projects is really slow.  :(

Thanks.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 03, 2022, 07:20:50 pm
One issue I see when using this plugin to parse the "Code::Blocks wx3.1.x (64bit)" cbp file.

In my computer, it takes more than 15 minutes, but from the "Code::Blocks Debug" log, I still see there are more than 280 more files need to be parsed. I see the "clangd.exe" eat about 75% of my cpu usage.

Is there option that we can only parse the active cpp files? Or active target source files. It looks like parsing the whole projects is really slow.  :(

Thanks.

You do not have to wait for all files to parse to use clangd.

Re: cpu usage. Set concurrently parsing threads to 2 at
   Setting->Editor->Clangd_Client->C.C++ parser(tab)->Concurrently parsing threads.

You should not worry about parsing going on in the background when restricting the number of parsing threads. My cpu usage is only 34% when I restrict concurrent parsing to 2 threads. And clangd response is quite fast.
(Intel i7 with 8 threads), only half of the threads are allowed to be used by clangd (hard coded), and only 2 to be used for background parsing (user option).

Active editors always get parsed first, then inactive editors, then background (non-editor) files. Newly opened editors go to the head of the queue and get parsed ahead of background files. Code completion requests also go to the head of queue.

There's no need to wait after the active editor is parsed (3 to 7 secs).
 
When I open CodeBlocks workspace (31_64), the active editor is indexed by clangd in a max of 7 seconds. All open editors have been indexed in less than 30 seconds. But I never have to wait more then 7 seconds to use code completion or other clangd features.

All those files being parsed in the background are used to fill the symbols tree. They're parsed in order of last-changed-time, then last-opened-time then all others so that the symbols tree gets filled with the most likely used files and symbols.
 
However, I'll put your suggestion in the ToDo list with an option to only parse files in editors. I don't know why you'd want to do that though, if you'll restrict the number of concurrent parsing threads.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 04, 2022, 07:04:40 am
One issue I see when using this plugin to parse the "Code::Blocks wx3.1.x (64bit)" cbp file.

In my computer, it takes more than 15 minutes, but from the "Code::Blocks Debug" log, I still see there are more than 280 more files need to be parsed. I see the "clangd.exe" eat about 75% of my cpu usage.

Is there option that we can only parse the active cpp files? Or active target source files. It looks like parsing the whole projects is really slow.  :(

Thanks.

You do not have to wait for all files to parse to use clangd.

Re: cpu usage. Set concurrently parsing threads to 2 at
   Setting->Editor->Clangd_Client->C.C++ parser(tab)->Concurrently parsing threads.

You should not worry about parsing going on in the background when restricting the number of parsing threads. My cpu usage is only 34% when I restrict concurrent parsing to 2 threads. And clangd response is quite fast.
(Intel i7 with 8 threads), only half of the threads are allowed to be used by clangd (hard coded), and only 2 to be used for background parsing (user option).

Active editors always get parsed first, then inactive editors, then background (non-editor) files. Newly opened editors go to the head of the queue and get parsed ahead of background files. Code completion requests also go to the head of queue.

There's no need to wait after the active editor is parsed (3 to 7 secs).
 
When I open CodeBlocks workspace (31_64), the active editor is indexed by clangd in a max of 7 seconds. All open editors have been indexed in less than 30 seconds. But I never have to wait more then 7 seconds to use code completion or other clangd features.

All those files being parsed in the background are used to fill the symbols tree. They're parsed in order of last-changed-time, then last-opened-time then all others so that the symbols tree gets filled with the most likely used files and symbols.
 
However, I'll put your suggestion in the ToDo list with an option to only parse files in editors. I don't know why you'd want to do that though, if you'll restrict the number of concurrent parsing threads.

Hi, thanks for the explanation.

I see in my setting: Setting->Editor->Clangd_Client->C.C++ parser(tab)->Concurrently parsing threads.

This value is 1. (I haven't change this value, so the default value is 1)

By reading the source code, I see that if the value is 1, it means we only let the indexer use 1 thread of the total CPUs. In my PC, I have a CPU with 4 threads.

So, the expected cpu usage should be 25%, am I correct?

Here is a test:
I set the value:  Setting->Editor->Clangd_Client->C.C++ parser(tab)->Concurrently parsing threads.  to 2.
Now, I see that the cpu usage of clangd.exe is about 50%.

This is interesting, as 2 means 2/4 = 50%, which is correct. 

But why the cpu usage is 75% if I set the value to 1?, I did test again, and see it is 25%, so sorry about that wrong report  :(. I may looked wrongly at the the "System Idle process" cpu usage, because when the clangd.exe use 25% cpu, and the 75% cpu is from the Idle process.


Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 04, 2022, 07:55:56 am
Maybe, the background index can be saved when we close the project, and reopen it when we load the project.

Here are some reference:

Qt Creator and clangd: An Introduction (https://www.qt.io/blog/qt-creator-and-clangd-an-introduction)
It said the index can be persistent.

Some from clangd and llvm github and forum
Ability to move a project's clangd background index without triggering reindexing  Issue #847  clangd/clangd (https://github.com/clangd/clangd/issues/847)
and Offline background index preparation  Issue #587 clangd/clangd (https://github.com/clangd/clangd/issues/587)
and Using background and static indexes simultaneously for large codebases - Clang Frontend / clangd - LLVM Discussion Forums (https://discourse.llvm.org/t/using-background-and-static-indexes-simultaneously-for-large-codebases/3706)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 04, 2022, 05:44:53 pm
Maybe, the background index can be saved when we close the project, and reopen it when we load the project.

Here are some reference:

Qt Creator and clangd: An Introduction (https://www.qt.io/blog/qt-creator-and-clangd-an-introduction)
It said the index can be persistent.

Some from clangd and llvm github and forum
Ability to move a project's clangd background index without triggering reindexing  Issue #847  clangd/clangd (https://github.com/clangd/clangd/issues/847)
and Offline background index preparation  Issue #587 clangd/clangd (https://github.com/clangd/clangd/issues/587)
and Using background and static indexes simultaneously for large codebases - Clang Frontend / clangd - LLVM Discussion Forums (https://discourse.llvm.org/t/using-background-and-static-indexes-simultaneously-for-large-codebases/3706)

Thanks for that information. I've often thought it would be nice to persist the clangd .cache and the symbols tree.
I'll put it on the ToDo list.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 07, 2022, 02:30:39 pm
I see an annoying issue that the focus changes of the log message.

Here is the steps to reproduce:

1, I hit the "save" (or the "save all") toolbar botton
2, I hit the "build" toolbar botton
3, The building process starts, and the active log is switched to the build log
4, after for a while, the active log is switched to the LSP message.


In the step 4, it is a bit annoying. Can we stop the focus switch in the step 4?
Or we can only switch the LSP message if the compiler(build process) is not running.

Thanks.


EDIT:

I see such code snippet about the log switch(focus)

Code
        // If last request was anything but "textDocument/didSave", don't steal the log focus.
        if ( not popupActive ) switch(1)
        {
            default:
            // switch to LSP messages only when user used "save"
            if (not GetLSPClient()->GetSaveFileEventOccured()) break;
            wxWindow* pFocusedWin = wxWindow::FindFocus();
            if (not GetLSPClient()->LSP_GetLog()) break;

            CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, GetLSPClient()->LSP_GetLog());
            CodeBlocksLogEvent evtShow(cbEVT_SHOW_LOG_MANAGER);
            Manager::Get()->ProcessEvent(evtSwitch);
            Manager::Get()->ProcessEvent(evtShow);
            if (pFocusedWin) pFocusedWin->SetFocus();
        }

I'm not sure why you combine the if and switch statement in the same line?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 08, 2022, 12:31:07 pm
I see some bugs here:

BUG1:

1, I have 5 cbp files in the same folder, and I also have a workspace file which contains the 5 cbp files.

2, I open the workskpace, and switch the active project between those 5 cbps

3, When I close the C::B or close the workspace, I got 4 error messages:

Code
19:17:44: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)
19:17:45: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)
19:17:45: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)
19:17:45: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)

The Chinese words means "System cannot find the file specified.".

So, I think that this plugin use the same .lock file name for all the cbp projects?



BUG2:

1, I have 5 cbp files in the same folder, and I also have a workspace file which contains the 5 cbp files.

2, I open the workskpace, and switch the active project between those 5 cbps.

3, Now, I use the git tool to update those 5 cbp files, and C::B asked that whether I need to reload the cbp files, I press "all".
Now, I see that my CPU usage is from the 25% CPU (which is the 1 thread in my clang_client setting) to 100%, and I see 4 clangd.exe running in the task manager window.
Each process of clangd eat about 25% of the cpu.

I guess that when 5 cbp files get reloaded in the same time, it will trigger several clangd.exe to run.

My testing project is:
asmwarrior/wxModularApp: Cross-Platform Modular Application (Main app + plugins) example for C++/wxWidgets (https://github.com/asmwarrior/wxModularApp)

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 09, 2022, 11:05:58 am
There is another issue to show the LSP messages.

Suppose you have several cpp files in the cbp, when you first open the cbp, you get all the LSP diagnostics from all the cpp files.

But once you edit only one cpp file, and press "save" button, the whole "LSP message" will be cleaned, and only the recent saved cpp file's diagnostics will be shown.

So, I suggest if we can only update the updated files' message, but keep the old ones, thanks.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 11, 2022, 03:26:20 am
Hi, guys, I think I found an issue when using clangd under msys2.

In the instruction:

CB Clangd Client / Code / [r41] /trunk/clangd_client/documentation-install/Windows-LLVM-ClangD-Install-Readme.txt (https://sourceforge.net/p/cb-clangd-client/code/HEAD/tree/trunk/clangd_client/documentation-install/Windows-LLVM-ClangD-Install-Readme.txt)

It said:

Code
MSYS2 Compiler - MinGW64
-------------------------
There are two main options to install the clangd.exe as follows:
    1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the following packages:
        +------------------------------------------+------------------------+
        |               Package                    | Clangd executable      |
        +------------------------------------------+------------------------+
        | mingw-w64-clang-x86_64-clang-tools-extra | clang64/bin/clangd.exe |
        | mingw-w64-x86_64-clang-tools-extra       | mingw64/bin/clangd.exe |
        +------------------------------------------+------------------------+

       To intall the package do the following:
        a)  Open the msys2.exe bash shell
        b) Run the following command:
               pacman -S <Package name in the table above>
   
 OR
    2) The second option is to intall the full Clang tool chain as follows:
        a)  Open the msys2.exe bash shell
        b) Run the following command:
               pacman -S mingw-w64-clang-x86_64-toolchain




If you are using the gcc from msys2, I mean the compilers in the folder "msys64\mingw64\bin", you should use "mingw-w64-x86_64-clang-tools-extra", which means the clangd.exe is under the folder "msys64\mingw64\bin" (the same folder in your gcc.exe).


If you are using the clang tool chain, I mean you use the compiler from the folder "msys64\clang64\bin", you should use "mingw-w64-clang-x86_64-clang-tools-extra".


I found that I just make a big mistake in one of my PC, that is I use the gcc toolchain from "msys64\mingw64\bin", but I use the clangd.exe from "msys64\clang64\bin", the result is I got a lot of LSP diagnostics messages about the errors.  ;)   Luckily I found the reason, and fix this issue. Hope this will help other guys.  :)


Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on February 11, 2022, 04:25:30 am
Can you raise a ticket for this so I do not forget about it as it may not be as simple as changing the docs as the code may need some changes to ensure that end users with GCC and CLANG do not have issues like you found.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 11, 2022, 04:39:57 am
Can you raise a ticket for this so I do not forget about it as it may not be as simple as changing the docs as the code may need some changes to ensure that end users with GCC and CLANG do not have issues like you found.

Done.

CB Clangd Client / Tickets / #37 use the compiler and clangd from the same folder(for msys2 the same package repositories) (https://sourceforge.net/p/cb-clangd-client/tickets/37/)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 21, 2022, 10:53:30 pm
Fixed rev 44

I see some bugs here:

BUG1:

1, I have 5 cbp files in the same folder, and I also have a workspace file which contains the 5 cbp files.

2, I open the workskpace, and switch the active project between those 5 cbps

3, When I close the C::B or close the workspace, I got 4 error messages:

Code
19:17:44: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)
19:17:45: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)
19:17:45: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)
19:17:45: File 'D:\code\plugin\wxModularApp\build\.cache\Clangd-cache.lock' couldn't be removed (error 2: 系统找不到指定的文件。)

The Chinese words means "System cannot find the file specified.".

So, I think that this plugin use the same .lock file name for all the cbp projects?



BUG2:

1, I have 5 cbp files in the same folder, and I also have a workspace file which contains the 5 cbp files.

2, I open the workskpace, and switch the active project between those 5 cbps.

3, Now, I use the git tool to update those 5 cbp files, and C::B asked that whether I need to reload the cbp files, I press "all".
Now, I see that my CPU usage is from the 25% CPU (which is the 1 thread in my clang_client setting) to 100%, and I see 4 clangd.exe running in the task manager window.
Each process of clangd eat about 25% of the cpu.

I guess that when 5 cbp files get reloaded in the same time, it will trigger several clangd.exe to run.

My testing project is:
asmwarrior/wxModularApp: Cross-Platform Modular Application (Main app + plugins) example for C++/wxWidgets (https://github.com/asmwarrior/wxModularApp)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 21, 2022, 10:54:20 pm
Added your comment to the Install instructions
Rev 44. Thanks

Hi, guys, I think I found an issue when using clangd under msys2.

In the instruction:

CB Clangd Client / Code / [r41] /trunk/clangd_client/documentation-install/Windows-LLVM-ClangD-Install-Readme.txt (https://sourceforge.net/p/cb-clangd-client/code/HEAD/tree/trunk/clangd_client/documentation-install/Windows-LLVM-ClangD-Install-Readme.txt)

It said:

Code
MSYS2 Compiler - MinGW64
-------------------------
There are two main options to install the clangd.exe as follows:
    1) The first option in order to  minimise disk space is to install the Clang extra tools using one of the following packages:
        +------------------------------------------+------------------------+
        |               Package                    | Clangd executable      |
        +------------------------------------------+------------------------+
        | mingw-w64-clang-x86_64-clang-tools-extra | clang64/bin/clangd.exe |
        | mingw-w64-x86_64-clang-tools-extra       | mingw64/bin/clangd.exe |
        +------------------------------------------+------------------------+

       To intall the package do the following:
        a)  Open the msys2.exe bash shell
        b) Run the following command:
               pacman -S <Package name in the table above>
   
 OR
    2) The second option is to intall the full Clang tool chain as follows:
        a)  Open the msys2.exe bash shell
        b) Run the following command:
               pacman -S mingw-w64-clang-x86_64-toolchain




If you are using the gcc from msys2, I mean the compilers in the folder "msys64\mingw64\bin", you should use "mingw-w64-x86_64-clang-tools-extra", which means the clangd.exe is under the folder "msys64\mingw64\bin" (the same folder in your gcc.exe).


If you are using the clang tool chain, I mean you use the compiler from the folder "msys64\clang64\bin", you should use "mingw-w64-clang-x86_64-clang-tools-extra".


I found that I just make a big mistake in one of my PC, that is I use the gcc toolchain from "msys64\mingw64\bin", but I use the clangd.exe from "msys64\clang64\bin", the result is I got a lot of LSP diagnostics messages about the errors.  ;)   Luckily I found the reason, and fix this issue. Hope this will help other guys.  :)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 21, 2022, 10:56:31 pm
Fixed rev 44.
Also added settings option to perform in the current manner.


There is another issue to show the LSP messages.

Suppose you have several cpp files in the cbp, when you first open the cbp, you get all the LSP diagnostics from all the cpp files.

But once you edit only one cpp file, and press "save" button, the whole "LSP message" will be cleaned, and only the recent saved cpp file's diagnostics will be shown.

So, I suggest if we can only update the updated files' message, but keep the old ones, thanks.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on February 21, 2022, 10:59:00 pm
Fixed in a rev previous to 44. Forgot to mention it.
Thanks for testing.


I see an annoying issue that the focus changes of the log message.

Here is the steps to reproduce:

1, I hit the "save" (or the "save all") toolbar botton
2, I hit the "build" toolbar botton
3, The building process starts, and the active log is switched to the build log
4, after for a while, the active log is switched to the LSP message.


In the step 4, it is a bit annoying. Can we stop the focus switch in the step 4?
Or we can only switch the LSP message if the compiler(build process) is not running.

Thanks.


EDIT:

I see such code snippet about the log switch(focus)

Code
        // If last request was anything but "textDocument/didSave", don't steal the log focus.
        if ( not popupActive ) switch(1)
        {
            default:
            // switch to LSP messages only when user used "save"
            if (not GetLSPClient()->GetSaveFileEventOccured()) break;
            wxWindow* pFocusedWin = wxWindow::FindFocus();
            if (not GetLSPClient()->LSP_GetLog()) break;

            CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, GetLSPClient()->LSP_GetLog());
            CodeBlocksLogEvent evtShow(cbEVT_SHOW_LOG_MANAGER);
            Manager::Get()->ProcessEvent(evtSwitch);
            Manager::Get()->ProcessEvent(evtShow);
            if (pFocusedWin) pFocusedWin->SetFocus();
        }

I'm not sure why you combine the if and switch statement in the same line?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on February 23, 2022, 11:49:55 am
Hi, Pecan, thanks for your fix!

Title: Re: Code completion using LSP and clangd
Post by: gd_on on February 28, 2022, 11:17:14 am
r46 version : typos : two new strings start by "Warings", should be "Warnings".
Title: Re: Code completion using LSP and clangd
Post by: BlueHazzard on March 04, 2022, 12:49:42 am
I get a lot of this message boxes (see image)
and they block the workflow quite hard. Would it be possible to log this error messages only to console, and not show a message box?
As far as i can tell they do not interfere with the plugin, at least it seems to work.

(i use not the last version of the plugin. If this is fixed in the last version please ignore this, i will update the source soon)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on March 04, 2022, 01:52:16 am
I get a lot of this message boxes (see image)
and they block the workflow quite hard. Would it be possible to log this error messages only to console, and not show a message box?
As far as i can tell they do not interfere with the plugin, at least it seems to work.

(i use not the last version of the plugin. If this is fixed in the last version please ignore this, i will update the source soon)

Those boxes were removed quite awhile back and written to the debug log instead.

You might want to download the nightly .dll and .zip, or update your clangd_client source.

Thanks for testing.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on March 20, 2022, 04:02:06 am
Is it possible to enable macro expansion for the llvm master path?

I mean this code:

Code
    ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("clangd_client"));
    wxString cfgClangdMasterPath = cfg->Read("/LLVM_MasterPath", wxString());

For example, we can enter such string in the clangd_client setting dialog.

Code
$(TARGET_COMPILER_DIR)bin\clangd.exe

BTW: I use the string:
Code
$(TARGET_COMPILER_DIR)bin\gdb.exe
under the GDB plugin setting.
Title: Re: Code completion using LSP and clangd
Post by: gd_on on March 20, 2022, 10:50:33 am
I try to use clangd plugin. I use Msys2 and the compiler installed in mingw64/bin, so following your recommandations I have installed with pacman mingw-w64-x86_64-clang-tools-extra.
clangd is installed in mingw64/bin normally. After the first installation my clang64 folder contains only empty folders (\bin, ...). I don't use clang compiler, so that's normal. Like that, clangd plugin works as it should.
Nevertheless, after some time and a few pacman updates, I see several warnings during the update process, and clang64 folders are progressively filled with different files. May be the pacman update process is not well adapted to the installation of clangd inside mingw64 folders ! Dependencies may be ? And all those new files are probably not necessary for clangd client plugin.
My question is : what is striclly necessary for clangd client usage : clangd.exe + a few dlls (used by clangd.exe or may be a static version of clangd.exe), sure, but is there anything else, other dll, other executables ? could we remove the update process to avoid unnecessary filling of clang64 folder ?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on March 20, 2022, 01:46:59 pm
Quote
Nevertheless, after some time and a few pacman updates, I see several warnings during the update process, and clang64 folders are progressively filled with different files. May be the pacman update process is not well adapted to the installation of clangd inside mingw64 folders ! Dependencies may be ? And all those new files are probably not necessary for clangd client plugin.

I have run the pacman updates today, and I didn't see such issue. I have clang64 folder, and I see there are some sub folders in this folder, but all are empty.


Quote
My question is : what is striclly necessary for clangd client usage : clangd.exe + a few dlls (used by clangd.exe or may be a static version of clangd.exe), sure, but is there anything else, other dll, other executables ? could we remove the update process to avoid unnecessary filling of clang64 folder ?

I guess your msys2 has some issue. You can try to remove the files/packages in clang64 folder, I have did that before, use such command:

Code
pacman -R $(pacman -Qsq 'mingw-w64-clang-x86_64*')
Title: Re: Code completion using LSP and clangd
Post by: gd_on on March 20, 2022, 03:28:09 pm
I have already tried to uninstall all my msys2, using the pacman -R option and even delete everything manually (C:\msys64), reinstalling msys2 (in C:\msys64), reinstalling C:\msys64\mingw64 and only clang64 extra tools in mingw64. Everything happens correctly and clangd plugin works, but after a while and several upddates with pacman during a few weeks, my C:\msys64\clang64 folder is progressively filled with different things as python, sqlite, p11-kit, ... etc. clangd.exe is still in C:\msys64\mingw64\bin.
So, what could be wrong, I don't know.

PS:
I have tried your command line. Though I was sure everything was suppressed from a previous standard clang try, many packages have been found. Obviously, there was things in the cache that was still there, but not installed as far as I understand. May be that was my problem. Wait and see in 2 or 3 weeks !
Title: Re: Code completion using LSP and clangd
Post by: Pecan on March 21, 2022, 09:11:14 pm
@Ollydbg

Is it possible to enable macro expansion for the llvm master path?
Code
$(TARGET_COMPILER_DIR)bin\clangd.exe

Yes, I'll do that. Good suggestion.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on March 23, 2022, 07:00:58 am
I have an issue to use the "find declaration" tool.
Find the declaration of a symbol in a header file, but the header file is not belong to the cbp project.


I have a project, say, it has a file named a.cpp. In this file, I have some definition like

Code
TypeA a;

And the TypeA is defined in a header file (e.g. TypeA.h), which is not belong to the cbp project, say, it could be in a include search path.

Now, when I use the "find declaration of TypeA", I see LSP can correctly jump to the TypeA.h.

Now, say the TypeA is actually a typedef, such as:

Code
typedef TypeB TypeA;

Now, when I right click on the TypeB symbol, and "find declaration of TypeB", I see the clangd_client plugin will jump a messagebox, it said:

Quote
[Window Title]
LSP OnGotoDeclaration

[Content]
The editor's file does not have an associated project.
Perhaps add the file to a project ?

[OK]

This looks wrong, I mean if the a.cpp get parsed by clangd, it should understand where TypeB is declared. So, is this a bug? I think adding the TypeA.h to my cbp project is not the correct way to solve this issue.

Any ideas?

Thanks.
Title: Re: Code completion using LSP and clangd
Post by: killerbot on March 23, 2022, 05:29:58 pm
and what does it do with :
using TypeA = TypeB;
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on March 25, 2022, 03:18:16 am
and what does it do with :
using TypeA = TypeB;

The same issue as the typedef.

Here is a simple test:

The cbp only contains main.cpp
Code
#include "TypeA.h"

int main()
{
    TypeA a;

    return 0;
}

And here are the TypeA.h

Code
#include "TypeB.h"


// typedef TypeB TypeA;


using TypeA = TypeB;

Here is TypeB.h

Code
class TypeB
{
public:
    int abc;

};

For testing, you can put the TypeA.h and TypeB.h in the same folder as main.cpp.

No, I can see that find declaration only goes from a file in cbp file to external file(a file not belong to cbp), such as main.cpp -> TypeA.h.

But find declaration will NOT go from an external file to an external file, so it failed from TypeA.h ->TypeB.h.

This is really an annoying issue. (BTW: our old code completion plugin works OK on this issue  :) )

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on March 25, 2022, 04:04:29 am
Code
// ----------------------------------------------------------------------------
void CodeCompletion::OnGotoDeclaration(wxCommandEvent& event)
// ----------------------------------------------------------------------------
{
    ProjectManager* pPrjMgr = Manager::Get()->GetProjectManager();
    cbProject* pActiveProject = pPrjMgr->GetActiveProject();
    if (not GetLSPclient(pActiveProject)) return;

    EditorManager* pEdMgr  = Manager::Get()->GetEditorManager();
    cbEditor*      pActiveEditor = pEdMgr->GetBuiltinActiveEditor();
    if (!pActiveEditor)
        return;

    TRACE(_T("OnGotoDeclaration"));

    const int pos      = pActiveEditor->GetControl()->GetCurrentPos();
    const int startPos = pActiveEditor->GetControl()->WordStartPosition(pos, true);
    const int endPos   = pActiveEditor->GetControl()->WordEndPosition(pos, true);

    wxString targetText;
    targetText << pActiveEditor->GetControl()->GetTextRange(startPos, endPos);
    if (targetText.IsEmpty())
        return;

    // prepare a boolean filter for declaration/implementation
    bool isDecl = event.GetId() == idGotoDeclaration    || event.GetId() == idMenuGotoDeclaration;
    bool isImpl = event.GetId() == idGotoImplementation || event.GetId() == idMenuGotoImplementation;
   // ----------------------------------------------------------------------------
   // LSP Goto Declaration/definition                //(ph 2020/10/12)
   // ----------------------------------------------------------------------------
    bool usingLSP_client = true;
    if (usingLSP_client)
    {
        // Assure editors file belongs to the active project (else it's not parsed yet).
        ProjectFile* pProjectFile = pActiveEditor->GetProjectFile();
        cbProject* pEdProject = pProjectFile ? pProjectFile->GetParentProject() : nullptr;
        wxString filename = pActiveEditor->GetFilename();
        if ( (not pEdProject)
             //?or (not (pEdProject == pActiveProject)) //(ph 2022/02/15)
             //?or (not pActiveProject->GetFileByFilename(filename,false))  //(ph 2022/02/15)
                or (not GetLSPclient(pEdProject))
            )
        {
            //? InfoWindow::Display("LSP " + wxString(__FUNCTION__), "Editor's file is not contained in the active project.", 6000); //(ph 2022/02/15)
            wxString msg = _("The editor's file does not have an associated ");
            if (not pEdProject)
                msg << _("project.") << _("\nPerhaps add the file to a project ?");
            else if (not GetLSPclient(pEdProject))
                msg << "clangd_client." << _("\nPerhaps the project needs to be reparsed ?");
            cbMessageBox(msg, "LSP " + wxString(__FUNCTION__));
            return;
        }


If I looked at the comment "// Assure editors file belongs to the active project (else it's not parsed yet)."

I think it is not correct, I'm not sure clangd has some feature to query if a file is parsed or not, any one know the research direction?  :) Because I can only find some information about clangd in this page: What is clangd? (https://clangd.llvm.org/), I'm not sure where is the official document of clangd, maybe I need to read the document about LSP?

EDIT:
Maybe, the LSP document is here:
language-server-protocol/protocol-2-x.md at main microsoft/language-server-protocol (https://github.com/Microsoft/language-server-protocol/blob/main/versions/protocol-2-x.md)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on March 25, 2022, 05:44:33 am

If I looked at the comment "// Assure editors file belongs to the active project (else it's not parsed yet)."

I think it is not correct, I'm not sure clangd has some feature to query if a file is parsed or not, any one know the research direction?-server-protocol[/url]

I apologize for not responding. But I'm in the middle of the US tax season. I'll respond as soon as I can get my head out  of the tax instructions.

This is not a clangd problem.
It's a "this  programmer failed to implement sending non-project files to clangd" problem.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on March 25, 2022, 06:41:51 am

If I looked at the comment "// Assure editors file belongs to the active project (else it's not parsed yet)."

I think it is not correct, I'm not sure clangd has some feature to query if a file is parsed or not, any one know the research direction?-server-protocol[/url]

I apologize for not responding. But I'm in the middle of the US tax season. I'll respond as soon as I can get my head out  of the tax instructions.

This is not a clangd problem.
It's a "this  programmer failed to implement sending non-project files to clangd" problem.

Hi, Pecan, thanks for the reply.

Maybe, we can have a mechanism that if a non-project file is opened in the editor, we can dynamically add(send) it to the clangd's database, and once the editor is closed, its content(the file) can be dynamically removed from the clangd's database.

This is only a guess.

Because, for my previous example, if I put the "TypeA.h", "TypeB.h" in the cbp file, then I see the find declaration works correctly in either header files.  :)


EDIT:
This issue maybe is related to this github issue:
Support non-self-contained files  Issue #45  clangd/clangd (https://github.com/clangd/clangd/issues/45)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on April 25, 2022, 08:59:46 pm
The current rev 50 of clangd_client adds support to load and parse non-project files (some project must be active), allow macros in clangd installation path and fixes assorted crash and logic errors.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on April 25, 2022, 11:55:41 pm
The current rev 50 of clangd_client adds support to load and parse non-project files (some project must be active), allow macros in clangd installation path and fixes assorted crash and logic errors.

Thanks, great work!

But I got build errors, see below build logs:

Code
-------------- Build: Clangd_Client-wx31_64 in Clangd_Client-wx31_64 (compiler: GNU GCC Compiler)---------------

[ 33.3%] Running target pre-build steps
[ 66.7%] cmd /c @echo TARGET_OUTPUT_DIR: devel31_64\
TARGET_OUTPUT_DIR: devel31_64\
[100.0%] cmd /c @echo TARGET_OUTPUT_FILENAME: clangd_client.dll
TARGET_OUTPUT_FILENAME: clangd_client.dll
cmd /c @ECHO TARGET_DEVEL_DIR: D:\code\cb\cb_sf_git\cccrash2019
TARGET_DEVEL_DIR: D:\code\cb\cb_sf_git\cccrash2019
[  3.4%] g++.exe -Wall -std=gnu++17 -m64 -g -g -pipe -mthreads -fmessage-length=0 -fexceptions -DHAVE_W32API_H -DBUILDING_PLUGIN -D__WXMSW__ -DWXUSINGDLL -DcbDEBUG -DNOPCH -DwxUSE_UNICODE -D_WIN64 -DCC_NO_COLLAPSE_ITEM -DLOGGING -DDONT_SHOW_SERVER_CONSOLE -ID:\code\cb\cb_sf_git\cccrash2019\src\include -ID:\code\cb\cb_sf_git\cccrash2019\src\sdk\wxscintilla\include\ -ID:\code\cb\cb_sf_git\cccrash2019\src\include\tinyxml\ -ID:\code\cb\clangd_plugin\trunk\clangd_client\src -Isrc -Isrc\LSPclient\include -Isrc\winprocess -Isrc\winprocess\asyncprocess -Isrc\winprocess\misc -IF:\code\wxWidgets-3.1.6\include -IF:\code\wxWidgets-3.1.6\lib\gcc_dll\mswu -Isdk\wxscintilla\include -Iinclude\tinyxml -Isrc\LSPclient -c D:\code\cb\clangd_plugin\trunk\clangd_client\src\codecompletion\codecompletion.cpp -o .obj\clangd_client\src\codecompletion\codecompletion.o
D:\code\cb\clangd_plugin\trunk\clangd_client\src\codecompletion\codecompletion.cpp: In member function 'ProcessLanguageClient* CodeCompletion::CreateNewLanguageServiceProcess(cbProject*)':
D:\code\cb\clangd_plugin\trunk\clangd_client\src\codecompletion\codecompletion.cpp:2995:25: error: 'class ProcessLanguageClient' has no member named 'SetParser'
 2995 |             pLSPclient->SetParser( static_cast<Parser*>(pParser));
      |                         ^~~~~~~~~
D:\code\cb\clangd_plugin\trunk\clangd_client\src\codecompletion\codecompletion.cpp: In member function 'void CodeCompletion::DoParseOpenedProjectAndActiveEditor(wxTimerEvent&)':
D:\code\cb\clangd_plugin\trunk\clangd_client\src\codecompletion\codecompletion.cpp:4747:23: error: 'class ProcessLanguageClient' has no member named 'SetParser'
 4747 |         pProxyClient->SetParser((Parser*)pProxyParser);
      |                       ^~~~~~~~~
Process terminated with status 1 (0 minute(s), 13 second(s))
2 error(s), 0 warning(s) (0 minute(s), 13 second(s))


The code snippet is around codecompletion.cpp line 2979, see below:

Code
        if (pParser)
        {
            pParser->SetLSP_Client(pLSPclient);

            // Create ProxyProject move to OnAppDoneStartup() //(ph 2022/04/16)
////            // Create a ProxyProject to use for non-project files (if not already existent )
////            GetParseManager()->SetProxyProject(pcbProject);
////            // Set the ProxyProject to share this clangd client.
////            cbProject* pProxyProject = GetParseManager()->GetProxyProject();
////            if (pProxyProject)
////            {
////                m_LSP_Clients[GetParseManager()->GetProxyProject()] = pLSPclient;
////                ParserBase* pProxyParser = GetParseManager()->GetParserByProject(pProxyProject);
////                pProxyParser->SetLSP_Client(pLSPclient);
////            }

            pLSPclient->SetParser( static_cast<Parser*>(pParser));
        }

        pLSPclient->LSP_Initialize(pcbProject);
    }
Title: Re: Code completion using LSP and clangd
Post by: BlueHazzard on April 26, 2022, 12:07:36 am
With this rev i get the following compiler errors:
Code
cb_clang\clangd_client\src\codecompletion\parser\parser.cpp|1405|error: 'class ProcessLanguageClient' has no member named 'GetClientsCBProject'; did you mean 'GetClientObject'?|
cb_clang\clangd_client\src\codecompletion\codecompletion.cpp|2995|error: 'class ProcessLanguageClient' has no member named 'SetParser'|
cb_clang\clangd_client\src\codecompletion\codecompletion.cpp|4747|error: 'class ProcessLanguageClient' has no member named 'SetParser'|

[edit:] ollydbg was faster....
Title: Re: Code completion using LSP and clangd
Post by: Pecan on April 26, 2022, 04:29:52 am
I have no idea why Tortoise svn hates me so much.

Rev 52 should now have the correct files.
I downloaded and compiled it ok.

Thanks guys !!
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on April 26, 2022, 11:59:08 am
I have no idea why Tortoise svn hates me so much.

Rev 52 should now have the correct files.
I downloaded and compiled it ok.

Thanks guys !!

Hi, Pecan, thanks for the fix.

In rev 52, why do you add a clangd_client.zip file to the repo?

BTW: I don't use TortoiseSVN, instead, I use TortoiseGit, and the git-svn bridge works OK in TortoiseGit.

EDIT:

CC_ProxyProject.cbp, what does this cbp file used for?
Title: Re: Code completion using LSP and clangd
Post by: Pecan on April 26, 2022, 05:08:29 pm
Quote from: ollydbg
In rev 52, why do you add a clangd_client.zip file to the repo?
...snip...
CC_ProxyProject.cbp, what does this cbp file used for?

That zip file got there out of frustration with Tortoise svn.
I gave up and just updated with everything from my local trunk.
I'll delete it for the next update. Thanks for the heads-up.

Re: CC_ProxyProject.cbp.
 
It's a hidden cbProject used to contain files that are not associated with a project. To send a file to clangd, we need info containing it's location and compile commands.
It's used to avoid making any changes to user workspaces and  projects.

A file (not belonging to a project but needing to be parsed) is added to this "~ProxyProject~" and then sent through the code that prepares the info that clangd needs.

For Example, To solve the problem described by https://forums.codeblocks.org/index.php/topic,24357.msg169687.html#msg169687
"TypeA.h" and "TypeB.h" must be scanned by clangd in order to ask for its symbols to use in a GoToDecl/Impl request (or any other request to clangd).
Since the files don't belong to a project, they're just added to a hidden project and sent off to clangd via the usual process.

CB requires a filename in order to create a project.
We can't even issue a "pointer = new cbProject()" without a filename.

So the clangd_client code puts an empty project in the users' appdata/codeblocks folder and loads it, clones it, closes it, then hides the clone.
Loading and closing it via ProjectManager is necessary to keep from screwing up the order of plugin notifications.

This one-and-only hidden ~ProxyProject~ is created at OnAppStartupDone() and removed at CB clangd_client shutdown. It's the equivalent of the old CodeCompletion hidden temp parser.

Thanks for testing !
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on June 30, 2022, 11:24:03 pm
I'm using the latest nightly in a Windows 7 pro 64 bit OS and for the first time I tested your implementation of the code completion using Clangd. Overall I like it and it's working but I have the following comments.

1) Using a medium sized projects (75 .cpp files for 20000 lines of code) the time needed for a complete parsing is 5 minutes (4 seconds for each file). I was expecting that at the first time the full parsing is needed. Then I closed the project and reloaded it (without closing CB). Then a full re-parsing is done by CB  for other 5 minutes. Because I didn't modify any source file I was expecting that no re-parsing is required. Waiting 5 minutes, before having a "ready" code completion, each time I open the project seems too much considering that no modifications was applied. Is there a way to avoid a full re-parsing each time I open a project? May be no but I'm wondering if some optimization is possible just re-paring modified files.

2) I typed some code in a file to have a test of the parser making some bad indentation and syntax error like typing "elset" instead of typing "else". During typing the LSP messages window is reporting various issues and a red rectangle appeared at the involved line. Then I corrected the errors but nothing happened. The red rectangle is still there! Saving the file the red rectangle disappeared. It seems that saving the file  is required to refresh the parser errors/warnings despite I selected the "Update parser when typing".  Is this behavior expected?  Have I to save the file to refresh the parser status anyway?

3) During typing it's easy to get messages related to indentation like

LSP diagnostics: AteReaders.cpp|:|----Time: 23:19:23.784---- (1 diagnostic)|
C:\Development\Projects\AteSfp28BiDi\AteReaders.cpp|56|warning:Different indentation for 'if' and corresponding 'else'|

Because it's not a major issue, considering also the topic 2), a good idea could be to have an option to ignore indentation issues. Moreover I'm wondering which indentation rules are used. Different teams may have different indentation rules for their projects. So it's possible to ignore the indentation warnings as an option?

Thank you in advance for your attention.

Max
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 01, 2022, 06:57:16 pm
I'm using the latest nightly in a Windows 7 pro 64 bit OS and for the first time I tested your implementation of the code completion using Clangd. Overall I like it and it's working but I have the following comments.

@Max
Firstly, thanks for testing.

Regarding 1)
You do not have to wait for the background parsing to finish.
Active editors always get parsed first, then inactive editors, then background (non-editor) files. Newly opened editors go to the head of the queue and get parsed ahead of background files. Code completion requests also go to the head of queue.

There's no need to wait after the active editor is parsed (3 to 7 secs).
 
When I open CodeBlocks workspace (31_64), the active editor is indexed by clangd in a max of 7 seconds. All open editors have been indexed in less than 30 seconds. But I never have to wait more then 3-7 seconds to use code completion or other clangd features from within the active editor.

All those files being parsed in the background are used to fill the symbols tree. They're parsed in order of last-changed-time, then last-opened-time then all others so that the symbols tree gets filled with the most likely used files and symbols.

Regarding 2)
Currently, changes on a single line need to be saved manually. Changes on multiple lines usually are recognized and clangd reparses the file. This is how the older codecompletion worked but I'll see if I can do a little better in a furture fix.

Regarding 3)
CodeBlocks clangd_client has no control over what clangd reports as a warning. However you can hide the warning as follows:
With the warning in the LSP messages log, right click on the "LSP messages" tab and click on "Show/set ignore messages". In the resulting dialog, check the box for the messages you want to ignore.

Regarding Indentation:
I have no idea what indentation rules clang/clangd is applying to source files.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 09, 2022, 06:55:37 am
I'm building this plugin with the latest wx 3.2.0 release.

The source code I use is the latest rev: [r67] (https://sourceforge.net/p/cb-clangd-client/code/67/)

It looks like I see "Requested token Not found" MessageBox when I use the mouse right context menu-> find declaration.

I switch back to an old rev [r66] (https://sourceforge.net/p/cb-clangd-client/code/66/), which I build against wx 3.1.7, and I don't see this issue there.

Does any one notice the same issue?

Thanks.

EDIT:

I just build the revision 66 against wx 3.2.0, and it works OK.
So, my guess is some regression in this plugin's source code in revision 67.

Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on July 09, 2022, 10:48:45 am
I updated during the week and have been updating my scripts for building both wx 3.1.7 and 3.2. and have not finished all of the combinations. Once I do I will see if I get the same results for r67, unless it is resolved by then. I hope it does not take more than another 2 days to finish.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 10, 2022, 06:05:03 pm
I'm building this plugin with the latest wx 3.2.0 release.

The source code I use is the latest rev: [r67] (https://sourceforge.net/p/cb-clangd-client/code/67/)

It looks like I see "Requested token Not found" MessageBox when I use the mouse right context menu-> find declaration.

I switch back to an old rev [r66] (https://sourceforge.net/p/cb-clangd-client/code/66/), which I build against wx 3.1.7, and I don't see this issue there.

Does any one notice the same issue?

Thanks.

EDIT:

I just build the revision 66 against wx 3.2.0, and it works OK.
So, my guess is some regression in this plugin's source code in revision 67.

That message box is still in rev 66 also. So some logic changed that is causing clangd to send back an empty response in rev 67.

Can you tell me how to re-create the situation with rev 67?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 11, 2022, 07:44:47 am

That message box is still in rev 66 also. So some logic changed that is causing clangd to send back an empty response in rev 67.

Can you tell me how to re-create the situation with rev 67?

I'm using C::B for my own big project.
Let me create a minimal project for testing(reproduce this bug)
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 12, 2022, 04:30:41 am
I see one issue:

When I open the client or server log(which locates under the C:\Users\[myusername]\AppData\Local\Temp\)

I got to see something like:

Code
09:59:08.833 SystemPath: F:\code\msys2-64\mingw64\bin;F:\code\msys2-64\mingw64;..\usr\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\System32;C:\Windows;

However, I see the string "..\usr\bin" is wrong here.

Because in the C::B Menu->Settings->Compiler->Tool Chain executable->Addtional Paths, I have one string

Code
$(TARGET_COMPILER_DIR)../usr/bin

So, it looks like the TARGET_COMPILER_DIR is not replaced by the "F:\code\msys2-64\mingw64".[/code]
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 12, 2022, 05:36:35 am

That message box is still in rev 66 also. So some logic changed that is causing clangd to send back an empty response in rev 67.

Can you tell me how to re-create the situation with rev 67?

I'm using C::B for my own big project.
Let me create a minimal project for testing(reproduce this bug)

Here is my research on the "find declaration failure".

For some unknown reasons, the find declaration gives empty result, see the log below:


Code
11:30:17.039 <<< GoToDeclaration:
file:///F:/MyProject/JsonRead.cpp,line[41], char[30]

11:30:17.040 <<< Content-Length: 211



{"id":"textDocument/declaration","jsonrpc":"2.0","method":"textDocument/declaration","params":{"position":{"character":30,"line":41},"textDocument":{"uri":"file:///F:/MyProject/JsonRead.cpp"}}}

11:30:17.155 >>> readJson() len:61:
{"id":"textDocument/declaration","jsonrpc":"2.0","result":[]}


While for another place, it works OK, see the log below:

Code

11:30:30.454 <<< GoToDeclaration:
file:///F:/MyProject/ImagePanel.cpp,line[207], char[21]

11:30:30.455 <<< Content-Length: 214



{"id":"textDocument/declaration","jsonrpc":"2.0","method":"textDocument/declaration","params":{"position":{"character":21,"line":207},"textDocument":{"uri":"file:///F:/MyProject/ImagePanel.cpp"}}}

11:30:30.659 >>> readJson() len:199:
{"id":"textDocument/declaration","jsonrpc":"2.0","result":[{"range":{"end":{"character":14,"line":35},"start":{"character":6,"line":35}},"uri":"file:///F:/MyProject/ImagePanel.h"}]}


So, it looks like the problem is in clangd side.

I will do more research on this issue, and try to make a minimal sample code.

Strange that clangd does not show the errors when parsing:

Code
LSP diagnostics: JsonRead.cpp|:|----Time: 11:30:08.905---- (0 diagnostics)|
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 12, 2022, 07:23:18 am
I stripped down to a minimal code snippet: (you should save the code to UTF8 format)

Code
int abc;


int main()
{
    abc = 3;
}


#include <string>


std::string Utf8ToGbk(const std::string& strUtf8);

std::string Utf8ToGbk(const std::string& strUtf8)
{
    // 上面的函数
    // return unicodeString.ToStdString(); // 默认使用当前操作系统的编码格式,Windows通常为GB2312
    return strUtf8;
}

You can see that if you right click on the "strUtf8", and find declaration gives empty result. The same as the "abc".

But if you remove the line:

Code
// 上面的函数

Then, everything works expected.

Can you guys reproduce this bug?
Thanks.

BTW: I have some local patches to enable the the utf8 handling, but I'm not sure they are related.

Code
-------------------- clangd_client/src/LSPclient/client.cpp --------------------
index 26ae994..fa1d7ca 100644
@@ -1162,7 +1162,7 @@ bool ProcessLanguageClient::DoValidateUTF8data(std::string& strdata)
             if (not i18n) //if not internationalization show U(<codepoint>)
             {
                 // With internationalization the wxUniChar gets an assert in wxString::Format
-                wxUniChar uniChar(invChar);
+                wxUniChar uniChar((unsigned int)invChar);
                 msg += wxString::Format("position(%d), hex(%02hhX), U(%x), \'%s\'", invloc, (unsigned int)invChar, (int)uniChar.GetValue(), invStr );
             }
             else

and

Code
-------------------- clangd_client/src/LSPclient/client.cpp --------------------
index df36437..66bfad8 100644
@@ -2629,6 +2629,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
     }
 
     didChangeEvent.text = edText;
+    didChangeEvent.text = edText.ToUTF8(); //Trying to find bad utf8 problem
     std::vector<TextDocumentContentChangeEvent> tdcce{didChangeEvent};
     DocumentUri docuri = DocumentUri(fileURI.c_str());
     // **debugging**

Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 14, 2022, 06:59:34 pm
I see one issue:

When I open the client or server log(which locates under the C:\Users\[myusername]\AppData\Local\Temp\)

I got to see something like:

Code
09:59:08.833 SystemPath: F:\code\msys2-64\mingw64\bin;F:\code\msys2-64\mingw64;..\usr\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\System32;C:\Windows;

However, I see the string "..\usr\bin" is wrong here.

Because in the C::B Menu->Settings->Compiler->Tool Chain executable->Addtional Paths, I have one string

Code
$(TARGET_COMPILER_DIR)../usr/bin

So, it looks like the TARGET_COMPILER_DIR is not replaced by the "F:\code\msys2-64\mingw64".[/code]

I don't understand the point here.
That line in the log is just info produced by client.cpp line 372 and line 394. It's the system path as seen by wxGetEnv() and is just for information.
Code
            wxString envPath;
            wxGetEnv("PATH", &envPath);
            logLine = "SystemPath: " + envPath;
            writeClientLog(logLine);

The code to find the path to clangd.exe is in Locate_ClangdDir() invoked at client.cpp line 195.
Search for "// Locate folder for Clangd" (without quotes).
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 14, 2022, 07:42:43 pm
I stripped down to a minimal code snippet: (you should save the code to UTF8 format)

Code
int abc;


int main()
{
    abc = 3;
}


#include <string>


std::string Utf8ToGbk(const std::string& strUtf8);

std::string Utf8ToGbk(const std::string& strUtf8)
{
    // 上面的函数
    // return unicodeString.ToStdString(); // 默认使用当前操作系统的编码格式,Windows通常为GB2312
    return strUtf8;
}

You can see that if you right click on the "strUtf8", and find declaration gives empty result. The same as the "abc".

But if you remove the line:

Code
// 上面的函数

Then, everything works expected.

Can you guys reproduce this bug?
Thanks.
...snip...

I am unable to re-produce this error.
Find declaration of strUtf8 jumps to the strUtf8 parameter.
Here's the log entry.
Code
10:37:36.951 <<< GoToDeclaration:
file:///C:/temp/OllyDbgGoToDeclConsole/main.cpp,line[27], char[14]
10:37:36.951 <<< Content-Length: 207

{"id":"textDocument/declaration","jsonrpc":"2.0","method":"textDocument/declaration","params":{"position":{"character":14,"line":27},"textDocument":{"uri":"file:///C:/temp/OllyDbgGoToDeclConsole/main.cpp"}}}

10:37:37.041 >>> readJson() len:196:
{"id":"textDocument/declaration","jsonrpc":"2.0","result":[{"range":{"end":{"character":48,"line":23},"start":{"character":41,"line":23}},"uri":"file:///C:/temp/OllyDbgGoToDeclConsole/main.cpp"}]}


Attached: a .zip of a .wmv recording the sucessful behavior.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 15, 2022, 05:05:13 am
I stripped down to a minimal code snippet: (you should save the code to UTF8 format)

Code
int abc;


int main()
{
    abc = 3;
}


#include <string>


std::string Utf8ToGbk(const std::string& strUtf8);

std::string Utf8ToGbk(const std::string& strUtf8)
{
    // 上面的函数
    // return unicodeString.ToStdString(); // 默认使用当前操作系统的编码格式,Windows通常为GB2312
    return strUtf8;
}

You can see that if you right click on the "strUtf8", and find declaration gives empty result. The same as the "abc".

But if you remove the line:

Code
// 上面的函数

Then, everything works expected.

Can you guys reproduce this bug?
Thanks.
...snip...

I am unable to re-produce this error.
Find declaration of strUtf8 jumps to the strUtf8 parameter.
Here's the log entry.
Code
10:37:36.951 <<< GoToDeclaration:
file:///C:/temp/OllyDbgGoToDeclConsole/main.cpp,line[27], char[14]
10:37:36.951 <<< Content-Length: 207

{"id":"textDocument/declaration","jsonrpc":"2.0","method":"textDocument/declaration","params":{"position":{"character":14,"line":27},"textDocument":{"uri":"file:///C:/temp/OllyDbgGoToDeclConsole/main.cpp"}}}

10:37:37.041 >>> readJson() len:196:
{"id":"textDocument/declaration","jsonrpc":"2.0","result":[{"range":{"end":{"character":48,"line":23},"start":{"character":41,"line":23}},"uri":"file:///C:/temp/OllyDbgGoToDeclConsole/main.cpp"}]}


Attached: a .zip of a .wmv recording the sucessful behavior.

Hi, Pecan, thanks for the test and the screen cast video. I will check what's the problem here.

BTW: do you use the wx 3.2 library? Or the wx 3.1.7  for building the codeblocks and the clangd_client.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 15, 2022, 06:26:47 am
@OllyDbg

I still use wx3.1.5 and the compiler used by the nightly.
I always compile, debug and publish with the wx that's used with the nightly.

I've noticed that clangd can behave peculiarly if a request is made to it and a previous error exists. When I correct any previous error, the subsequent clangd requests tend to work.

See if fixing the main functions "return int" fixes the problem. Just a guess...



Thanks for all your testing.
 
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 15, 2022, 08:57:56 am
@OllyDbg

I still use wx3.1.5 and the compiler used by the nightly.
I always compile, debug and publish with the wx that's used with the nightly.

I've noticed that clangd can behave peculiarly if a request is made to it and a previous error exists. When I correct any previous error, the subsequent clangd requests tend to work.

See if fixing the main functions "return int" fixes the problem. Just a guess...



Thanks for all your testing.

Thanks for the reply and help.

I just added a "return 0;" statement in the main function, but the same issue.

I have rebuild the whole C::B and clangd_client plugin with the wx 3.2.0 today. But still the same issue.

I will try to rebuild the C::B and clangd_client plugin with wx 3.1.7 later today to see whether it is the wx related issue.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 15, 2022, 12:16:06 pm

I will try to rebuild the C::B and clangd_client plugin with wx 3.1.7 later today to see whether it is the wx related issue.

The issue persist with wx 3.1.7. So, it looks like this is not a wx related issue.

Can someone share a C::B + clangd_client plugin, so that I can tested in my PC? Thanks.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 15, 2022, 01:39:28 pm
I have upload a screen cast mp4 file in zip file about this issue.

See here:

go declaration got error Issue 1 asmwarrior/clangd_client_bug_2022 (https://github.com/asmwarrior/clangd_client_bug_2022/issues/1)

Because this forum does not allow a file larger than 512K, I upload to github issue, clangd_go_decl_bug.zip (https://github.com/asmwarrior/clangd_client_bug_2022/files/9120484/clangd_go_decl_bug.zip)
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 16, 2022, 02:41:54 pm
Hi, Pecan, I did some test, I tred to use different clangd from winlibs, I tried to used to use the online visual studio code.

It looks like clangd does not have this issue. so I guess the issue is inside the clangd_plugin code. clangd_plugin rev66 about one months ago works OK.

I compared rev67 and rev66, especially the log file. By comparing the logs from clangd_plugin rev66 and rev67, I noticed some difference.

It looks like the textDocument/didOpen method is different. In rev67, it just send an empty string.


Here is the log of rev66, it looks good. (Note I cut down the source file path, because it was a bit long)
Code
20:25:11.290 <<< Content-Length: 614



{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"\r\n\r\n\r\n\r\nint abc;\r\n\r\n\r\nint main()\r\n{\r\n    abc = 3;\r\n    return 0;\r\n}\r\n\r\n\r\n#include <string>\r\n\r\n\r\nstd::string Utf8ToGbk(const std::string& strUtf8);\r\n\r\nstd::string Utf8ToGbk(const std::string& strUtf8)\r\n{\r\n    // 上面的函数\r\n    // return unicodeString.ToStdString(); 默认使用当前操作系统的编码格式,Windows通常为GB2312\r\n    return strUtf8;\r\n}\r\n\r\n\r\n\r\n","uri":"file:///D:/project/test5-readtext/a.cpp","version":0}}}



In rev67, the log looks wrong, because an empty string is passed.

Code
20:27:05.074 <<< Content-Length: 185



{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"","uri":"file:///D:/test5-readtext/a.cpp","version":0}}}


You can see, the "text":"". So, it just send the empty string to the clangd?

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 16, 2022, 02:53:01 pm
OK, it looks like the change in rev67 is here:

Code
@@ -1664,9 +1683,13 @@ bool ProcessLanguageClient::LSP_DidOpen(cbEditor* pcbEd)
     // save current length of the file
     m_FileLinesHistory[pcbEd] = pCntl->GetLineCount();
 
-    wxString strText = pCntl->GetText();
-    //-const char* pText = strText.mb_str();        //works //(ph 2022/01/17)
-    const char* pText = strText.ToUTF8();           //ollydbg  220115 did not solve illegal utf8char
+    #if wxCHECK_VERSION(3,1,5) //3.1.5 or higher
+    wxString strText = pCntl->GetText().utf8_string(); //solves most illegal utf8chars
+    #else
+    //const char* pText = strText.mb_str();         //works //(ph 2022/01/17)
+    wxString strText = pCntl->GetText().ToUTF8();  //ollydbg  220115 did not solve illegal utf8chars
+    #endif
+    const char* pText = strText.c_str();

This code change looks wrong (cause my issue) here.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 16, 2022, 03:13:32 pm
OK, it looks like the change in rev67 is here:

Code
@@ -1664,9 +1683,13 @@ bool ProcessLanguageClient::LSP_DidOpen(cbEditor* pcbEd)
     // save current length of the file
     m_FileLinesHistory[pcbEd] = pCntl->GetLineCount();
 
-    wxString strText = pCntl->GetText();
-    //-const char* pText = strText.mb_str();        //works //(ph 2022/01/17)
-    const char* pText = strText.ToUTF8();           //ollydbg  220115 did not solve illegal utf8char
+    #if wxCHECK_VERSION(3,1,5) //3.1.5 or higher
+    wxString strText = pCntl->GetText().utf8_string(); //solves most illegal utf8chars
+    #else
+    //const char* pText = strText.mb_str();         //works //(ph 2022/01/17)
+    wxString strText = pCntl->GetText().ToUTF8();  //ollydbg  220115 did not solve illegal utf8chars
+    #endif
+    const char* pText = strText.c_str();

This code change looks wrong (cause my issue) here.

I just revert this changes in rev67, and rebuild the clangd_client plugin, and my issue is gone!  :)
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 16, 2022, 04:41:59 pm
There are some other issues in rev67, which I never see in rev66.

When editing the comments, I got this message box:

Code
[Window Title]
codeblocks.exe

[Content]
LSP: trying to get AST for non-added document

[OK]

I really don't know why this will happen.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 16, 2022, 06:08:55 pm
There are some other issues in rev67, which I never see in rev66.

When editing the comments, I got this message box:

Code
[Window Title]
codeblocks.exe

[Content]
LSP: trying to get AST for non-added document

[OK]

I really don't know why this will happen.

Acknowledge. I get this when adding a new file to the project. Specifically (for me) MainMenu/File/new/file...

It's caused because CB invokes OnEditorActivated() before setting the editor's ProjectFile member (pointing to the parent project) and ~proxyProject~ grabs it thinking it's a non-project file.

It'll be fixed in the next commit.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 16, 2022, 06:16:54 pm
OK, it looks like the change in rev67 is here:

Code
@@ -1664,9 +1683,13 @@ bool ProcessLanguageClient::LSP_DidOpen(cbEditor* pcbEd)
     // save current length of the file
     m_FileLinesHistory[pcbEd] = pCntl->GetLineCount();
 
-    wxString strText = pCntl->GetText();
-    //-const char* pText = strText.mb_str();        //works //(ph 2022/01/17)
-    const char* pText = strText.ToUTF8();           //ollydbg  220115 did not solve illegal utf8char
+    #if wxCHECK_VERSION(3,1,5) //3.1.5 or higher
+    wxString strText = pCntl->GetText().utf8_string(); //solves most illegal utf8chars
+    #else
+    //const char* pText = strText.mb_str();         //works //(ph 2022/01/17)
+    wxString strText = pCntl->GetText().ToUTF8();  //ollydbg  220115 did not solve illegal utf8chars
+    #endif
+    const char* pText = strText.c_str();

This code change looks wrong (cause my issue) here.

I just revert this changes in rev67, and rebuild the clangd_client plugin, and my issue is gone!  :)

Thanks, I'll revert that change for the next commit.

Question: Do you NOT use utf8 in CB editors?
The line containing " wxString strText = pCntl->GetText().utf8_string();" was advertised as solving non-utf8 chars in a buffer. And does so for me.

What editor encoding do you use?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 17, 2022, 01:31:17 am


Question: Do you NOT use utf8 in CB editors?
The line containing " wxString strText = pCntl->GetText().utf8_string();" was advertised as solving non-utf8 chars in a buffer. And does so for me.

What editor encoding do you use?

Yes, I use UTF8 in the C::B editors. My source code is also in UTF8 format.

My question: The function wxString::utf8_string() returned a std::string type, but why you still use a wxString to hold the returned value? Maybe there is a conversion from std::string to wxString?

My OS: Windows7 64bit, but my OS' local language setting is Simplified Chinese. My guess is that some conversion is wrong here, maybe, a std::string to wxString is using some local language setting, and its not necessary. 
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 17, 2022, 01:35:19 am
There are some other issues in rev67, which I never see in rev66.

When editing the comments, I got this message box:

Code
[Window Title]
codeblocks.exe

[Content]
LSP: trying to get AST for non-added document

[OK]

I really don't know why this will happen.

Acknowledge. I get this when adding a new file to the project. Specifically (for me) MainMenu/File/new/file...

It's caused because CB invokes OnEditorActivated() before setting the editor's ProjectFile member (pointing to the parent project) and ~proxyProject~ grabs it thinking it's a non-project file.

It'll be fixed in the next commit.

OK, thanks for the explanation.

Sometimes, when a new editor get opened. (mostly happens when I use find declaration to open a new editor), there is a message shown in the right bottom corner of the C::B's main frame immediately after the editor opened, and it said this file is not parsed yet. I also believe this is a wrong event sequence handling issue.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 17, 2022, 09:40:34 am
Code
[Window Title]
codeblocks.exe

[Content]

LSP_DidChange error: [json.exception.type_error.316] invalid UTF-8 byte at index 4: 0xB4
file:///D:/project/abc.cpp

[OK]

I also got some message like the above in the rev67.

I checked the code change and it looks like:

Code
@@ -2585,7 +2609,12 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
         ///- hasChangedLineCount = true; //(ph 2021/07/26) //(ph 2021/10/11) clangd v13 looks ok
     if ( (hasChangedLineCount) or (lineChangedNbr >= oldLineCount-1) )
         // send the whole editor text to the server.
-        edText = pCtrl->GetText();
+        // Assure text is UTF8 before handing to DidChange()
+        #if wxCHECK_VERSION(3,1,5) //3.1.5 or higher
+        edText = pCtrl->GetText().utf8_string();    //(ph 2022/06/22)
+        #else
+        edText = pCtrl->GetText().ToUTF8();
+        #endif
     else
     {
         // send only the one line that changed. //(send previous, current, and next line maybe??)
@@ -2599,9 +2628,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
         didChangeEvent.range = range;
     }
 
-    // Assure text is UTF8 before handing to DidChange()
     didChangeEvent.text = edText;
-    // didChangeEvent.text = edText.ToUTF8(); Trying to find bad utf8 problem
     std::vector<TextDocumentContentChangeEvent> tdcce{didChangeEvent};
     DocumentUri docuri = DocumentUri(fileURI.c_str());
     // **debugging**


This may cause the issue.

EDIT: code in rev67.

Code
    wxString edText;
    // If line count has changed, send full text, else send changed line.
    // Also, special handling for last line of text
        ///- hasChangedLineCount = true; //(ph 2021/07/26) //(ph 2021/10/11) clangd v13 looks ok
    if ( (hasChangedLineCount) or (lineChangedNbr >= oldLineCount-1) )
        // send the whole editor text to the server.
        // Assure text is UTF8 before handing to DidChange()
        #if wxCHECK_VERSION(3,1,5) //3.1.5 or higher
        edText = pCtrl->GetText().utf8_string();    //(ph 2022/06/22)
        #else
        edText = pCtrl->GetText().ToUTF8();
        #endif
    else
    {
        // send only the one line that changed. //(send previous, current, and next line maybe??)
        edText = lineText;
        Range range;
        range.start.line = lineChangedNbr;
        range.start.character = lineBeginCol;
        range.end.line = lineEndNbr+1;
        range.end.character = 0;
        //didChangeEvent.rangeLength = lineText.Length(); dont use. it's been deprecated
        didChangeEvent.range = range;
    }

    didChangeEvent.text = edText;

I think the variable "edText" should have the std::string type, not the wxString.

Also, if possible this line

edText = lineText;

Should also be adjusted because lineText is wxString, while edText is changed to std::string.

Maybe, you should also put the wxString to utf8 format at the last stage as:

didChangeEvent.text = edText.ToUTF8();

Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 18, 2022, 07:29:09 pm
...snipped...
I think the variable "edText" should have the std::string type, not the wxString.

Also, if possible this line

edText = lineText;

Should also be adjusted because lineText is wxString, while edText is changed to std::string.

Maybe, you should also put the wxString to utf8 format at the last stage as:

didChangeEvent.text = edText.ToUTF8();

I will revert DidChange() and DidOpen() to rev66 since that code worked ok.
Then (after the revert commit) I'll make an experimental branch with your suggestions and have you test the changes.

Thanks for the suggestions and thanks for testing.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 18, 2022, 07:44:37 pm
Sometimes, when a new editor get opened. (mostly happens when I use find declaration to open a new editor), there is a message shown in the right bottom corner of the C::B's main frame immediately after the editor opened, and it said this file is not parsed yet. I also believe this is a wrong event sequence handling issue.

Yes, I know.
There needs to be some wait set between the time a closed file is opened and sent to clangd and when the code for GoTo Decl/Impl is executed. This probably is also true of FindReferences etc.

I'll enter this comment into the clangd_client repo ticket system.
(Ticket #54 in Clangd_Client repo)
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on July 19, 2022, 12:05:14 am
Pecan, You can blow away my old experimental branch so that there is only one experimental branch.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 22, 2022, 07:12:37 am
Hi, Pecan, I think this patch is still needed to handle the wxString to char* convertion, the char* should be UTF-8 format.

This is against rev69.


Code
-------------------- clangd_client/src/LSPclient/client.cpp --------------------
index c1d5d59..c6f8c22 100644
@@ -2649,7 +2649,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
         didChangeEvent.range = range;
     }
 
-    didChangeEvent.text = edText;
+    didChangeEvent.text = edText.ToStdString(wxConvUTF8);
     std::vector<TextDocumentContentChangeEvent> tdcce{didChangeEvent};
     DocumentUri docuri = DocumentUri(fileURI.c_str());
     // **debugging**
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 22, 2022, 05:45:03 pm
Hi, Pecan, I think this patch is still needed to handle the wxString to char* convertion, the char* should be UTF-8 format.

This is against rev69.


Code
-------------------- clangd_client/src/LSPclient/client.cpp --------------------
index c1d5d59..c6f8c22 100644
@@ -2649,7 +2649,7 @@ void ProcessLanguageClient::LSP_DidChange(cbEditor* pEd)
         didChangeEvent.range = range;
     }
 
-    didChangeEvent.text = edText;
+    didChangeEvent.text = edText.ToStdString(wxConvUTF8);
     std::vector<TextDocumentContentChangeEvent> tdcce{didChangeEvent};
     DocumentUri docuri = DocumentUri(fileURI.c_str());
     // **debugging**

Applied locally. Will test it for awhile.
If ok, it'll be in rev 70.

Thanks
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 24, 2022, 06:15:38 am
I see one bug, I'm not sure it is a clangd bug or our client plugin bug.

When I do code refactoring, I mean I want to rename a variable aaa to bbb.

If there is a line:

Quote
wxLogMessage("aaa", aaa);

Then I will get this:

Quote
wxLogMessage("bbb", aaa);

maybe, clangd does not give us the column information of a variable? It just tell use the line information?
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 24, 2022, 06:58:20 am
I see one bug, I'm not sure it is a clangd bug or our client plugin bug.

When I do code refactoring, I mean I want to rename a variable aaa to bbb.

If there is a line:

Quote
wxLogMessage("aaa", aaa);

Then I will get this:

Quote
wxLogMessage("bbb", aaa);

maybe, clangd does not give us the column information of a variable? It just tell use the line information?

Do you mean that the unquoted aaa should have been changed to the unquoted bbb (the second parameter) ?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 24, 2022, 07:23:36 am
I see one bug, I'm not sure it is a clangd bug or our client plugin bug.

When I do code refactoring, I mean I want to rename a variable aaa to bbb.

If there is a line:

Quote
wxLogMessage("aaa", aaa);

Then I will get this:

Quote
wxLogMessage("bbb", aaa);

maybe, clangd does not give us the column information of a variable? It just tell use the line information?

Do you mean that the unquoted aaa should have been changed to the unquoted bbb (the second parameter) ?

Yes.
Title: Re: Code completion using LSP and clangd
Post by: BlueHazzard on July 29, 2022, 10:04:45 pm
Hi, not quite sure what is happening, and i did not investigate, but i got a crash and this backtrace, just wanted to note it here:
Code
AddrPC           Params
00007FFC87E084EB 00000158724B49E0 0000002690BFE4F0 00000000FFFF86AD  clangd_client.dll!Parser::LSP_ParseSemanticTokens
00007FFC87E13403 00000158724B49E0 00000158771FF080 0000000000000000  clangd_client.dll!Parser::OnLSP_RequestedSemanticTokensResponse
00007FFC87DB64F1 000001586D6EB3F0 00000158771FF080 0000002690BFEED0  clangd_client.dll!ClgdCompletion::OnLSP_Event
00007FFC2F35398C 000001586CB04130 000001586D6EB3F0 00007FFC2A605B5E  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::HandleEvent
00007FFC2F353A0D 000001586CB04130 000001586D6EB3F0 000001586D50E880  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::CallEventHandler
00007FFC2F42DBF4 000001586D50E8E0 000001586D6EB3F0 00000158771FF080  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEventIfMatchesId
00007FFC2F42E90A 000001586D6EB3F0 00000158771FF080 00000158771FF080  wxmsw315ud_gcc_custom.dll!wxEvtHandler::SearchDynamicEventTable
00007FFC2F42E07A 000001586D6EB3F0 00000158771FF080 0000002690BFF0C0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::TryHereOnly
00007FFC2FC31040 000001586D6EB3F0 00000158771FF080 0000015870E46080  wxmsw315ud_gcc_custom.dll!wxEvtHandler::TryBeforeAndHere
00007FFC2F42DE83 000001586D6EB3F0 00000158771FF080 000001586D6EB3F0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEvent
00007FFC2F42DF7F 000001587244F920 00000158771FF080 0000002690BFF120  wxmsw315ud_gcc_custom.dll!wxEvtHandler::DoTryChain
00007FFC2F42DF10 000001587244F920 00000158771FF080 000001586CAB5FB0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEventLocally
00007FFC2F42DE95 000001587244F920 00000158771FF080 00000158773507D0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEvent
00007FFC2F42DA98 000001587244F920 0000000000000000 000001586CB042F8  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessPendingEvents
00007FFC2F3535ED 000001586CB04130 00007FFC2F4FFA99 000001586CB04130  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::ProcessPendingEvents
00007FFC2F37666E 000001587479F1C0 0000000000000040 0000002690BFF380  wxmsw315ud_gcc_custom.dll!wxEventLoopManual::ProcessEvents
00007FFC2F37677D 000001587479F1C0 000001587479F1D4 000001587479F100  wxmsw315ud_gcc_custom.dll!wxEventLoopManual::DoRun
00007FFC2F376234 000001587479F1C0 000001586CB042F0 000001587479F1C0  wxmsw315ud_gcc_custom.dll!wxEventLoopBase::Run
00007FFC2F352E88 000001586CB04130 0000000000000055 000001586CAB5FB0  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::MainLoop
00007FFC2F352BB2 000001586CB04130 00007FFCDC9A03E0 00007FFCDC980000  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::OnRun
00007FFC2F59BA17 000001586CB04130 000001586CB00000 0000000000000000  wxmsw315ud_gcc_custom.dll!wxAppBase::OnRun
00007FF742BF5C8A 000001586CB04130 00007FFC3028D7B0 000001586B0CC050  codeblocks.exe!CodeBlocksApp::OnRun
00007FFC2F3A0FA2 00007FFC3028D7B0 000001586B0CC050 000001586CAAF898  wxmsw315ud_gcc_custom.dll!wxEntryReal
00007FFC2F436B60 00007FFC3028D7B0 000001586B0CC050 0000000000000000  wxmsw315ud_gcc_custom.dll!wxEntry
00007FFC2F436C45 00007FF742BF0000 0000000000000000 000001586B0C3987  wxmsw315ud_gcc_custom.dll!wxEntry
00007FF742BF2544 00007FF742BF0000 0000000000000000 000001586B0C3987  codeblocks.exe!WinMain
00007FF742BF13B1 0000000000000000 0000000000000000 0000000000000000  codeblocks.exe!__tmainCRTStartup
00007FF742BF14C6 0000000000000000 0000000000000000 0000000000000000  codeblocks.exe!WinMainCRTStartup
00007FFCDC997034 0000000000000000 0000000000000000 0000000000000000  KERNEL32.DLL!BaseThreadInitThunk
00007FFCDD9E2651 0000000000000000 0000000000000000 0000000000000000  ntdll.dll!RtlUserThreadStart

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 30, 2022, 05:02:08 am
@BlueHazzard, maybe you can check the log files in your system Temp folder to see what content were sent from the clangd.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 30, 2022, 09:51:00 pm
Hi, not quite sure what is happening, and i did not investigate, but i got a crash and this backtrace, just wanted to note it here:
Code
AddrPC           Params
00007FFC87E084EB 00000158724B49E0 0000002690BFE4F0 00000000FFFF86AD  clangd_client.dll!Parser::LSP_ParseSemanticTokens
00007FFC87E13403 00000158724B49E0 00000158771FF080 0000000000000000  clangd_client.dll!Parser::OnLSP_RequestedSemanticTokensResponse
00007FFC87DB64F1 000001586D6EB3F0 00000158771FF080 0000002690BFEED0  clangd_client.dll!ClgdCompletion::OnLSP_Event
00007FFC2F35398C 000001586CB04130 000001586D6EB3F0 00007FFC2A605B5E  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::HandleEvent
00007FFC2F353A0D 000001586CB04130 000001586D6EB3F0 000001586D50E880  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::CallEventHandler
00007FFC2F42DBF4 000001586D50E8E0 000001586D6EB3F0 00000158771FF080  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEventIfMatchesId
00007FFC2F42E90A 000001586D6EB3F0 00000158771FF080 00000158771FF080  wxmsw315ud_gcc_custom.dll!wxEvtHandler::SearchDynamicEventTable
00007FFC2F42E07A 000001586D6EB3F0 00000158771FF080 0000002690BFF0C0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::TryHereOnly
00007FFC2FC31040 000001586D6EB3F0 00000158771FF080 0000015870E46080  wxmsw315ud_gcc_custom.dll!wxEvtHandler::TryBeforeAndHere
00007FFC2F42DE83 000001586D6EB3F0 00000158771FF080 000001586D6EB3F0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEvent
00007FFC2F42DF7F 000001587244F920 00000158771FF080 0000002690BFF120  wxmsw315ud_gcc_custom.dll!wxEvtHandler::DoTryChain
00007FFC2F42DF10 000001587244F920 00000158771FF080 000001586CAB5FB0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEventLocally
00007FFC2F42DE95 000001587244F920 00000158771FF080 00000158773507D0  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessEvent
00007FFC2F42DA98 000001587244F920 0000000000000000 000001586CB042F8  wxmsw315ud_gcc_custom.dll!wxEvtHandler::ProcessPendingEvents
00007FFC2F3535ED 000001586CB04130 00007FFC2F4FFA99 000001586CB04130  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::ProcessPendingEvents
00007FFC2F37666E 000001587479F1C0 0000000000000040 0000002690BFF380  wxmsw315ud_gcc_custom.dll!wxEventLoopManual::ProcessEvents
00007FFC2F37677D 000001587479F1C0 000001587479F1D4 000001587479F100  wxmsw315ud_gcc_custom.dll!wxEventLoopManual::DoRun
00007FFC2F376234 000001587479F1C0 000001586CB042F0 000001587479F1C0  wxmsw315ud_gcc_custom.dll!wxEventLoopBase::Run
00007FFC2F352E88 000001586CB04130 0000000000000055 000001586CAB5FB0  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::MainLoop
00007FFC2F352BB2 000001586CB04130 00007FFCDC9A03E0 00007FFCDC980000  wxmsw315ud_gcc_custom.dll!wxAppConsoleBase::OnRun
00007FFC2F59BA17 000001586CB04130 000001586CB00000 0000000000000000  wxmsw315ud_gcc_custom.dll!wxAppBase::OnRun
00007FF742BF5C8A 000001586CB04130 00007FFC3028D7B0 000001586B0CC050  codeblocks.exe!CodeBlocksApp::OnRun
00007FFC2F3A0FA2 00007FFC3028D7B0 000001586B0CC050 000001586CAAF898  wxmsw315ud_gcc_custom.dll!wxEntryReal
00007FFC2F436B60 00007FFC3028D7B0 000001586B0CC050 0000000000000000  wxmsw315ud_gcc_custom.dll!wxEntry
00007FFC2F436C45 00007FF742BF0000 0000000000000000 000001586B0C3987  wxmsw315ud_gcc_custom.dll!wxEntry
00007FF742BF2544 00007FF742BF0000 0000000000000000 000001586B0C3987  codeblocks.exe!WinMain
00007FF742BF13B1 0000000000000000 0000000000000000 0000000000000000  codeblocks.exe!__tmainCRTStartup
00007FF742BF14C6 0000000000000000 0000000000000000 0000000000000000  codeblocks.exe!WinMainCRTStartup
00007FFCDC997034 0000000000000000 0000000000000000 0000000000000000  KERNEL32.DLL!BaseThreadInitThunk
00007FFCDD9E2651 0000000000000000 0000000000000000 0000000000000000  ntdll.dll!RtlUserThreadStart

This looks like the crashes during CB shutdown or when closing a file while clangd sent a response to a previous request.
Likely fixed in rev 70.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 30, 2022, 09:53:38 pm
I see one bug, I'm not sure it is a clangd bug or our client plugin bug.

When I do code refactoring, I mean I want to rename a variable aaa to bbb.

If there is a line:

Quote
wxLogMessage("aaa", aaa);

Then I will get this:

Quote
wxLogMessage("bbb", aaa);

maybe, clangd does not give us the column information of a variable? It just tell use the line information?

Do you mean that the unquoted aaa should have been changed to the unquoted bbb (the second parameter) ?

Yes.
Fixed rev 70
Title: Re: Code completion using LSP and clangd
Post by: BlueHazzard on July 31, 2022, 12:03:11 am
@BlueHazzard, maybe you can check the log files in your system Temp folder to see what content were sent from the clangd.
It could be this two logs, but i am not 100% sure:
client log:
Code
21:58:21.731 Project: Addr2LineUI wx3.1.x (64 bit): codeblocksdir\src\tools\Addr2LineUI\Addr2LineUI_wx31_64.cbp

21:58:21.731 SystemPath: C:\msys64\mingw64\bin;C:\msys64\mingw64\bin\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\tools;C:\Program Files\WireGuard;C;C:\Program Files\TortoiseSVN\bin;C:\Program Files\AMD\AMDuProf\bin;C:\Users\eberh\AppData\Local\Microsoft\WindowsApps

21:58:21.733 <<< Initialize(): codeblocksdir/src/tools/Addr2LineUI

21:58:21.734 <<< Content-Length: 1202



{"id":"initialize","jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"offsetEncoding":["utf-8"],"textDocument":{"codeAction":{"codeActionLiteralSupport":true},"completion":{"completionItem":{"deprecatedSupport":true,"snippetSupport":true},"completionItemKind":{"valueSet":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},"editsNearCursor":true},"documentSymbol":{"hierarchicalDocumentSymbolSupport":true},"hover":{"contentFormat":["plaintext"]},"publishDiagnostics":{"categorySupport":true,"codeActionsInline":true,"relatedInformation":true},"semanticTokens":{"dynamicRegistration":true},"signatureHelp":{"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true}}}},"workspace":{"applyEdit":false,"symbol":{"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"workspaceEdit":{"documentChanges":false}}},"initializationOptions":{"clangdFileStatus":false,"compilationDatabasePath":null,"configSettings":{"compilationDatabaseChanges":{}},"fallbackFlags":[]},"processId":21764,"rootPath":null,"rootUri":"file:///codeblocksdir/src/tools/Addr2LineUI"}}

21:58:21.990 >>> readJson() len:1873:
{"id":"initialize","jsonrpc":"2.0","result":{"capabilities":{"astProvider":true,"callHierarchyProvider":true,"clangdInlayHintsProvider":true,"codeActionProvider":true,"compilationDatabase":{"automaticReload":true},"completionProvider":{"allCommitCharacters":[" ","\t","(",")","[","]","{","}","<",">",":",";",",","+","-","/","*","%","^","&","#","?",".","=","\"","'","|"],"resolveProvider":false,"triggerCharacters":[".","<",">",":","\"","/","*"]},"declarationProvider":true,"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{"resolveProvider":false},"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"hoverProvider":true,"implementationProvider":true,"memoryUsageProvider":true,"referencesProvider":true,"renameProvider":true,"selectionRangeProvider":true,"semanticTokensProvider":{"full":{"delta":true},"legend":{"tokenModifiers":["declaration","deprecated","deduced","readonly","static","abstract","virtual","dependentName","defaultLibrary","usedAsMutableReference","functionScope","classScope","fileScope","globalScope"],"tokenTypes":["variable","variable","parameter","function","method","function","property","variable","class","interface","enum","enumMember","type","type","unknown","namespace","typeParameter","concept","type","macro","comment"]},"range":false},"signatureHelpProvider":{"triggerCharacters":["(",")","{","}","<",">",","]},"textDocumentSync":{"change":2,"openClose":true,"save":true},"typeDefinitionProvider":true,"typeHierarchyProvider":true,"workspaceSymbolProvider":true},"offsetEncoding":"utf-8","serverInfo":{"name":"clangd","version":"clangd version 14.0.4 windows x86_64-w64-windows-gnu"}}}

server:
Code
Project: Addr2LineUI wx3.1.x (64 bit): codeblocksdir\src\tools\Addr2LineUI\Addr2LineUI_wx31_64.cbp
SystemPath: C:\msys64\mingw64\bin;C:\msys64\mingw64\bin\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\tools;C:\Program Files\WireGuard;C;C:\Program Files\TortoiseSVN\bin;C:\Program Files\AMD\AMDuProf\bin;C:\Users\eberh\AppData\Local\Microsoft\WindowsApps
I[21:58:21.827] clangd version 14.0.4

I[21:58:21.828] Features: windows

I[21:58:21.828] PID: 26712

I[21:58:21.828] Working directory: codeblocksdir/src/tools/Addr2LineUI

I[21:58:21.828] argv[0]: C:\msys64\mingw64\bin\clangd.exe

I[21:58:21.828] argv[1]: --log=verbose

I[21:58:21.828] argv[2]: --query-driver=C:\msys64\mingw64\bin\**\x*

I[21:58:21.828] argv[3]: -j=8

I[21:58:21.828] argv[4]: --limit-results=20

I[21:58:21.828] argv[5]: --resource-dir=C:\msys64\mingw64\lib\clang\14.0.4

V[21:58:21.830] User config file is C:/Users/eberh/AppData/Local/clangd/config.yaml

I[21:58:21.830] Starting LSP over stdin/stdout

V[21:58:21.830] <<< {"id":"initialize","jsonrpc":"2.0","method":"initialize","params":{"capabilities":{"offsetEncoding":["utf-8"],"textDocument":{"codeAction":{"codeActionLiteralSupport":true},"completion":{"completionItem":{"deprecatedSupport":true,"snippetSupport":true},"completionItemKind":{"valueSet":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},"editsNearCursor":true},"documentSymbol":{"hierarchicalDocumentSymbolSupport":true},"hover":{"contentFormat":["plaintext"]},"publishDiagnostics":{"categorySupport":true,"codeActionsInline":true,"relatedInformation":true},"semanticTokens":{"dynamicRegistration":true},"signatureHelp":{"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true}}}},"workspace":{"applyEdit":false,"symbol":{"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"workspaceEdit":{"documentChanges":false}}},"initializationOptions":{"clangdFileStatus":false,"compilationDatabasePath":null,"configSettings":{"compilationDatabaseChanges":{}},"fallbackFlags":[]},"processId":21764,"rootPath":null,"rootUri":"file:///codeblocksdir/src/tools/Addr2LineUI"}}



I[21:58:21.830] <-- initialize("initialize")

I[21:58:21.851] --> reply:initialize("initialize") 21 ms

V[21:58:21.851] >>> {"id":"initialize","jsonrpc":"2.0","result":{"capabilities":{"astProvider":true,"callHierarchyProvider":true,"clangdInlayHintsProvider":true,"codeActionProvider":true,"compilationDatabase":{"automaticReload":true},"completionProvider":{"allCommitCharacters":[" ","\t","(",")","[","]","{","}","<",">",":",";",",","+","-","/","*","%","^","&","#","?",".","=","\"","'","|"],"resolveProvider":false,"triggerCharacters":[".","<",">",":","\"","/","*"]},"declarationProvider":true,"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{"resolveProvider":false},"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[]},"documentRangeFormattingProvider":true,"documentSymbolProvider":true,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]},"hoverProvider":true,"implementationProvider":true,"memoryUsageProvider":true,"referencesProvider":true,"renameProvider":true,"selectionRangeProvider":true,"semanticTokensProvider":{"full":{"delta":true},"legend":{"tokenModifiers":["declaration","deprecated","deduced","readonly","static","abstract","virtual","dependentName","defaultLibrary","usedAsMutableReference","functionScope","classScope","fileScope","globalScope"],"tokenTypes":["variable","variable","parameter","function","method","function","property","variable","class","interface","enum","enumMember","type","type","unknown","namespace","typeParameter","concept","type","macro","comment"]},"range":false},"signatureHelpProvider":{"triggerCharacters":["(",")","{","}","<",">",","]},"textDocumentSync":{"change":2,"openClose":true,"save":true},"typeDefinitionProvider":true,"typeHierarchyProvider":true,"workspaceSymbolProvider":true},"offsetEncoding":"utf-8","serverInfo":{"name":"clangd","version":"clangd version 14.0.4 windows x86_64-w64-windows-gnu"}}}
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 31, 2022, 12:40:25 am
@BlueHazzard, maybe you can check the log files in your system Temp folder to see what content were sent from the clangd.

To find a particular clangd_client log, look at the file "CBclangd_LogsIndex.txt" in your temp folder.

Each line contains the processid, the date and time of the log, location of the clangd executable, and the CB project .cbp filename.

The logs are named:
\temp\CBclangd_client-<processID>.log
\temp\CBclangd_server-<processID>.log

The CBclangd_client-<processID>.log is the most interesting for debugging CB.

The CBclangd_client-<processID>.log is useful for probing/debugging clangd and is usually required to submit bug reports to the clangd team.

One log (not so interesting) exists for the CC_ProxyProject.cbp. It handles parsing non-project files.

Two logs for each opened project; The client log and the server log.

The first log line header contains the project it belong to. And the .cbp that created it. the time is on the left.

Edit: 2022/07/31
The log representing a project contains all clangd requests and responses for any file or any target. 
In error, I said that there was a log for each target. Not so.
Title: Re: Code completion using LSP and clangd
Post by: BlueHazzard on July 31, 2022, 01:04:14 am
The crash is still happening with r70,
i can reproduce it now:
1) Open codeblocks
2) Open a project with some code (i used the clang_cc project)
3) Hit recompile as fast as you can after project load, and the cc parser is not finished. compiling will start and in the middle -> crash

backtrace and log content is the same as in my previous posts
Title: Re: Code completion using LSP and clangd
Post by: Pecan on July 31, 2022, 01:24:01 am
The crash is still happening with r70,
i can reproduce it now:
1) Open codeblocks
2) Open a project with some code (i used the clang_cc project)
3) Hit recompile as fast as you can after project load, and the cc parser is not finished. compiling will start and in the middle -> crash

backtrace and log content is the same as in my previous posts

I'm having a problem getting the crash.

Would you please copy your devel31_64 version of clangd_client.dll with the debug symbols over the top of your output31_64 version and post the crash .RPT file.
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on July 31, 2022, 03:36:15 am
I was not able to re-create the crash, but I got a crash if I close C::B down while compiling which did not occur with the latest nightly.  I close by clicking on the [X] on the top right of the C::B window. This crash does not include any ClangD-cleint functions, but does have event functions  in the stack so there is a very small slim possibility it could be related and this is why I am posting it here just in case I am wrong.

Code
-------------------

Error occurred on Sunday, July 31, 2022 at 11:00:29.

CodeBlocks.exe caused an Access Violation at location 00007FFFFAAAC2DC in module codeblocks.dll Reading from location FFFFFFFFFFFFFFFF.

AddrPC           Params
00007FFFFAAAC2DC 00000120EBD30BE0 0000001A76BFED50 00000000000005E9  codeblocks.dll!wxPostEvent+0x9c  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/include/wx/event.h @ 4169]
  4167:     wxCHECK_RET( dest, "need an object to post event to" );
  4168:
> 4169:     dest->AddPendingEvent(event);
  4170: }
  4171:
00007FFFFA8BD86B 00000120F3EED750 00007FFF000049E8 0000000000000000  codeblocks.dll!PipedProcess::OnTerminate+0xd7  [D:/Andrew_Development/Work_Installers/CodeBLocks_Private_Experimental_GCC/src/sdk/pipedprocess.cpp @ 235]
   233:     event.SetInt(status);
   234:     event.SetX(m_Index);
>  235:     wxPostEvent(m_Parent, event);
   236:
   237:     if (m_pvThis)
00007FFFC2B555A6 00000000002309D0 0000000000002B10 0000000000000000  wxmsw32ud_gcc_cb.dll!wxExecuteWindowCbk+0xaf  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/msw/utilsexc.cpp @ 341]
   339:         if ( data->handler )
   340:         {
>  341:             data->handler->OnTerminate((int)data->dwProcessId,
   342:                                        (int)data->dwExitCode);
   343:         }
00007FF848E3E858 0000001A76BFF1E0 00007FFFC2B554F7 00000000002309D0  USER32.dll!UserCallWinProcCheckWow+0x2f8
00007FF848E3E3DC 0000000000000000 0000000000000000 0000000000000000  USER32.dll!DispatchClientMessage+0x9c
00007FF848E50BC3 0000000000000000 0000000000000000 00000000000083AE  USER32.dll!__fnDWORD+0x33
00007FF849CF0D74 00007FF848E3A5C3 0000000000000000 0000000000000000  ntdll.dll!KiUserCallbackDispatch+0x24
00007FF847641064 0000000000000000 0000000000000000 0000000000000000  win32u.dll!NtUserPeekMessage+0x14
00007FF848E3A5C3 0000000000000000 00000120E8FCC7E0 0000000000000000  USER32.dll!_PeekMessage+0x43
00007FF848E3A523 00000120EA4331A8 0000001A76BFF440 0000000000000038  USER32.dll!PeekMessageW+0x143
00007FFFC2B37CAF 00000120EF9E2370 00000120EF9E2370 0000001A76BFF490  wxmsw32ud_gcc_cb.dll!wxMSWEventLoopBase::Pending+0x35  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/msw/evtloopconsole.cpp @ 62]
    60: {
    61:     MSG msg;
>   62:     return ::PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) != 0;
    63: }
    64:
00007FFFC2AA6E6C 00000120EF9E2370 00000120EF9E2384 0000000000000000  wxmsw32ud_gcc_cb.dll!wxEventLoopManual::DoRun+0x52  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/common/evtloopcmn.cpp @ 276]
   274:                 // for them too
   275:                 while ( !m_shouldExit
>  276:                             && !Pending()
   277:                                 && !(wxTheApp && wxTheApp->HasPendingEvents())
   278:                                     && ProcessIdle() )
00007FFFC2AA6973 00000120EF9E2370 00000120EA47B650 00000120EF9E2370  wxmsw32ud_gcc_cb.dll!wxEventLoopBase::Run+0xf7  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/common/evtloopcmn.cpp @ 87]
    85:
    86:     // Finally really run the loop.
>   87:     return DoRun();
    88: }
    89:
00007FFFC2A82E85 00000120EA47B490 0000000000000038 0000000000000000  wxmsw32ud_gcc_cb.dll!wxAppConsoleBase::MainLoop+0x93  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/common/appbase.cpp @ 381]
   379:         wxTheApp->OnLaunched();
   380:
>  381:     return m_mainLoop ? m_mainLoop->Run() : -1;
   382: }
   383:
00007FFFC2A82BBD 00000120EA47B490 00007FF8490703E0 00007FF849050000  wxmsw32ud_gcc_cb.dll!wxAppConsoleBase::OnRun+0x25  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/common/appbase.cpp @ 303]
   301: int wxAppConsoleBase::OnRun()
   302: {
>  303:     return MainLoop();
   304: }
   305:
00007FFFC2CDDF7B 00000120EA47B490 00007FF849C75BA1 0000000000000000  wxmsw32ud_gcc_cb.dll!wxAppBase::OnRun+0x35  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/common/appcmn.cpp @ 334]
   332:     //else: it has been changed, assume the user knows what he is doing
   333:
>  334:     return wxAppConsole::OnRun();
   335: }
   336:
00007FF62FE68EBC 00000120EA47B490 00007FFFC3ADA7B0 00000120E8A1EAF0  CodeBlocks.exe!CodeBlocksApp::OnRun+0x30  [D:/Andrew_Development/Work_Installers/CodeBLocks_Private_Experimental_GCC/src/src/app.cpp @ 1070]
  1068:     try
  1069:     {
> 1070:         int retval = wxApp::OnRun();
  1071:         // wx 2.6.3 docs says that OnRun() function's return value is used as exit code
  1072:         return m_Batch ? m_BatchExitCode : retval;
00007FFFC2AD1B32 00007FFFC3ADA7B0 00000120E8A1EAF0 00000120EA4692F0  wxmsw32ud_gcc_cb.dll!wxEntryReal+0xaa  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/common/init.cpp @ 503]
   501:
   502:         // app execution
>  503:         return wxTheApp->OnRun();
   504:     }
   505:     wxCATCH_ALL( wxTheApp->OnUnhandledException(); return -1; )
00007FFFC2B69390 00007FFFC3ADA7B0 00000120E8A1EAF0 0000000000000000  wxmsw32ud_gcc_cb.dll!wxEntry+0x20  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/msw/main.cpp @ 184]
   182: int wxEntry(int& argc, wxChar **argv)
   183: {
>  184:     return wxEntryReal(argc, argv);
   185: }
   186:
00007FFFC2B6947A 00007FF62FE60000 0000000000000000 00000120E8A13C5A  wxmsw32ud_gcc_cb.dll!wxEntry+0x4e  [D:/Andrew_Development/Libraries/wxWidgets-3.2.0_win64/build/msw/../../src/msw/main.cpp @ 296]
   294:         return -1;
   295:
>  296:     return wxEntry(wxArgs.argc, wxArgs.argv);
   297: }
   298:
00007FF62FE6257D 00007FF62FE60000 0000000000000000 00000120E8A13C5A  CodeBlocks.exe!WinMain+0x3a  [D:/Andrew_Development/Work_Installers/CodeBLocks_Private_Experimental_GCC/src/src/app.cpp @ 339]
   337: } // namespace
   338:
>  339: IMPLEMENT_APP(CodeBlocksApp) // TODO: This gives a "redundant declaration" warning, though I think it's false. Dig through macro and check.
   340:
   341: BEGIN_EVENT_TABLE(CodeBlocksApp, wxApp)
00007FF62FE613AE 0000000000000000 0000000000000000 0000000000000000  CodeBlocks.exe!__tmainCRTStartup+0x22e  [C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c @ 329]
00007FF62FE614E6 0000000000000000 0000000000000000 0000000000000000  CodeBlocks.exe!mainCRTStartup+0x16  [C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c @ 206]
00007FF849067034 0000000000000000 0000000000000000 0000000000000000  KERNEL32.DLL!BaseThreadInitThunk+0x14
00007FF849CA2651 0000000000000000 0000000000000000 0000000000000000  ntdll.dll!RtlUserThreadStart+0x21

Windows 10.0.19044
DrMingw 0.9.5

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on July 31, 2022, 06:10:12 am
Hi, Pecan, if possible, can you have several more small svn commits instead of a big svn commit.

I mean I see your commit history(such as rev70), it mainly have several code changes from many places, and the expected way is for each logic code change, you should have a commit. This make the code a bit clean and easy to track.

Thanks.

BTW: The best way is using git, not svn.  :)
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on September 07, 2022, 10:26:16 pm
Hi Pecan,

I' using the ClangdClientForCBNightly_20220813_rev12864_win64.zip with the latest CB nightly and I'm observing a minor issue and a crash. They are present on both Win7 Pro  and Windows 10 Enterprise

The minor issue is related to the option "Update parser when typing )on save otherwise". I de-select this option because I'd like to update just when I'm saving the file. In reality the updating happens both when typing and (instead of otherwise) when saving. May be this is the implemented feature but in some cases the parser updating when typing is a little bit annoying, I think that updating just on saving can be very useful especially when you are typing a new code and several errors appears when I'm correcting them

The crash happens when the window, shown in the attached picture , is present in the editor. CB just freeze and the a crash happen. I'm also attaching the .RPT file related to this crash.

Hope this helps

Max
Title: Re: Code completion using LSP and clangd
Post by: AndrewCot on September 08, 2022, 12:21:10 am
MaxGaspa, The type of crash in the rpt file has been seen before and Miguel has made some changes a month or two ago that reduced the occurrence of it, but it looks like it is still occurring.  It is my understanding from what I have seen that the problem is not to do with the Clangd_Client plugin, but you just had the dialog up when it crashed.

Just before it crashed were you editing or had some other app (not C::B) in focus?


It looks like it could be the same or similar issue to the crashes as per the following ticket:
https://sourceforge.net/p/codeblocks/tickets/1168 (https://sourceforge.net/p/codeblocks/tickets/1168)
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on September 08, 2022, 03:14:46 am
Just before it crashed were you editing or had some other app (not C::B) in focus?

I was editing the related file source file in CB ....

Max
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 09, 2022, 07:15:02 am
The crash(both reported by MaxGaspa and https://sourceforge.net/p/codeblocks/tickets/1168/) looks like inside the CCManager code:

Code
AddrPC           Params
0000000070CB7861 000000002D1DC710 000000000083EDDC 000000000083EDD8  codeblocks.dll!cbThreadPool::Done
0000000070CB7497 000000000083EE30 000000002D1DC710 000000002D96A1F0  codeblocks.dll!cbThreadPool::Done
00000000709830CA 000000000B03A350 000000000083F140 000000002F8D3F80  codeblocks.dll!CCManager::OnPopupScroll

Mainly in the CCManager::OnPopupScroll function.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on September 10, 2022, 09:14:35 pm
I'm beginning to think this actually is a clangd_client problem.
Clangd_client is using a feature of ccmanager that was never used before. Namely a call to ccmanager::NotifyDocumentation().
CodeCompletion never used it. No other code has ever used it. So this is a path through ccmanager that has previously never been thoroughly test.

I'm working on it.

Edit: 2022/09/13
As it turns out, the problem existed before clangd_client was created.
But clangd_client gets the problem also.
The html documentation popup gets stuck opened (usually by slow double-clicking on a completion selection) and cannot be closed. Using the mouse to focus outside CB then attempting to focus back into CB reveils the stall.
The debugger just shows (for me) "corrupted stack".
But I suspect the stall occurs before focusing outside CB.
Title: Re: Code completion using LSP and clangd
Post by: gd_on on September 12, 2022, 04:26:59 pm
Probably because of recent changes in C::B sdk, clangd_client does not compile when using wxWidgets 3.2.1 (probably >= 3.1.6)
Error in client.cpp, line 3672 : CodeBlocksLogEvent waits for a wxBitmapBundle*, but logbmp is a wxBitmap*
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 12, 2022, 04:38:18 pm
Probably because of recent changes in C::B sdk, clangd_client does not compile when using wxWidgets 3.2.1 (probably >= 3.1.6)
Error in client.cpp, line 3672 : CodeBlocksLogEvent waits for a wxBitmapBundle*, but logbmp is a wxBitmap*

I'm building C::B rev12886, and clangd_client rev76, I don't have build issue against wx 3.2.1.

Maybe the recent change from rev12887 to rev12890 causes the build issue.

Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on September 12, 2022, 05:18:05 pm
Starting with r12887, if you are compiling with wxWidgets >= 3.1.6 the last parameter of CodeBlocksLogEvent must be a pointer to wxBitmapBundle.

The change is straightforward, I will publish a patch in this thread tomorrow (I have detected an error in the original notebook HiDPI code that must be fixed beforehand).
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on September 12, 2022, 09:54:47 pm
Bug fixed in r12891.

To fix the plugin replace (in client.cpp:3664) this
Code
        const int uiSize = Manager::Get()->GetImageSize(Manager::UIComponent::InfoPaneNotebooks);
        const int uiScaleFactor = Manager::Get()->GetUIScaleFactor(Manager::UIComponent::InfoPaneNotebooks);
        const wxString imgFile = ConfigManager::GetDataFolder()
                              + wxString::Format(_T("/resources.zip#zip:/images/%dx%d/filefind.png"),
                                                 uiSize, uiSize);
        wxBitmap* logbmp = new wxBitmap(cbLoadBitmapScaled(imgFile, wxBITMAP_TYPE_PNG, uiScaleFactor));
with this
Code
        const int uiSize = Manager::Get()->GetImageSize(Manager::UIComponent::InfoPaneNotebooks);
        wxString prefix(ConfigManager::GetDataFolder()+"/resources.zip#zip:/images/");
#if wxCHECK_VERSION(3, 1, 6)
        const double uiScaleFactor = Manager::Get()->GetUIScaleFactor(Manager::UIComponent::InfoPaneNotebooks);
        wxBitmapBundle* logbmp = new wxBitmapBundle(cbLoadBitmapBundle(prefix, "filefind.png", wxRound(uiSize/uiScaleFactor), wxBITMAP_TYPE_PNG));
#else
        prefix << wxString::Format("%dx%d/", uiSize, uiSize);
        wxBitmap* logbmp = new wxBitmap(cbLoadBitmap(prefix+"filefind.png", wxBITMAP_TYPE_PNG));
#endif
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 13, 2022, 03:32:51 am
Hi, Miguel Gimenez, Thanks for the fix.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on September 13, 2022, 09:30:43 pm
@ MaxGaspa

Until I can find the cause of the crash, you can disable Settings/Editor/GeneralSetting/Documentation popup.

This should eliminate the stall/crash. If It does not, let me know.

Thanks
Title: Re: Code completion using LSP and clangd
Post by: Pecan on September 15, 2022, 11:06:06 pm
@ MaxGaspa
Until I can find the cause of the crash, you can disable Settings/Editor/GeneralSetting/Documentation popup.
This should eliminate the stall/crash. If It does not, let me know.
Thanks

RFC: patch for ticket 1168.
This is a Request For Comment for the attached patch.
I have posted a patch on the second page of ticket #1168:
Direct link to Patch (https://sourceforge.net/p/codeblocks/tickets/_discuss/thread/92a1b2249a/e111/attachment/ccManagerMouseTrap220916-1.patch)

The attached patch (ccManagerMouseTrap220915-1.patch) resolves the following described conditions for both CodeCompletion and Clangd_client. The patch has been tested on both MSW and Linux.

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.

What is actually happening? (tldr version)
CB is getting stuck in function OnPopScroll statement:
Code
else if (m_pAutocompPopup && m_pAutocompPopup->GetScreenRect().Contains(pos))
in the GetScreenRect() function because the AutocompPopup window has been hidden and the HtmlDocumentationPopup may or may not be hidden, but a wxEVT_MOUSEWHEEL connection is owned by the html popup.

It seems that wxWidgets does not like this condition.
The debugger cannot even step out of this condition.

The problem usually arises from a slower double-mouse-click on an AutocompPopup item such that the double click gets interpreted as two single-clicks.
The AutocompPopup will get closed leaving the HtmlDocumentationPopup out to dry.
Now the conditions on which ccManager depended to remove the event connection will never be met.
We than have a happy deadly embrace.

Other sequences of action also cause the deadly embrace including (occasionally) un-focusing and re-focusing CB while both popups are showing.

I didn't trace through all the conditions causing the deadly embrace since the fix to avoid connecting wxEVT_MOUSEWHEEL to HtmlPopup when AutocompPopup was hidden fixed most of the other conditions also. (ie. the first fix eliminated the possibility of the others).
I did, however, trace through all listed conditions once the fix was applied locally.

I would like to apply the patch before the next nightly.
Comments please....
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 16, 2022, 05:29:45 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!
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 16, 2022, 07:50:24 am
About the ccManagerMouseTrap220915-1.patch file.

I'm not sure, but this variable

Code
std::map<cbEditor*,bool> m_EdAutoCompMouseTraps;

The bool value is always "true"? Since I see the only code here is:
Code
m_EdAutoCompMouseTraps[ed] = true;

Also, is the code Windows related? If yes, I think the "#ifdef __WXMSW__" should also be placed in the header file around this member variable declaration.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on September 16, 2022, 07:26:36 pm
About the ccManagerMouseTrap220915-1.patch file.

I'm not sure, but this variable

Code
std::map<cbEditor*,bool> m_EdAutoCompMouseTraps;

The bool value is always "true"? Since I see the only code here is:
Code
m_EdAutoCompMouseTraps[ed] = true;

Also, is the code Windows related? If yes, I think the "#ifdef __WXMSW__" should also be placed in the header file around this member variable declaration.


The declaration and all references to m_EdAutoCompMouseTraps are already guarded by "#ifdef __WXMSW__"
Code
#ifdef __WXMSW__
        /** a handle to the autocomplete list window created by (wx)scintilla, needed under Windows
         * to determine its dimensions (so the scroll event can be sent to it, if relevant)
         */
        wxListView* m_pAutocompPopup;

        /**
         * List of editors holding an event connect to popup mouse scroll event
         * for AutoCompPopup and html Documentation popup
         */
        std::map<cbEditor*,bool> m_EdAutoCompMouseTraps;
#endif // __WXMSW__
The statement:
Code
m_EdAutoCompMouseTraps[ed] = true;
is only used to enter the cbEditor* into the map assuring only one entry for this editor exists. Is there a better method for inserting a entry into a map?

It is removed by statement:
Code
m_EdAutoCompMouseTraps.erase(m_pLastEditor);

I will make a specific comment explaining that.
Thanks for reviewing.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 17, 2022, 02:40:14 pm
I'm tweaking wx sample workspace, see here: codeblocks cbp projects for wx samples (https://forums.codeblocks.org/index.php/topic,25105.0.html)

While, after switch from one cbp to other cbp for many times, I got many clangd.exe process running, see the image shot below, is it correct?

Thanks.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 17, 2022, 02:45:36 pm
Is there a better method for inserting a entry into a map?

I'm not fully understand the code logic, but do you really need a map? When a key is added, it's  value is always "true".

I mean a std::set<cbEditor*> is better than std::map<cbEditor*,bool> ?
Title: Re: Code completion using LSP and clangd
Post by: Pecan on September 17, 2022, 05:27:13 pm
I'm not fully understand the code logic, but do you really need a map? When a key is added, it's  value is always "true".

I mean a std::set<cbEditor*> is better than std::map<cbEditor*,bool> ?

Thanks, I learned a long time ago that other eyes reviewing code can make it better.
Direct link to newer patch (https://sourceforge.net/p/codeblocks/tickets/_discuss/thread/92a1b2249a/e111/attachment/ccManagerMouseTrap220917-1.patch)
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on September 17, 2022, 08:28:22 pm
Patch for ticket #1168 applied in r12899, thank you.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 22, 2022, 06:33:13 am
The msys2 project now has clangd 15.0 for mingw64 targets.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 25, 2022, 04:21:30 am
I have a question:

LSP_ParseSemanticTokens(), what does this function used for?

I see this code:

Code
// ----------------------------------------------------------------------------
void Parser::OnLSP_RequestedSemanticTokensResponse(wxCommandEvent& event)  //(ph 2021/03/12)
// ----------------------------------------------------------------------------
{
    if (GetIsShuttingDown()) return;

    // This is a callback after requesting textDocument/Symbol (request done at end of OnLSP_RequestedSymbolsResponse() )
    // Currently, we allow SemanticTokens for the BuiltinActiveEditor only,

    // ----------------------------------------------------------------------------
    ///  GetClientData() contains ptr to json object
    ///  DONT free it! The return to OnLSP_Event() will free it as a unique_ptr
    // ----------------------------------------------------------------------------
    json* pJson = (json*)event.GetClientData();
    wxString idStr = event.GetString();
    wxString URI = idStr.AfterFirst(STX);
    if (URI.Contains(STX))
        URI = URI.BeforeFirst(STX); //filename

    wxString uriFilename = fileUtils.FilePathFromURI(URI);      //(ph 2021/12/21)
    cbEditor*  pEditor =  nullptr;
    cbProject* pProject = nullptr;
    EditorManager* pEdMgr = Manager::Get()->GetEditorManager();
    EditorBase* pEdBase = pEdMgr->IsOpen(uriFilename);
    if (pEdBase)
    {
        pEditor = pEdMgr->GetBuiltinActiveEditor();
        if (not pEditor or (pEditor->GetFilename() != uriFilename))
            return;
        ProjectFile* pProjectFile = pEditor->GetProjectFile();
        if (pProjectFile) pProject = pProjectFile->GetParentProject();
        if ( (not pProjectFile) or (not pProject) ) return;
        ParserBase* pParser = GetParseManager()->GetParserByProject(pProject);
        if (not pParser)
            return;
    }
    else return;

    if (not pProject) pProject = Manager::Get()->GetProjectManager()->GetActiveProject();
    ProcessLanguageClient* pClient = GetLSPClient();

    // Queue the the json data to OnLSP_ParseDocumentSymbols() event, passing it the json pointer
    // The json data will be placed in a queue to be processed during OnIdle() events. //(ph 2021/09/11)
    wxCommandEvent symEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("textDocument/semanticTokens"));
    symEvent.SetString(uriFilename);
    symEvent.SetClientData(pJson);
    LSP_ParseSemanticTokens(symEvent); //Call directly

The last line:
LSP_ParseSemanticTokens(symEvent); //Call directly

This use the our old-CC's parsing code, for example


Code
// ----------------------------------------------------------------------------
Token* LSP_SymbolsParser::DoHandleClass(EClassType ct, int lineNumber, int lastLineNumber, int endCol)            //(ph 2021/05/15)
// ----------------------------------------------------------------------------
{
    // need to force the tokenizer _not_ skip anything
    // as we 're manually parsing class decls
    // don't forget to reset that if you add any early exit condition!
    TokenizerState oldState = m_Tokenizer.GetState();
    m_Tokenizer.SetState(tsNormal);
Title: Re: Code completion using LSP and clangd
Post by: Pecan 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.
 
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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.  :)
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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.  :(
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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.
Title: Re: Code completion using LSP and clangd
Post by: Pecan 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.
Title: Re: Code completion using LSP and clangd
Post by: Pecan 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 ?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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.
Title: Re: Code completion using LSP and clangd
Post by: Pecan 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.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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);
    }
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa 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?


Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa 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)
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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.





Title: Re: Code completion using LSP and clangd
Post by: Pecan 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.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg 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;
}

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 30, 2022, 08:25:07 am
I'm not quite understand the code, when I read the source code of clangd_client, I see this:

Code
        size_t resultCount = pJson->at("result").size();
        if (not resultCount) return;

        // Nothing for ShowCalltip is ever in the signature array //(ph 2021/11/1)
        // Show Tootip vs ShowCalltip is so damn confusing !!!
        // **debugging**std::string dumpit = pJson->dump();

        size_t signatureCount = pJson->at("result").at("signatures").size();
        if (not signatureCount) return;

        json signatures = pJson->at("result").at("signatures");
        for (size_t labelndx=0; labelndx<signatureCount && labelndx<10; ++labelndx)
        {
                wxString labelValue = signatures[labelndx].at("label").get<std::string>();
                v_SignatureTokens.push_back(cbCodeCompletionPlugin::CCCallTip(labelValue));
        }

I'm not sure, but it looks like:

Code
wxString labelValue = signatures[labelndx].at("label").get<std::string>();

get<std::string>() should return a std::string.

Do we need to convert it to wxString?
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on September 30, 2022, 09:14:17 am
OK, I think I have fixed this issue by using such patch:

Code
From 8523dd2bd9a58d1780c3d2efe9459f7e5fccfb41 Mon Sep 17 00:00:00 2001
From: hide<hide@hide.hide>
Date: Fri, 30 Sep 2022 15:11:28 +0800
Subject: fix the wrong tip code when Chinese comment is used


diff --git a/clangd_client/src/codecompletion/parser/parser.cpp b/clangd_client/src/codecompletion/parser/parser.cpp
index 2b9c5ea..3ddde25 100644
--- a/clangd_client/src/codecompletion/parser/parser.cpp
+++ b/clangd_client/src/codecompletion/parser/parser.cpp
@@ -2546,7 +2546,8 @@ void Parser::OnLSP_HoverResponse(wxCommandEvent& event, std::vector<ClgdCCToken>
         if (not valueItemsCount) return;
 
         json contents = pJson->at("result").at("contents");
-        wxString contentsValue = contents.at("value").get<std::string>();
+        std::string contentsValueStdString = contents.at("value").get<std::string>();
+        wxString contentsValue(contentsValueStdString.c_str(), wxConvUTF8);
 
         // Example Hover contents: L"instance-method HelloWxWorldFrame::OnAbout\n\nType: void\nParameters:\n- wxCommandEvent & event\n\n// In HelloWxWorldFrame\nprivate: void HelloWxWorldFrame::OnAbout(wxCommandEvent &event)"
         // get string array of hover info separated at /n chars.
@@ -2670,7 +2671,8 @@ void Parser::OnLSP_SignatureHelpResponse(wxCommandEvent& event, std::vector<cbCo
         json signatures = pJson->at("result").at("signatures");
         for (size_t labelndx=0; labelndx<signatureCount && labelndx<10; ++labelndx)
         {
-                wxString labelValue = signatures[labelndx].at("label").get<std::string>();
+                std::string labelValueStdString = signatures[labelndx].at("label").get<std::string>();
+                wxString labelValue(labelValueStdString.c_str(), wxConvUTF8);
                 v_SignatureTokens.push_back(cbCodeCompletionPlugin::CCCallTip(labelValue));
         }
 


I'm not sure the second hunk is needed, but the first hunk is the true fix.
Title: Re: Code completion using LSP and clangd
Post by: sodev on September 30, 2022, 08:22:14 pm
Since i have seen quite some string encoding related issues in this thread and many try-and-error attempts to solve them, i want to add my two cents to these issues.

Never do this:
Code
wxString contentsValue = contents.at("value").get<std::string>();

This converts the std::string into a wxString using the currently set C++ locale. A locale set in CodeBlocks. But this std::string does not come from CodeBlocks. Also, std::string has, at least on Windows, no support for UTF-8. However, this doesn't stop anyone from putting UTF-8 into such a string. As long as you don't use methods that depend on the locale, this is fine. The code snippet above does depend on the locale.

Now these two lines:
Code
std::string contentsValueStdString = contents.at("value").get<std::string>();
wxString contentsValue(contentsValueStdString.c_str(), wxConvUTF8);

These lines manually convert the std::string to a wxString by telling the wxString object that the std::string does contain UTF-8. Since the user post says this does fix the issue, apparently there is UTF-8 inside that std::string.

I suggest you figure out what encoding Clang does use and then check your code if you rely anywhere else on such automatic conversions. Also, wxWidgets offers the build option wxNO_UNSAFE_WXSTRING_CONV to disable such implicit conversions, but i am not sure if this does also work for std::string, they mention only C-Strings.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 01, 2022, 01:47:51 am
Since i have seen quite some string encoding related issues in this thread and many try-and-error attempts to solve them, i want to add my two cents to these issues.

Never do this:
Code
wxString contentsValue = contents.at("value").get<std::string>();

This converts the std::string into a wxString using the currently set C++ locale. A locale set in CodeBlocks. But this std::string does not come from CodeBlocks. Also, std::string has, at least on Windows, no support for UTF-8. However, this doesn't stop anyone from putting UTF-8 into such a string. As long as you don't use methods that depend on the locale, this is fine. The code snippet above does depend on the locale.

Now these two lines:
Code
std::string contentsValueStdString = contents.at("value").get<std::string>();
wxString contentsValue(contentsValueStdString.c_str(), wxConvUTF8);

These lines manually convert the std::string to a wxString by telling the wxString object that the std::string does contain UTF-8. Since the user post says this does fix the issue, apparently there is UTF-8 inside that std::string.

I suggest you figure out what encoding Clang does use and then check your code if you rely anywhere else on such automatic conversions. Also, wxWidgets offers the build option wxNO_UNSAFE_WXSTRING_CONV to disable such implicit conversions, but i am not sure if this does also work for std::string, they mention only C-Strings.

Hi, sodev, thanks for the advice.

If I remember correctly, the clangd_client use the UTF-8 format for it's input source. Normally I use UTF-8 for my source code, but my system(Windows) locale is not UTF-8.

I see that clangd's document: Protocol extensions UTF-8 offsets (https://clangd.llvm.org/extensions.html#utf-8-offsets)

It said it can support UTF-8.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 01, 2022, 09:35:41 pm
Since i have seen quite some string encoding related issues in this thread and many try-and-error attempts to solve them, i want to add my two cents to these issues.

Never do this:
Code
wxString contentsValue = contents.at("value").get<std::string>();

This converts the std::string into a wxString using the currently set C++ locale. A locale set in CodeBlocks. But this std::string does not come from CodeBlocks. Also, std::string has, at least on Windows, no support for UTF-8. However, this doesn't stop anyone from putting UTF-8 into such a string. As long as you don't use methods that depend on the locale, this is fine. The code snippet above does depend on the locale.

Now these two lines:
Code
std::string contentsValueStdString = contents.at("value").get<std::string>();
wxString contentsValue(contentsValueStdString.c_str(), wxConvUTF8);

These lines manually convert the std::string to a wxString by telling the wxString object that the std::string does contain UTF-8. Since the user post says this does fix the issue, apparently there is UTF-8 inside that std::string.

I suggest you figure out what encoding Clang does use and then check your code if you rely anywhere else on such automatic conversions. Also, wxWidgets offers the build option wxNO_UNSAFE_WXSTRING_CONV to disable such implicit conversions, but i am not sure if this does also work for std::string, they mention only C-Strings.

Hi, sodev, thanks for the advice.

If I remember correctly, the clangd_client use the UTF-8 format for it's input source. Normally I use UTF-8 for my source code, but my system(Windows) locale is not UTF-8.

I see that clangd's document: Protocol extensions UTF-8 offsets (https://clangd.llvm.org/extensions.html#utf-8-offsets)

It said it can support UTF-8.

@sodev
@ollydbg

Thanks for this. I'll get to work checking every use of std::string to wxString in the source.

Clangd by default uses utf16. But it allows the use of utf8 as an option.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 03, 2022, 07:43:47 pm
@ollydbg

OK, I think I have fixed this issue by using such patch:

Code
From 8523dd2bd9a58d1780c3d2efe9459f7e5fccfb41 Mon Sep 17 00:00:00 2001
From: hide<hide@hide.hide>
Date: Fri, 30 Sep 2022 15:11:28 +0800
Subject: fix the wrong tip code when Chinese comment is used


diff --git a/clangd_client/src/codecompletion/parser/parser.cpp b/clangd_client/src/codecompletion/parser/parser.cpp
index 2b9c5ea..3ddde25 100644
--- a/clangd_client/src/codecompletion/parser/parser.cpp
+++ b/clangd_client/src/codecompletion/parser/parser.cpp
@@ -2546,7 +2546,8 @@ void Parser::OnLSP_HoverResponse(wxCommandEvent& event, std::vector<ClgdCCToken>
         if (not valueItemsCount) return;
 
         json contents = pJson->at("result").at("contents");
-        wxString contentsValue = contents.at("value").get<std::string>();
+        std::string contentsValueStdString = contents.at("value").get<std::string>();
+        wxString contentsValue(contentsValueStdString.c_str(), wxConvUTF8);
 
         // Example Hover contents: L"instance-method HelloWxWorldFrame::OnAbout\n\nType: void\nParameters:\n- wxCommandEvent & event\n\n// In HelloWxWorldFrame\nprivate: void HelloWxWorldFrame::OnAbout(wxCommandEvent &event)"
         // get string array of hover info separated at /n chars.
@@ -2670,7 +2671,8 @@ void Parser::OnLSP_SignatureHelpResponse(wxCommandEvent& event, std::vector<cbCo
         json signatures = pJson->at("result").at("signatures");
         for (size_t labelndx=0; labelndx<signatureCount && labelndx<10; ++labelndx)
         {
-                wxString labelValue = signatures[labelndx].at("label").get<std::string>();
+                std::string labelValueStdString = signatures[labelndx].at("label").get<std::string>();
+                wxString labelValue(labelValueStdString.c_str(), wxConvUTF8);
                 v_SignatureTokens.push_back(cbCodeCompletionPlugin::CCCallTip(labelValue));
         }
 


I'm not sure the second hunk is needed, but the first hunk is the true fix.

@ollydbg

Would you test Clangd_Client rev 82 or the current nightly clangd_client to see if it solves the tooltip problem?

I've applied your fix for every clangd json std::string reference.
Example:
Code
 
idValue = GetwxUTF8Str(pJson->at("id").get<std::string>());

GetwxUTFStr is defined as:
Code
        wxString GetwxUTF8Str(const std::string stdString)
        {
            return wxString(stdString.c_str(), wxConvUTF8);
        }


Let me know if it works and thanks for testing.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 04, 2022, 02:43:39 am
Hi, pecan, thanks for the fix.

rev 82 works OK.

BTW, Is it possible to show the doxygen document in the tip window? Maybe, clangd already send to us? Thanks.

EDIT:

It looks like this clangd issue in github is related: Doxygen parsing missing Issue #529 clangd/clangd (https://github.com/clangd/clangd/issues/529)
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 04, 2022, 09:11:14 am
I did some extra test of how to show the comments.

Here is the log file from CBclangd_client-xxxxx.log:

Code
{"id":"textDocument/hover","jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":4,"line":3},"textDocument":{"uri":"file:///F:/code/test_clangd_client_tipwin/main.cpp"}}}

15:06:48.772 >>> readJson() len:220:
{"id":"textDocument/hover","jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"variable m_AAA\n\nType: int\nABCDEFG\n\nint m_AAA"},"range":{"end":{"character":9,"line":3},"start":{"character":4,"line":3}}}}

15:07:41.294 <<< Hover:
file:///F:/code/test_clangd_client_tipwin/main.cpp,line[1], char[4]

15:07:41.294 <<< Content-Length: 196



{"id":"textDocument/hover","jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":4,"line":1},"textDocument":{"uri":"file:///F:/code/test_clangd_client_tipwin/main.cpp"}}}

15:07:41.524 >>> readJson() len:240:
{"id":"textDocument/hover","jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"variable m_TcpFile\n\nType: int\nTCP鎺ユ敹鐨勬暟鎹甛n\nint m_TcpFile"},"range":{"end":{"character":13,"line":1},"start":{"character":4,"line":1}}}}

and here is the test code:
Code

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

int m_AAA; ///< ABCDEFG

int main()
{
    return 0;
}




You can see, when I hover on the variable "m_TcpFile", the received json contains some wrong contents, I'm not sure why it is not shown in Chinese.
While, for the variable "m_AAA", it shows the "ABCDEFG" correctly.


EDIT

It looks like we just drop the text returned from clangd, after the second \n

Here is the screen shot(in attachment)

The source code looks like in parser.cpp line 2553

Code
        // Example Hover contents: L"instance-method HelloWxWorldFrame::OnAbout\n\nType: void\nParameters:\n- wxCommandEvent & event\n\n// In HelloWxWorldFrame\nprivate: void HelloWxWorldFrame::OnAbout(wxCommandEvent &event)"
        // get string array of hover info separated at /n chars.
        wxString hoverString = contentsValue;
        hoverString.Replace("\n\n", "\n"); //remove double newline chars
        wxArrayString vHoverInfo = GetArrayFromString(hoverString, "\n");

        // **Debugging**
        // LogManager* pLogMgr = Manager::Get()->GetLogManager();
        //    for (size_t ii=0; ii<vHoverInfo.size(); ++ii)
        //        pLogMgr->DebugLog(wxString::Format("vHoverInfo[%d]:%s", int(ii), vHoverInfo[ii]));

        // Find items from hover data and cut the chaff
        wxString hoverText;
        for (size_t ii=0, foundIn=false; ii<vHoverInfo.size(); ++ii)
        {
            if (ii < 2) hoverText += vHoverInfo[ii] + "\n"; //type and return value
            if (vHoverInfo[ii].StartsWith("// In "))    //parent
            {
                hoverText += vHoverInfo[ii] += "\n";
                foundIn = true; continue;
            }
            if (foundIn) hoverText += vHoverInfo[ii] + "\n";;
        }//endfor vHoverInfo

        v_HoverTokens.push_back(ClgdCCToken(0, hoverText, hoverText));
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on October 04, 2022, 11:27:44 am
@pecan,

I observed an unexpected behavior (i would say a bug) using the latest nightly and latest plugin. I'm observing the issue using both win7 SP1 or Win10 Enterprise.

After I opened a project the plugin started to parse the files starting from "62 more" ....in the meantime I launch the related executable (compiled before). The parser stopped. During the stopping phase the parser is parsing some files without updating the remaining file counter (repeating "59 more")

After closing the executable, the parser didn't restarted, It stayed sleeping. I used the option "Reparse the project" but the new parser was not starting. I opened one of the project's file (Main.cpp) and the parser parsed the opened file (restarting the remaining file counter from 66, not 62!!!! ( the previous starting number)  but then stopped.

I closed Main.cpp and used several times "reparse the project" without success. I closed the project and the reopened it....the parser didn't start.

Then if I close CB and running a new CB loading the same projects used before I got the parser correctly parsing all files form 66 to 0.

I'm attaching the log from CB.

Hope this helps to reproduce the issue (It seems reproducible). I'm using 0 threads while compiling (and running?) and 6 threads concurrently parsing.

It seems there is some "memory" of the past parsing even if I delete the parser....

Max
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 04, 2022, 01:21:01 pm
I created a patch which can show the "doxygen comments".

Code
 clangd_client/src/codecompletion/parser/parser.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clangd_client/src/codecompletion/parser/parser.cpp b/clangd_client/src/codecompletion/parser/parser.cpp
index 6852ee2..4706432 100644
--- a/clangd_client/src/codecompletion/parser/parser.cpp
+++ b/clangd_client/src/codecompletion/parser/parser.cpp
@@ -2563,13 +2563,14 @@ void Parser::OnLSP_HoverResponse(wxCommandEvent& event, std::vector<ClgdCCToken>
         wxString hoverText;
         for (size_t ii=0, foundIn=false; ii<vHoverInfo.size(); ++ii)
         {
-            if (ii < 2) hoverText += vHoverInfo[ii] + "\n"; //type and return value
             if (vHoverInfo[ii].StartsWith("// In "))    //parent
             {
                 hoverText += vHoverInfo[ii] += "\n";
                 foundIn = true; continue;
             }
-            if (foundIn) hoverText += vHoverInfo[ii] + "\n";;
+            if (foundIn) hoverText += vHoverInfo[ii] + "\n";
+
+            if (ii < 3) hoverText += vHoverInfo[ii] + "\n"; //type and return value  [0]: kind, [1]: type, [2]: comments
         }//endfor vHoverInfo
 
         v_HoverTokens.push_back(ClgdCCToken(0, hoverText, hoverText));


Normally, I see that

Code
variable m_AAA\n\nType: int\nABCDEFG\n\nint m_AAA

There are 3 sections separated by "\n\n", first: "variable m_AAA", second: "Type: int\nABCDEFG", and third: "int m_AAA". Basically the first two sections are needed.

There is two ";" in the original statement, this should be fixed.
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on October 05, 2022, 02:46:09 pm
@pecan

I'm observing another issue using the clangd plugin.

Using a std::vector the list of functions shown are listed in alphabetical order but it seems there is a maximum number of list members. Look at the attached images, all the functions after max_size() are not listed. For example push_back() is not listed but if I write "push" after the dot the plugin is correctly suggesting push_back (look at the attached images).

So it seems that the plugin knows the function push_back() exists but is not showing in the full list.

Is there a way to increase the number of items in the list? Is that limitation intentional?

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 06, 2022, 03:36:18 am
I did some extra test of how to show the comments.

Here is the log file from CBclangd_client-xxxxx.log:

Code
...

15:07:41.524 >>> readJson() len:240:
{"id":"textDocument/hover","jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"variable m_TcpFile\n\nType: int\nTCP鎺ユ敹鐨勬暟鎹甛n\nint m_TcpFile"},"range":{"end":{"character":13,"line":1},"start":{"character":4,"line":1}}}}


The log file shows the wrong Chinese words.

Code
 int\nTCP鎺ユ敹鐨勬暟鎹甛n\n

The following patch solves this issue:

Code
 clangd_client/src/LSPclient/client.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clangd_client/src/LSPclient/client.cpp b/clangd_client/src/LSPclient/client.cpp
index c4a7729..76d19ca 100644
--- a/clangd_client/src/LSPclient/client.cpp
+++ b/clangd_client/src/LSPclient/client.cpp
@@ -1020,7 +1020,7 @@ bool ProcessLanguageClient::readJson(json &json)
     m_MutexInputBufGuard.Unlock();
 
     if (stdStrInputbuf.size())
-        writeClientLog(wxString::Format(">>> readJson() len:%d:\n%s", length, stdStrInputbuf.c_str()) );
+        writeClientLog(wxString::Format(">>> readJson() len:%d:\n%s", length, GetwxUTF8Str(stdStrInputbuf.c_str()).wx_str()) );
 
     // remove any invalid utf8 chars
     bool validData = DoValidateUTF8data(stdStrInputbuf);
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 06, 2022, 05:48:35 am
I created a patch which can show the "doxygen comments".
...

I think it again, and I think using the original text from the hover message is good enough. I think we don't need to "cut the chaff".

wxString hoverString = contentsValue;

Just show this, and I tested this method, and it works fine.
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on October 09, 2022, 11:40:42 pm
@pecan

About my replay #203....

I read the message in which you said you are unable to replicate the issue. I was about to create a test project but it seems that your messagewas deleted. Do you replicated the issue?
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 10, 2022, 06:41:29 am
@pecan

About my replay #203....

I read the message in which you said you are unable to replicate the issue. I was about to create a test project but it seems that your messagewas deleted. Do you replicated the issue?
Yes, I was finally able to replicate the issue and fix it in the new Nightly 221008.
https://forums.codeblocks.org/index.php/topic,25130.msg171351/topicseen.html#msg171351 (https://forums.codeblocks.org/index.php/topic,25130.msg171351/topicseen.html#msg171351)

To change the number of matched completions displayed use Settings/Editor/clangd_client/Maximum allowed code-completion matches.
I suggest you be conservative since the matches are cached, ie., taking up memory until new completions are requested.

Thanks for catching this and for testing.

Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 10, 2022, 06:59:15 am
I did some extra test of how to show the comments.

Here is the log file from CBclangd_client-xxxxx.log:

Code
...

15:07:41.524 >>> readJson() len:240:
{"id":"textDocument/hover","jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"variable m_TcpFile\n\nType: int\nTCP鎺ユ敹鐨勬暟鎹甛n\nint m_TcpFile"},"range":{"end":{"character":13,"line":1},"start":{"character":4,"line":1}}}}


The log file shows the wrong Chinese words.

Code
 int\nTCP鎺ユ敹鐨勬暟鎹甛n\n

The following patch solves this issue:

Code
 clangd_client/src/LSPclient/client.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clangd_client/src/LSPclient/client.cpp b/clangd_client/src/LSPclient/client.cpp
index c4a7729..76d19ca 100644
--- a/clangd_client/src/LSPclient/client.cpp
+++ b/clangd_client/src/LSPclient/client.cpp
@@ -1020,7 +1020,7 @@ bool ProcessLanguageClient::readJson(json &json)
     m_MutexInputBufGuard.Unlock();
 
     if (stdStrInputbuf.size())
-        writeClientLog(wxString::Format(">>> readJson() len:%d:\n%s", length, stdStrInputbuf.c_str()) );
+        writeClientLog(wxString::Format(">>> readJson() len:%d:\n%s", length, GetwxUTF8Str(stdStrInputbuf.c_str()).wx_str()) );
 
     // remove any invalid utf8 chars
     bool validData = DoValidateUTF8data(stdStrInputbuf);

In clangd_client rev 83, I've completely reworked writing to the logs.

The purpose of the logs (for me) is to see exactly what clangd was sending to the CB client. My prior code was not accomplishing that. It was converting std:strings (from clangd) to wxStrings. I should not have done that.

I changed the log code to record the std:strings as clangd sent them, which is much more accurate in my estimation.

Would you retest the the error you're getting to see if rev 83 also gets the error.
If it does, I'd rather fix it using the conversion methods you and sodev suggested in other forum messages without modifying the logs.

Thanks for testing.
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on October 10, 2022, 11:17:39 am

About my replay #203....


Yes, I was finally able to replicate the issue and fix it in the new Nightly 221008.

Pecan, I do not want to bore you....

Yes you fixed the issue related to my message #205 but the bugs in #203 is still present (latest nightly and plugin, Win7 and Win10).

I'm observing the plugin in "sleep state" in several way but the one in #203 seems the simpler test case. The most surprising thing is that I need to close CB to force a reparse...

If you need a test project to replicate the issue let me know.

Thank you anyway for your plugin...is usable and good (IMHO)

MAx
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 10, 2022, 03:21:56 pm

In clangd_client rev 83, I've completely reworked writing to the logs.

The purpose of the logs (for me) is to see exactly what clangd was sending to the CB client. My prior code was not accomplishing that. It was converting std:strings (from clangd) to wxStrings. I should not have done that.

I changed the log code to record the std:strings as clangd sent them, which is much more accurate in my estimation.

Would you retest the the error you're getting to see if rev 83 also gets the error.
If it does, I'd rather fix it using the conversion methods you and sodev suggested in other forum messages without modifying the logs.

Thanks for testing.

Hi, I have just tested this rev83. But it looks like the log still has some error Chinese chars. See the log below:

Code
{"id":"textDocument/hover","jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":4,"line":5},"textDocument":{"uri":"file:///F:/code/test_clangd_client_tipwin/main.cpp"}}}

19:59:55.500 >>> readJson() len:220:
{"id":"textDocument/hover","jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"variable m_AAA\n\nType: int\nABCDEFG\n\nint m_AAA"},"range":{"end":{"character":9,"line":5},"start":{"character":4,"line":5}}}}

19:59:58.665 <<< Hover:
file:///F:/code/test_clangd_client_tipwin/main.cpp,line[1], char[4]

19:59:58.666 <<< Content-Length: 196



{"id":"textDocument/hover","jsonrpc":"2.0","method":"textDocument/hover","params":{"position":{"character":4,"line":1},"textDocument":{"uri":"file:///F:/code/test_clangd_client_tipwin/main.cpp"}}}

19:59:58.750 >>> readJson() len:240:
{"id":"textDocument/hover","jsonrpc":"2.0","result":{"contents":{"kind":"plaintext","value":"variable m_TcpFile\n\nType: int\nTCP鎺ユ敹鐨勬暟鎹甛n\nint m_TcpFile"},"range":{"end":{"character":13,"line":1},"start":{"character":4,"line":1}}}}

I see you have a function named:

std::string StdString_Format(const std::string fmt, ...)

I try to use this patch to avoid the function call, like:

Code
-------------------- clangd_client/src/LSPclient/client.cpp --------------------
index faecc9c..e92c789 100644
@@ -1068,7 +1068,7 @@ bool ProcessLanguageClient::readJson(json &json)
     m_MutexInputBufGuard.Unlock();
 
     if (stdStrInputbuf.size())
-        writeClientLog(StdString_Format(">>> readJson() len:%d:\n%s", length, stdStrInputbuf.c_str()) );
+        writeClientLog(StdString_Format(">>> readJson() len:%d:\n", length) + stdStrInputbuf);
 
     // remove any invalid utf8 chars
     bool validData = DoValidateUTF8data(stdStrInputbuf);

But I still got the same error result of Chinese chars.  :(

Anyway, though the log file contains error Chinese chars, but the tip window shows correct Chinese words. (I'm showing the whole contents of the hoverString in the tip window)

Code
         // Example Hover contents: L"instance-method HelloWxWorldFrame::OnAbout\n\nType: void\nParameters:\n- wxCommandEvent & event\n\n// In HelloWxWorldFrame\nprivate: void HelloWxWorldFrame::OnAbout(wxCommandEvent &event)"
         // get string array of hover info separated at /n chars.
         wxString hoverString = contentsValue;

See image shot below in attachment.

Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 10, 2022, 08:09:14 pm

About my reply #203....


Yes, I was finally able to replicate the issue and fix it in the new Nightly 221008.

Pecan, I do not want to bore you....

Yes you fixed the issue related to my message #205 but the bugs in #203 is still present (latest nightly and plugin, Win7 and Win10).

I'm observing the plugin in "sleep state" in several way but the one in #203 seems the simpler test case. The most surprising thing is that I need to close CB to force a reparse...

If you need a test project to replicate the issue let me know.

Thank you anyway for your plugin...is usable and good (IMHO)

MAx
@MaxGaspa
Do NOT think that you bore me. I'm grateful for your help.
Thanks for reporting that the max completion matches list is fixed.

I have not yet had time to investigate the Pause/Sleep ("sleep state") bug.
I agree that it's a bug. I'll look at it very soon.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 11, 2022, 03:41:12 am

But I still got the same error result of Chinese chars.  :(


I guess in some stage, the original string(in UTF8) is still translated to the unicode string by my local encoding(GB2312, not the UTF8).

EDIT

Code
// ----------------------------------------------------------------------------
void ProcessLanguageClient::writeClientLog(const std::string& logmsg)
// ----------------------------------------------------------------------------
{
    if (not lspClientLogFile.IsOpened()) return;
    std::string logcr = "";
    if (not StdString_EndsWith(logmsg, "\n"))
        logcr = "\n";
    lspClientLogFile.Write("\n" + GetTime_in_HH_MM_SS_MMM() + " " + logmsg + logcr);
    lspClientLogFile.Flush();
}
// ----------------------------------------------------------------------------
void ProcessLanguageClient::writeServerLog(const std::string& logmsg)
// ----------------------------------------------------------------------------
{
    if (not lspServerLogFile.IsOpened()) return;
    lspServerLogFile.Write(logmsg);
    lspServerLogFile.Flush();

It looks like the wxFFile::Write only accept the wxString, but you passed the std:;string, so the wrong encoding is used for conversion.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 11, 2022, 04:17:36 am
Hi, Pecan, my guess is correct.  ;)

Code
-------------------- clangd_client/src/LSPclient/client.cpp --------------------
index e92c789..5c56b26 100644
@@ -626,7 +626,7 @@ void ProcessLanguageClient::writeClientLog(const std::string& logmsg)
     std::string logcr = "";
     if (not StdString_EndsWith(logmsg, "\n"))
         logcr = "\n";
-    lspClientLogFile.Write("\n" + GetTime_in_HH_MM_SS_MMM() + " " + logmsg + logcr);
+    lspClientLogFile.Write("\n" + GetTime_in_HH_MM_SS_MMM() + " " + GetwxUTF8Str(logmsg) + logcr);
     lspClientLogFile.Flush();
 }
 // ----------------------------------------------------------------------------
@@ -634,7 +634,7 @@ void ProcessLanguageClient::writeServerLog(const std::string& logmsg)
 // ----------------------------------------------------------------------------
 {
     if (not lspServerLogFile.IsOpened()) return;
-    lspServerLogFile.Write(logmsg);
+    lspServerLogFile.Write(GetwxUTF8Str(logmsg));
     lspServerLogFile.Flush();
 
     //(ph 2022/02/16)



With this patch, the log file is correctly showing the non-ascii characters.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 11, 2022, 06:36:51 am
Hi, Pecan, my guess is correct.  ;)

Code
-------------------- clangd_client/src/LSPclient/client.cpp --------------------
index e92c789..5c56b26 100644
@@ -626,7 +626,7 @@ void ProcessLanguageClient::writeClientLog(const std::string& logmsg)
     std::string logcr = "";
     if (not StdString_EndsWith(logmsg, "\n"))
         logcr = "\n";
-    lspClientLogFile.Write("\n" + GetTime_in_HH_MM_SS_MMM() + " " + logmsg + logcr);
+    lspClientLogFile.Write("\n" + GetTime_in_HH_MM_SS_MMM() + " " + GetwxUTF8Str(logmsg) + logcr);
     lspClientLogFile.Flush();
 }
 // ----------------------------------------------------------------------------
@@ -634,7 +634,7 @@ void ProcessLanguageClient::writeServerLog(const std::string& logmsg)
 // ----------------------------------------------------------------------------
 {
     if (not lspServerLogFile.IsOpened()) return;
-    lspServerLogFile.Write(logmsg);
+    lspServerLogFile.Write(GetwxUTF8Str(logmsg));
     lspServerLogFile.Flush();
 
     //(ph 2022/02/16)



With this patch, the log file is correctly showing the non-ascii characters.

There is no need for the logs to show only ascii chars.
I hex dumped that section of the log. Those non ascii chars are each legal utf8 3byte hex representations of one char.

At the point we need to use/display them, we do the GetwxUTF8String() to convert them to wxStrings.
That works just fine.

Please do not convert the logs. I need them to look just the same as clangd sent to us. Especially when trying to document possible bugs.

Thanks for the work you do. I'm grateful.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 11, 2022, 11:44:26 am
There is no need for the logs to show only ascii chars.
I hex dumped that section of the log. Those non ascii chars are each legal utf8 3byte hex representations of one char.

At the point we need to use/display them, we do the GetwxUTF8String() to convert them to wxStrings.
That works just fine.

Please do not convert the logs. I need them to look just the same as clangd sent to us. Especially when trying to document possible bugs.

Thanks for the work you do. I'm grateful.


Hi, Pecan, I think the using of member function Write from wxWidgets: wxFFile Class Reference (https://docs.wxwidgets.org/3.0/classwx_f_file.html):

Code
bool 	Write (const wxString &str, const wxMBConv &conv=wxConvAuto())

which is wrong here.

If you look at the source code, you will see:

Code
// ----------------------------------------------------------------------------
void ProcessLanguageClient::writeClientLog(const std::string& logmsg)
// ----------------------------------------------------------------------------
{
    if (not lspClientLogFile.IsOpened()) return;
    std::string logcr = "";
    if (not StdString_EndsWith(logmsg, "\n"))
        logcr = "\n";
    lspClientLogFile.Write("\n" + GetTime_in_HH_MM_SS_MMM() + " " + logmsg + logcr);
    lspClientLogFile.Flush();
}

In this code, you first construct a std::string arg0:

Code
arg0 = "\n" + GetTime_in_HH_MM_SS_MMM() + " " + logmsg + logcr

Then, the lspClientLogFile.Write() function need a wxString, so the arg0 is convert to wxString(arg0), and the bad thing is it will use the "Locale encodings", in my PC, it could be GB2312. The wrong thing is: logmsg is returned from clangd, which is encoded in UTF8, and the implicit conversion from arg0 to wxString is using Locale encodings(GB2312).

I think if you just need a byte stream, then we need another member function:

Code
size_t 	Write (const void *buffer, size_t count)

This just Writes the specified number of bytes from a buffer.

I hope you can understand my explanation.



Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 14, 2022, 09:45:18 pm

...Partial quote....

Yes you fixed the issue related to my message #205 but the bugs in #203 is still present (latest nightly and plugin, Win7 and Win10).

I'm observing the plugin in "sleep state" in several way but the one in #203 seems the simpler test case. The most surprising thing is that I need to close CB to force a reparse...

If you need a test project to replicate the issue let me know.

Thank you anyway for your plugin...is usable and good (IMHO)

MAx

@ MaxGaspa

Try the "-2" version below to see if it fixes the "sleep state" error.
It seems you've run across a CB bug where the "compiler finished" event was not being issued and clangd_client got stuck waiting for the compiler to end.

I've made a temporary fix (until the next Nightly) that circumvents the missing event.

Be careful though, the circumvention allows clangd to parse files while the "Run" command is active. You might want to right-click on the project name and "Pause parsing(toggle)" before running your program from the menu run command.

After the "Run" finishes, you can "Pause parsing(toggle)" again to continue parsing where it left off.

Try:
 
https://sourceforge.net/projects/cb-clangd-client/files/Plugin_Install_Package/Windows_x64/ClangdClientForCBNightly_221008_rev12969_win64-2.zip/download
 (https://sourceforge.net/projects/cb-clangd-client/files/Plugin_Install_Package/Windows_x64/ClangdClientForCBNightly_221008_rev12969_win64-2.zip/download)
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 14, 2022, 10:27:38 pm
@ olldbg RE: Reply #218 on: October 11, 2022, 02:44:26

Thanks, it works for me.
Will be in rev 85.
Code
// ----------------------------------------------------------------------------
void ProcessLanguageClient::writeClientLog(const std::string& logmsg)
// ----------------------------------------------------------------------------
{
    if (not lspClientLogFile.IsOpened()) return;
    std::string logcr = "";
    if (not StdString_EndsWith(logmsg, "\n"))
        logcr = "\n";
    std::string out = "\n" + GetTime_in_HH_MM_SS_MMM() + " " + logmsg + logcr;
    lspClientLogFile.Write(out.c_str(), out.size());
    lspClientLogFile.Flush();
}
// ----------------------------------------------------------------------------
void ProcessLanguageClient::writeServerLog(const std::string& logmsg)
// ----------------------------------------------------------------------------
{
    if (not lspServerLogFile.IsOpened()) return;
    lspServerLogFile.Write(logmsg.c_str(), logmsg.size());
    lspServerLogFile.Flush();

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 15, 2022, 05:36:38 am
@ olldbg RE: Reply #218 on: October 11, 2022, 02:44:26

Thanks, it works for me.
Will be in rev 85.
Code
// ----------------------------------------------------------------------------
void ProcessLanguageClient::writeClientLog(const std::string& logmsg)
// ----------------------------------------------------------------------------
{
    if (not lspClientLogFile.IsOpened()) return;
    std::string logcr = "";
    if (not StdString_EndsWith(logmsg, "\n"))
        logcr = "\n";
    std::string out = "\n" + GetTime_in_HH_MM_SS_MMM() + " " + logmsg + logcr;
    lspClientLogFile.Write(out.c_str(), out.size());
    lspClientLogFile.Flush();
}
// ----------------------------------------------------------------------------
void ProcessLanguageClient::writeServerLog(const std::string& logmsg)
// ----------------------------------------------------------------------------
{
    if (not lspServerLogFile.IsOpened()) return;
    lspServerLogFile.Write(logmsg.c_str(), logmsg.size());
    lspServerLogFile.Flush();


Good work, this should the correct fix.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 15, 2022, 05:47:11 am
Hi, I'm building clangd_client rev84 with the latest C::B rev 12976.

Do I need to change the line to this:

Code
// ----------------------------------------------------------------------------
void ClgdCompletion::OnCompilerStarted(CodeBlocksEvent& event)
// ----------------------------------------------------------------------------
{
    //If this is a idCompileMenuRun only, do not set compiler is running
    // else we'll hang before nightly rev 12975 fix
    //#warning Developer should remove this condition after nightly for CB rev 12975
    //if (ns_CompilerEventId == XRCID("idCompilerMenuRun")) return;
    GetParseManager()->SetCompilerIsRunning(true);
}

I have to comment out the line

Code
    //if (ns_CompilerEventId == XRCID("idCompilerMenuRun")) return;

Am I correct?
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 15, 2022, 06:56:44 am
Hi, I'm building clangd_client rev84 with the latest C::B rev 12976.

Do I need to change the line to this:

Code
// ----------------------------------------------------------------------------
void ClgdCompletion::OnCompilerStarted(CodeBlocksEvent& event)
// ----------------------------------------------------------------------------
{
    //If this is a idCompileMenuRun only, do not set compiler is running
    // else we'll hang before nightly rev 12975 fix
    //#warning Developer should remove this condition after nightly for CB rev 12975
    //if (ns_CompilerEventId == XRCID("idCompilerMenuRun")) return;
    GetParseManager()->SetCompilerIsRunning(true);
}

I have to comment out the line

Code
    //if (ns_CompilerEventId == XRCID("idCompilerMenuRun")) return;

Am I correct?

You are correct. That fix is not needed with CB rev 12975 and above.

Thanks for testing.
Title: Re: Code completion using LSP and clangd
Post by: MaxGaspa on October 15, 2022, 09:36:37 am

I've made a temporary fix (until the next Nightly) that circumvents the missing event.

Be careful though, the circumvention allows clangd to parse files while the "Run" command is active. You might want to right-click on the project name and "Pause parsing(toggle)" before running your program from the menu run command.

After the "Run" finishes, you can "Pause parsing(toggle)" again to continue parsing where it left off.


@pecan

At the moment I'm unable to replicate the bug, so the bug seems fixed.

Is there any inconvenience leaving the parser working while I'm running the application? I mean not considering the CPU usage?

Max
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 15, 2022, 12:56:32 pm
Hi, Pecan, In the latested r84 and with the change to using the std::string output of the both function writeClientLog() and writeServerLog().

I found an interesting thing that I got two different encoding output of the Chinese text in the comments.
One place is here, in the function: bool ProcessLanguageClient::WriteHdr(const std::string &in)
I see that the output of the content(usually the textDocument/didOpen message's content the client try to send to the LSP server) will be in GB2312 in my PC.
While, the content received from the server(usually the textDocument/hover message return from the LSP server) will be in UTF8 format.

I just exam the function body: bool ProcessLanguageClient::WriteHdr(), I see it still use the some kinds of std::string to wxString, and later some wxString to std::string, some conversion will use the default local encoding.

For example:
Code
limitedLogOut = wxString::Format("<<< Write():\n%s", wxString(in)).Mid(0,512) + "<...DATA SNIPED BY LOG WRITE()...>";

The variable in to wxString will use wrong encoding.

So, what I think is that we should use std::string inside the WriteHdr().

Even I see there is a function call:

Code
    // Write raw data to clangd server
    #if defined(_WIN32)
        bool ok = m_pServerProcess->WriteRaw( out ); //windows
        if (not ok)
        {
            writeClientLog("Error: WriteHdr() failed WriteRaw()");
            return false;
        }
    #else
        // unix just posts the msg to an output thread queue, so no return code.
        m_pServerProcess->Write( fileUtils.ToStdString(out) );            //unix
    #endif

I think the content sent to the pipe is still in UTF8 encoding. (I just checked the code in src\winprocess\asyncprocess\winprocess_impl.cpp.

Code
bool WinProcessImpl::Write(const std::string& buff) { return WriteRaw(buff + "\r\n"); }

bool WinProcessImpl::WriteRaw(const wxString& buff) { return WriteRaw(FileUtils::ToStdString(buff)); }

bool WinProcessImpl::WriteRaw(const std::string& buff)
{
    // Sanity
    if(!IsRedirect()) {
        return false;
    }
    m_writerThread->Write(buff);
    return true;
}
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 16, 2022, 01:57:16 am
<Partial quote>
Hi, Pecan, In the latested r84 and with the change to using the std::string output of the both function writeClientLog() and writeServerLog().

I found an interesting thing that I got two different encoding output of the Chinese text in the comments.
One place is here, in the function: bool ProcessLanguageClient::WriteHdr(const std::string &in)
I see that the output of the content(usually the textDocument/didOpen message's content the client try to send to the LSP server) will be in GB2312 in my PC.
While, the content received from the server(usually the textDocument/hover message return from the LSP server) will be in UTF8 format.

I just exam the function body: bool ProcessLanguageClient::WriteHdr(), I see it still use the some kinds of std::string to wxString, and later some wxString to std::string, some conversion will use the default local encoding.

For example:
Code
limitedLogOut = wxString::Format("<<< Write():\n%s", wxString(in)).Mid(0,512) + "<...DATA SNIPED BY LOG WRITE()...>";

The variable in to wxString will use wrong encoding.

So, what I think is that we should use std::string inside the WriteHdr().
[/code]

Fixed in rev 85. At least I think so. I can't produce an environment that lets me accurately use chinese characters.

When I try to paste copied chinese chars into the editor it automatically converts them to utf8.

Tell me if it actually fixes this.

Thanks for testing and for the fixes.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 16, 2022, 02:06:03 am

I've made a temporary fix (until the next Nightly) that circumvents the missing event.

Be careful though, the circumvention allows clangd to parse files while the "Run" command is active. You might want to right-click on the project name and "Pause parsing(toggle)" before running your program from the menu run command.

After the "Run" finishes, you can "Pause parsing(toggle)" again to continue parsing where it left off.


@pecan

At the moment I'm unable to replicate the bug, so the bug seems fixed.

Is there any inconvenience leaving the parser working while I'm running the application? I mean not considering the CPU usage?

Max

You can set the number of parsers you would like to run while compiling,running,debugging can be set at Settings/Editor/Clangd_client/"C/C++ parser"/Max number of threads while compiling.

But it really eats up the cpu. Set it to about 1/2 the number of processors/threads in your cpu.

Then sit back and feel it warm up the house and enjoy the aroma of melting plastic.

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 16, 2022, 03:25:10 am
<Partial quote>
Hi, Pecan, In the latested r84 and with the change to using the std::string output of the both function writeClientLog() and writeServerLog().

I found an interesting thing that I got two different encoding output of the Chinese text in the comments.
One place is here, in the function: bool ProcessLanguageClient::WriteHdr(const std::string &in)
I see that the output of the content(usually the textDocument/didOpen message's content the client try to send to the LSP server) will be in GB2312 in my PC.
While, the content received from the server(usually the textDocument/hover message return from the LSP server) will be in UTF8 format.

I just exam the function body: bool ProcessLanguageClient::WriteHdr(), I see it still use the some kinds of std::string to wxString, and later some wxString to std::string, some conversion will use the default local encoding.

For example:
Code
limitedLogOut = wxString::Format("<<< Write():\n%s", wxString(in)).Mid(0,512) + "<...DATA SNIPED BY LOG WRITE()...>";

The variable in to wxString will use wrong encoding.

So, what I think is that we should use std::string inside the WriteHdr().
[/code]

Fixed in rev 85. At least I think so. I can't produce an environment that lets me accurately use chinese characters.

When I try to paste copied chinese chars into the editor it automatically converts them to utf8.

Tell me if it actually fixes this.

Thanks for testing and for the fixes.

Hi, Pecan, I just tested this rev 85, and I can confirm that the encoding issue is fixed. In the log file, both the textDocument/didOpen and textDocument/hover messages are showing the same UTF8 encoding now.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 28, 2022, 12:40:23 pm
Hi, Pecan, I try to debug clangd_client, but disable all the other plugins. So I have the patch here:

Re: How to exclude the other plugins when debugging (https://forums.codeblocks.org/index.php/topic,25161.msg171549.html#msg171549)

But when I have only two plugins to load, in the debug-plugin.conf file, I have such content:

Code
	<plugins>
<TRY_TO_ACTIVATE>
<str>
<![CDATA[]]>
</str>
</TRY_TO_ACTIVATE>
<INSTALL_GLOBALLY bool="1" />
<INSTALL_CONFIRMATION bool="1" />
<BATCH_BUILD_PLUGINS>
<astr>
<s>
<![CDATA[compiler.dll]]>
</s>
<s>
<![CDATA[clangd_client.dll]]>
</s>
</astr>
</BATCH_BUILD_PLUGINS>
<CLANGD_CLIENT bool="1" />
</plugins>

This means only those two dlls get loaded.

But when debugging, I see the debugee codeblocks will report that:

Code
[Window Title]
Clangd_client plugin

[Content]
The Clangd client plugin cannot run while the "Code completion" plugin is enabled.
The Clangd client plugin will now inactivate itself. :-(

If you wish to use the Clangd_client rather than the older CodeCompletion plugin,
navigate to Plugins->Manage plugins... and disable CodeCompletion, then enable Clangd_client.

Restart CodeBlocks after closing the "Manage plugins" dialog.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
Only one (Clangd_Client or CodeCompletion) should be enabled.

[OK]


In my plugin management dialog, I have only two plugins, so CodeCompletion plugin is not loaded. I'm not sure why in this case, clangd_client still report the codecompletion is enabled?

Thanks.


EDIT

It looks like the clangd_client has some logic to detect the codecompletion plugin, but the logic is not correct.

Now, I have a workaround, I have change the conf file to have this:

Code
	<plugins>
<TRY_TO_ACTIVATE>
<str>
<![CDATA[]]>
</str>
</TRY_TO_ACTIVATE>
<INSTALL_GLOBALLY bool="1" />
<INSTALL_CONFIRMATION bool="1" />
<BATCH_BUILD_PLUGINS>
<astr>
<s>
<![CDATA[compiler.dll]]>
</s>
<s>
<![CDATA[clangd_client.dll]]>
</s>
<s>
<![CDATA[codecompletion.dll]]>
</s>
</astr>
</BATCH_BUILD_PLUGINS>
<CLANGD_CLIENT bool="1" />
<CODECOMPLETION bool="0" />
</plugins>
Then, I can enable the clangd_client plugin correctly. (the codecompletion plugin should be loaded but disabled)

The situation is: if the codecompletion plugin never get loaded, I have no way to enable the clangd_client plugin.  :(

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on October 28, 2022, 03:25:13 pm
I see another crash caught by GDB.

Code
From b54738b2d2d2eec2eb7185f14f7c0e1f7c75c68f Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Fri, 28 Oct 2022 21:22:01 +0800
Subject: delete the instance first, and later remove it from the list

If first remove from the list, the iterator becomes invalid, remember the pointer before the iterator get destroyed

diff --git a/clangd_client/src/codecompletion/parsemanager.cpp b/clangd_client/src/codecompletion/parsemanager.cpp
index 1590f31..9101ddd 100644
--- a/clangd_client/src/codecompletion/parsemanager.cpp
+++ b/clangd_client/src/codecompletion/parsemanager.cpp
@@ -713,11 +713,12 @@ bool ParseManager::DeleteParser(cbProject* project)
 
         // The logic here is : firstly delete the parser instance, then see whether we need an
         // active parser switch (call SetParser())
-        m_ParserList.erase(parserList_it); //remove deleted parser from parser list
-        delete parserList_it->second;
+        ParserBase* delParser = parserList_it->second;
+        delete parserList_it->second;      // delete the instance first, then remove from the list
+        m_ParserList.erase(parserList_it); // remove deleted parser from parser list
 
         // if the active parser is deleted, set the active parser to nullptr
-        if (parserList_it->second == m_Parser)
+        if (delParser == m_Parser)
         {
             m_Parser = nullptr;
             SetParser(m_TempParser); // Also updates class browser; do not use SetParser(m_TempParser) //(ph 2022/06/6)-


This will fix the crash.


EDIT:

I updated the patch, because I see the iterator get invalid, so we have to member the pointer address for later comparing.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 31, 2022, 07:13:03 pm
Hi, Pecan, I try to debug clangd_client, but disable all the other plugins. So I have the patch here:

Re: How to exclude the other plugins when debugging (https://forums.codeblocks.org/index.php/topic,25161.msg171549.html#msg171549)

But when I have only two plugins to load, in the debug-plugin.conf file,
This means only those two dlls get loaded.

But when debugging, I see the debugee codeblocks will report that:

<...some content snipped by pecan...>

The Clangd client plugin cannot run while the "Code completion"
plugin is enabled.


In my plugin management dialog, I have only two plugins, so CodeCompletion plugin is not loaded. I'm not sure why in this case, clangd_client still report the codecompletion is enabled?

Thanks.


EDIT

It looks like the clangd_client has some logic to detect the codecompletion plugin, but the logic is not correct.

Now, I have a workaround, I have change the conf file to have this:

The situation is: if the codecompletion plugin never get loaded, I have no way to enable the clangd_client plugin.  :(

I've reworked the code that attempts to avoid running clangd_client when CodeCompletion is enabled.

This situation was caused by:
1) CodeCompletion.dll plugin is missing but the .conf say that it's enabled.
2) CodeCompletion is loaded by PluginManager but there's no info about it in the .conf file.

Hope I've solved these situations in clangd_client repo rev 87.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on October 31, 2022, 07:14:32 pm
I see another crash caught by GDB.

Code
From b54738b2d2d2eec2eb7185f14f7c0e1f7c75c68f Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Fri, 28 Oct 2022 21:22:01 +0800
Subject: delete the instance first, and later remove it from the list

If first remove from the list, the iterator becomes invalid, remember the pointer before the iterator get destroyed

diff --git a/clangd_client/src/codecompletion/parsemanager.cpp b/clangd_client/src/codecompletion/parsemanager.cpp
index 1590f31..9101ddd 100644
--- a/clangd_client/src/codecompletion/parsemanager.cpp
+++ b/clangd_client/src/codecompletion/parsemanager.cpp
@@ -713,11 +713,12 @@ bool ParseManager::DeleteParser(cbProject* project)
 
         // The logic here is : firstly delete the parser instance, then see whether we need an
         // active parser switch (call SetParser())
-        m_ParserList.erase(parserList_it); //remove deleted parser from parser list
-        delete parserList_it->second;
+        ParserBase* delParser = parserList_it->second;
+        delete parserList_it->second;      // delete the instance first, then remove from the list
+        m_ParserList.erase(parserList_it); // remove deleted parser from parser list
 
         // if the active parser is deleted, set the active parser to nullptr
-        if (parserList_it->second == m_Parser)
+        if (delParser == m_Parser)
         {
             m_Parser = nullptr;
             SetParser(m_TempParser); // Also updates class browser; do not use SetParser(m_TempParser) //(ph 2022/06/6)-


This will fix the crash.


EDIT:

I updated the patch, because I see the iterator get invalid, so we have to member the pointer address for later comparing.

Fix applied in repo rev 87.
Thanks
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 01, 2022, 08:01:38 am
...
I've reworked the code that attempts to avoid running clangd_client when CodeCompletion is enabled.

This situation was caused by:
1) CodeCompletion.dll plugin is missing but the .conf say that it's enabled.
2) CodeCompletion is loaded by PluginManager but there's no info about it in the .conf file.

Hope I've solved these situations in clangd_client repo rev 87.

I can confirm this issue is fixed, thanks!
Title: Re: Code completion using LSP and clangd
Post by: killerbot on November 01, 2022, 03:40:19 pm
when we activate this new improved way in our nightly builds ?
Is it usable enough (I haven't tried it yet I must admit) to promote to a contrib plug-in ?
I
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 01, 2022, 05:15:21 pm
when we activate this new improved way in our nightly builds ?
Is it usable enough (I haven't tried it yet I must admit) to promote to a contrib plug-in ?
I

I'm comfortable with it now to say that it's ready to be added as a contrib.
I've used it everyday for more than a year.

If/when it become a contrib, it behaves/is guided by the presence of the old CodeCompletion plugin.
1) If CodeCompletion is enabled, Clangd_client disables itself.
2) If CB is a virgin install, and there's no compiler masterpath, Clangd_client disables itself.
3)If CodeCompletion is disabled, Clangd_client can run if the user enables it.
4)If CodeCompletion dll is missing, Clangd_client can run if the user enables it.
5) Otherwise, it remains asleep. waiting for user attention.

All these machinations are done to avoid any conflict with CodeCompletion and to give CodeCompletion priority. It requires the user to specifically take some actions:
1) Disable CodeCompletion and enable Clangd_client.
2) Provide a default compiler.
3) Provide access to a  clang/clangd location (such as llvm or Msys).

I'll provide instructions in the CB wiki regarding it's use and requirements.
Andrew has already provided most of the work for that wiki entry.

But I'd like to hear how other users feel about it becoming a contrib.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 02, 2022, 01:51:15 am
...
...
But I'd like to hear how other users feel about it becoming a contrib.
+1.

I use clangd_client plugin in my daily work for several months, it works quite well.
It gives more accurate code suggestion, code reference, code-refactoring(rename) feature than the old code completion plugin.
I have maintained the old code completion plugin for many years. The C++ language and its grammar is becoming so complex nowadays, so we need a compiler level parser. Currently only clang based tool has this kinds of feature.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 05, 2022, 09:14:41 am
I see a bug that when the source code has TAB as the indent chars, our C::B editor will report the wrong position to clangd.

It looks like clangd just recognize the TAB as a single char, but in our C::B editor, when we get the column position, a TAB may be recognized as "4 space", in this case, when the clangd_client send the request to the LSP server, it send the wrong column position.

Do you see this bug?

To fix this issue, I think we have to adjust the column position we got from the editor. Any ideas?

EDIT:

The GetColumn() function has such document:

Retrieve the column number of a position, taking tab width into account.

EDIT2

In this page, we can get a "char" based column:
get column number Issue #75 jacobslusser/ScintillaNET (https://github.com/jacobslusser/ScintillaNET/issues/75)

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 05, 2022, 10:44:34 am
Other issue is that it looks like the icons are not showing correctly, it looks like the transparent color is shown in black?

See the image shot below:

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 05, 2022, 11:16:17 am
I see a bug that when the source code has TAB as the indent chars, our C::B editor will report the wrong position to clangd.

It looks like clangd just recognize the TAB as a single char, but in our C::B editor, when we get the column position, a TAB may be recognized as "4 space", in this case, when the clangd_client send the request to the LSP server, it send the wrong column position.

Do you see this bug?

To fix this issue, I think we have to adjust the column position we got from the editor. Any ideas?

EDIT:

The GetColumn() function has such document:

Retrieve the column number of a position, taking tab width into account.

EDIT2

In this page, we can get a "char" based column:
get column number Issue #75 jacobslusser/ScintillaNET (https://github.com/jacobslusser/ScintillaNET/issues/75)

This issue can be fixed by this patch:

Code
From 8acd4b5b3bfe74d36583c54c4539dda112c6b1f3 Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Sat, 5 Nov 2022 18:09:48 +0800
Subject: handling the char based column, do not take account the TAB width


diff --git a/clangd_client/src/LSPclient/client.cpp b/clangd_client/src/LSPclient/client.cpp
index 1654e1d..424fd0a 100644
--- a/clangd_client/src/LSPclient/client.cpp
+++ b/clangd_client/src/LSPclient/client.cpp
@@ -2301,7 +2301,10 @@ void ProcessLanguageClient::LSP_GoToDefinition(cbEditor* pcbEd, int argCaretPosi
     //-const int startPosn = pCtrl->WordStartPosition(edCaretPosn, true);
     //-const int endPosn   = pCtrl->WordEndPosition(posn, true); //not needed
     position.line       = edLineNum;
-    position.character  = edColumn;
+
+    int linePos = pCtrl->PositionFromLine(edLineNum); // Retrieve the position at the start of a line.
+    int fauxColumn = edCaretPosn - linePos;
+    position.character  = fauxColumn;
     writeClientLog(StdString_Format("<<< GoToDefinition:\n%s,line[%d], char[%d]", docuri.c_str(), position.line, position.character) );
 
     //Tell LSP server if text has changed
@@ -2386,7 +2389,9 @@ void ProcessLanguageClient::LSP_GoToDeclaration(cbEditor* pcbEd, int argCaretPos
     DocumentUri docuri = DocumentUri(stdFileURI.c_str());
     Position position;
     position.line       = edLineNum;
-    position.character  = edColumn;
+
+    int linePos = pCtrl->PositionFromLine(edLineNum); // Retrieve the position at the start of a line.
+    int fauxColumn = edCaretPosn - linePos;
     writeClientLog(StdString_Format("<<< GoToDeclaration:\n%s,line[%d], char[%d]", docuri.c_str(), position.line, position.character) );
 
     // Tell server if text has changed
@@ -2476,7 +2481,18 @@ void ProcessLanguageClient::LSP_FindReferences(cbEditor* pEd, int argCaretPositi
     //-int startPosn = pCtrl->WordStartPosition(caretPosn, true);
     //-const int endPosn   = pCtrl->WordEndPosition(posn, true); //not needed
     position.line       = edLineNum;
-    position.character  = edColumn;
+
+    // the clangd need char based column, where a TAB equals one char
+    // but GetColumn() function just return the column which retrieves the column number of a position, taking tab width into account.
+    // so we need a hack to get a new fauxColumn
+    // get column number Issue #75 jacobslusser/ScintillaNET - https://github.com/jacobslusser/ScintillaNET/issues/75
+    // var currentPos = scintilla.CurrentPosition;
+    // var currentLine = scintilla.LineFromPosition(currentPos);
+    // var linePos = scintilla.Lines[currentLine].Position;
+    // var fauxColumn = (currentPos - linePos);
+    int linePos = pCtrl->PositionFromLine(edLineNum); // Retrieve the position at the start of a line.
+    int fauxColumn = caretPosn - linePos;
+    position.character  = fauxColumn;
     writeClientLog(StdString_Format("<<< FindReferences:\n%s,line[%d], char[%d]", docuri.c_str(), position.line, position.character) );
 
     // Report changes to server else reported line references will be wrong.


I have one question: when I click the context menu->find reference. I see from the client log, there are also "goto declaration" and "goto definition" messages from the json RPC. Do we really need those extra 2 messages? I see find reference messages already correctly return the positions we needed.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 05, 2022, 09:37:37 pm
Other issue is that it looks like the icons are not showing correctly, it looks like the transparent color is shown in black?

See the image shot below:

How are seeing those icons.
I don't remember displaying them in clangd_client.
Are you sure you're using clangd_client?

I really didn't want to use the icons. But instead use the extra column for useful data.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 06, 2022, 05:46:32 am
Other issue is that it looks like the icons are not showing correctly, it looks like the transparent color is shown in black?

See the image shot below:

How are seeing those icons.
I don't remember displaying them in clangd_client.
Are you sure you're using clangd_client?

I really didn't want to use the icons. But instead use the extra column for useful data.

Hi, I'm sorry, this screen shot is from the code completion plugin, not from the clangd_client plugin.  :(
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 06, 2022, 11:30:05 am
I have some situation that there are many information messages showing: LSP: File not yet parsed.

The step is:

1, double click on a file in the source navigation tree, and a new editor is opened.
2, mouse hover on some symbols in the editor.
3, the information massage happens.

Sometimes, I got this information messages showing many times, I think there is a logic error.

My guess the logic here is: once the editor get opened, the content will be sent to the LSP. But if the parsing is not finished, the hover event will report that the File not parsed yet. But I'm not sure sometimes, it will always popup. I have to close the project, and re-open the project to workaround this issue.

Maybe there are some options which affect this issue. My guess is the option:

Update parser when typing (on save otherwise).
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 06, 2022, 07:42:32 pm

I have one question: when I click the context menu->find reference. I see from the client log, there are also "goto declaration" and "goto definition" messages from the json RPC. Do we really need those extra 2 messages? I see find reference messages already correctly return the positions we needed.

That may be true of the current clangd you're currently using.
But in previous versions (11 & 12),  clangd was returning the wrong reference because it didn't distinguish between a declaration and a definition.
So I asked for both and chose the right one to display.

I'll revisit this some later time and make sure clangd is returning the actual request (definitions vs implementation).
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 06, 2022, 08:04:14 pm
I see a bug that when the source code has TAB as the indent chars, our C::B editor will report the wrong position to clangd.

It looks like clangd just recognize the TAB as a single char, but in our C::B editor, when we get the column position, a TAB may be recognized as "4 space", in this case, when the clangd_client send the request to the LSP server, it send the wrong column position.

Do you see this bug?

To fix this issue, I think we have to adjust the column position we got from the editor. Any ideas?

EDIT:

The GetColumn() function has such document:

Retrieve the column number of a position, taking tab width into account.

EDIT2

In this page, we can get a "char" based column:
get column number Issue #75 jacobslusser/ScintillaNET (https://github.com/jacobslusser/ScintillaNET/issues/75)

This issue can be fixed by this patch:

Code
From 8acd4b5b3bfe74d36583c54c4539dda112c6b1f3 Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Sat, 5 Nov 2022 18:09:48 +0800
Subject: handling the char based column, do not take account the TAB width


diff --git a/clangd_client/src/LSPclient/client.cpp b/clangd_client/src/LSPclient/client.cpp
index 1654e1d..424fd0a 100644
--- a/clangd_client/src/LSPclient/client.cpp
+++ b/clangd_client/src/LSPclient/client.cpp
@@ -2301,7 +2301,10 @@ void ProcessLanguageClient::LSP_GoToDefinition(cbEditor* pcbEd, int argCaretPosi
     //-const int startPosn = pCtrl->WordStartPosition(edCaretPosn, true);
     //-const int endPosn   = pCtrl->WordEndPosition(posn, true); //not needed
     position.line       = edLineNum;
-    position.character  = edColumn;
+
+    int linePos = pCtrl->PositionFromLine(edLineNum); // Retrieve the position at the start of a line.
+    int fauxColumn = edCaretPosn - linePos;
+    position.character  = fauxColumn;
     writeClientLog(StdString_Format("<<< GoToDefinition:\n%s,line[%d], char[%d]", docuri.c_str(), position.line, position.character) );
 
     //Tell LSP server if text has changed
@@ -2386,7 +2389,9 @@ void ProcessLanguageClient::LSP_GoToDeclaration(cbEditor* pcbEd, int argCaretPos
     DocumentUri docuri = DocumentUri(stdFileURI.c_str());
     Position position;
     position.line       = edLineNum;
-    position.character  = edColumn;
+
+    int linePos = pCtrl->PositionFromLine(edLineNum); // Retrieve the position at the start of a line.
+    int fauxColumn = edCaretPosn - linePos;
     writeClientLog(StdString_Format("<<< GoToDeclaration:\n%s,line[%d], char[%d]", docuri.c_str(), position.line, position.character) );
 
     // Tell server if text has changed
@@ -2476,7 +2481,18 @@ void ProcessLanguageClient::LSP_FindReferences(cbEditor* pEd, int argCaretPositi
     //-int startPosn = pCtrl->WordStartPosition(caretPosn, true);
     //-const int endPosn   = pCtrl->WordEndPosition(posn, true); //not needed
     position.line       = edLineNum;
-    position.character  = edColumn;
+
+    // the clangd need char based column, where a TAB equals one char
+    // but GetColumn() function just return the column which retrieves the column number of a position, taking tab width into account.
+    // so we need a hack to get a new fauxColumn
+    // get column number Issue #75 jacobslusser/ScintillaNET - https://github.com/jacobslusser/ScintillaNET/issues/75
+    // var currentPos = scintilla.CurrentPosition;
+    // var currentLine = scintilla.LineFromPosition(currentPos);
+    // var linePos = scintilla.Lines[currentLine].Position;
+    // var fauxColumn = (currentPos - linePos);
+    int linePos = pCtrl->PositionFromLine(edLineNum); // Retrieve the position at the start of a line.
+    int fauxColumn = caretPosn - linePos;
+    position.character  = fauxColumn;
     writeClientLog(StdString_Format("<<< FindReferences:\n%s,line[%d], char[%d]", docuri.c_str(), position.line, position.character) );
 
     // Report changes to server else reported line references will be wrong.


I don't understand your patch.
The fix according to the jacob slusser quote is to use GetColumn().
But your patch uses fauxColumn instead.

Jacobslusser quote:
Code
jacobslusser commented on Jul 12, 2015
TL;DR
The GetColumn method.

That's an interesting question when you think about it... We could use the CurrentPosition property to get the position of the caret within the document; use that with LineFromPosition to get the line index; get the line start position from Line.Position and then finally subtract that from the original caret position to get the "column":

var currentPos = scintilla.CurrentPosition;
var currentLine = scintilla.LineFromPosition(currentPos);
var linePos = scintilla.Lines[currentLine].Position;
var fauxColumn = (currentPos - linePos);
This wouldn't be the "column" though (hence my fauxColumn variable name). Why? Because it doesn't account for tab characters which can occupy 4, 8, or any other amount of spaces. Usually when someone says they want the "column", they want the line space as it would show on a ruler, which is not necessarily the number of characters. To get a column position--while also taking into account the tab size--use the GetColumn method:

var column = scintilla.GetColumn(scintilla.CurrentPosition);
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 06, 2022, 08:48:48 pm
I have some situation that there are many information messages showing: LSP: File not yet parsed.

The step is:

1, double click on a file in the source navigation tree, and a new editor is opened.
2, mouse hover on some symbols in the editor.
3, the information massage happens.

Sometimes, I got this information messages showing many times, I think there is a logic error.

My guess the logic here is: once the editor get opened, the content will be sent to the LSP. But if the parsing is not finished, the hover event will report that the File not parsed yet. But I'm not sure sometimes, it will always popup. I have to close the project, and re-open the project to workaround this issue.

Maybe there are some options which affect this issue. My guess is the option:

Update parser when typing (on save otherwise).

I can't re-create the error after many tries, but I think I've experienced this.
So I'll have to insert some code to try and catch it.
I'll enter this as a ticket @clangd_client repo so it doesn't get lost.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 06, 2022, 09:13:59 pm
@ollydbg
RE: #244 Tab character.

Would you provide me with an example text files with Tabs that create this situation. I'd like to debug trace through the code.
Also what is your editor setting for tabs?

Thanks

Edit:
Never mind. I finally figured it out by adding both fixes and keeping the one that works. Namey ollydbgs fix.

"var column = scintilla.GetColumn(scintilla.CurrentPosition);"
does not fix the problem. It causes the same problem when tabs are in the source line.
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 07, 2022, 02:09:09 am
@ollydbg
RE: #244 Tab character.

Would you provide me with an example text files with Tabs that create this situation. I'd like to debug trace through the code.
Also what is your editor setting for tabs?

Thanks

Edit:
Never mind. I finally figured it out by adding both fixes and keeping the one that works. Namey ollydbgs fix.

"var column = scintilla.GetColumn(scintilla.CurrentPosition);"
does not fix the problem. It causes the same problem when tabs are in the source line.
It's good that you can reproduce it.
I just prepared the test code, it is very simple:

Code
int main()
{
int abc = 0;
int xyz = abc + abc;
return 0;
}

And all use "tab" as indent.

Here is the screen shot.
Find declaration shows nothing, see the information message.
Find reference shows only one line, see the list view, it should show 2 lines.

Here is the screen shot:
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 08, 2022, 07:30:09 am
It's good that you can reproduce it.
I just prepared the test code, it is very simple:

Code
int main()
{
int abc = 0;
int xyz = abc + abc;
return 0;
}

And all use "tab" as indent.

Here is the screen shot.
Find declaration shows nothing, see the information message.
Find reference shows only one line, see the list view, it should show 2 lines.

Here is the screen shot:

@ollydbg
RE: #244 Tab character.

Tab char column determination fixed in Clangd_client rev 88.
Give it a try.
Thanks for the fix.

https://sourceforge.net/p/cb-clangd-client/code/88/
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 08, 2022, 10:32:13 pm
I'm trying to update clangd_client as a contrib.
On Linux after I run:
Code
cd trunk
./bootstrap
./configure
make

How do I know if it worked or not.
I don't see any make output even though it looks like it ran without errors.
Am I supposed to have .o files or something?

Edit 13:45
I see there was produced the following:
Code
pecan@Zbook17:~/proj/cbHeadM4/trunk$ find . -name ".libs"
./src/src/.libs
./src/sdk/mozilla_chardet/src/.libs
./src/sdk/wxscintilla/src/scintilla/src/.libs
./src/sdk/wxscintilla/src/scintilla/lexlib/.libs
./src/sdk/wxscintilla/src/scintilla/lexers/.libs
./src/sdk/wxscintilla/src/.libs
./src/sdk/wxscintilla/.libs
./src/sdk/scripting/sqstdlib/.libs
./src/sdk/scripting/squirrel/.libs
./src/sdk/scripting/bindings/.libs
./src/sdk/.libs
./src/build_tools/autorevision/.libs
./src/plugins/codecompletion/.libs
./src/plugins/codecompletion/parser/.libs
./src/plugins/astyle/astyle/.libs
./src/plugins/astyle/.libs
./src/plugins/scriptedwizard/.libs
./src/plugins/compilergcc/.libs
./src/plugins/compilergcc/depslib/src/.libs
./src/plugins/todo/.libs
./src/plugins/defaultmimehandler/.libs
./src/plugins/debuggergdb/.libs
./src/plugins/projectsimporter/.libs
./src/plugins/openfileslist/.libs
./src/plugins/classwizard/.libs
./src/plugins/occurrenceshighlighting/.libs
./src/plugins/abbreviations/.libs
./src/plugins/autosave/.libs
./src/base/tinyxml/.libs
./src/tools/cb_share_config/.libs
./src/tools/ConsoleRunner/.libs

But nothing for any contribs. Is this normal?
If so, how do I produce .libs for the contribs (just to see if I'm on the right track)?

Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 09, 2022, 02:49:06 am
......

@ollydbg
RE: #244 Tab character.

Tab char column determination fixed in Clangd_client rev 88.
Give it a try.
Thanks for the fix.

https://sourceforge.net/p/cb-clangd-client/code/88/

Hi, thanks for the fix, I just test the rev88, and it works quite well. I see you have extra fixes in the "rename" event handling.

When editing the "#include <" or other statement, I see an annoying messagebox, I just translate the messagebox to log:

Code
From 96e57a13033c2f67e45813ad423e2d6c077488bb Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Sat, 5 Nov 2022 18:10:33 +0800
Subject: change the annoying messagebox to log


diff --git a/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp b/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp
index 65c2c5a..a2868de 100644
--- a/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp
+++ b/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp
@@ -2198,7 +2198,9 @@ Token* LSP_SymbolsParser::DoHandleClass(EClassType ct, int lineNumber, int lastL
             newToken->m_IsAnonymous = true;
             #if defined(cbDEBUG)
                 wxString msg((wxString::Format("Trying to DoParse recursion in %s():%d", __FUNCTION__, __LINE__)));
-                cbMessageBox(msg, "Assert(non fatal)");
+                CCLogger::Get()->DebugLog(msg);
+                wxString str = wxString::Format("m_Buffer = %s, next = %s", m_Buffer, next);
+                //cbMessageBox(msg, "Assert(non fatal)");
             #endif
             break; //(ph 2021/10/13)
             /// DoParse(); // recursion


BTW: I really do not know why this happens, do you want to parse a single line using the hand written parser ourselves?



Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 09, 2022, 06:36:27 pm
...

When editing the "#include <" or other statement, I see an annoying messagebox, I just translate the messagebox to log:
Code
From 96e57a13033c2f67e45813ad423e2d6c077488bb Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Sat, 5 Nov 2022 18:10:33 +0800
Subject: change the annoying messagebox to log


diff --git a/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp b/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp
index 65c2c5a..a2868de 100644
--- a/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp
+++ b/clangd_client/src/codecompletion/parser/LSP_symbolsparser.cpp
@@ -2198,7 +2198,9 @@ Token* LSP_SymbolsParser::DoHandleClass(EClassType ct, int lineNumber, int lastL
             newToken->m_IsAnonymous = true;
             #if defined(cbDEBUG)
                 wxString msg((wxString::Format("Trying to DoParse recursion in %s():%d", __FUNCTION__, __LINE__)));
-                cbMessageBox(msg, "Assert(non fatal)");
+                CCLogger::Get()->DebugLog(msg);
+                wxString str = wxString::Format("m_Buffer = %s, next = %s", m_Buffer, next);
+                //cbMessageBox(msg, "Assert(non fatal)");
             #endif
             break; //(ph 2021/10/13)
             /// DoParse(); // recursion


BTW: I really do not know why this happens, do you want to parse a single line using the hand written parser ourselves?

I'll make that annoying cbMessageBox into a log msg instead.
Code
#if defined(cbDEBUG)
                // FIXME (ph#): Find out why this happens when trying to find a class ancestor.
                wxString msg((wxString::Format("Trying to DoParse recursion in %s():%d", __FUNCTION__, __LINE__)));
                //-cbMessageBox(msg, "Assert(non fatal)");
                CCLogger::Get()->DebugLog(msg);
            #endif
            break; //(ph 2021/10/13)
            /// DoParse(); // recursion

The code is trying to parse out the ancestor of a class to add to the symbols tree. Clangd has no protocol msg to achieve that, so I was trying to use the old CodeCompletion code to parse it from the source line.

Do you have any steps you can give me to re-create the situation.

Thanks
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 11, 2022, 11:48:02 pm
If There are no objections, I'd like to commit Clangd_client as a contrib.

It runs fine on both Windows and Linux.
And I believe Andrew has it working on Mac.

Thanks

Title: Re: Code completion using LSP and clangd
Post by: gd_on on November 14, 2022, 02:04:13 pm
Cool.
I see that clangd_client plugin is now included in contrib plugins.
Three details :

gd_on
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on November 14, 2022, 02:30:42 pm
Conversely, clangd_client_wx32.cbp is missing although CodeBlocks_wx32.workspace includes it (ticket #1327).
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on November 14, 2022, 04:16:26 pm
File clangd_client_wx31.cbp has this linker option:
Code
<Add option="-m64" />
but it is a 32-bit project.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 14, 2022, 06:08:10 pm
Cool.
I see that clangd_client plugin is now included in contrib plugins.
Three details :
  • within contrib, it's version 87 though on your svn site it's version 88;
  • CodeBlocks_wx32_64.workspace has not been updated to include the clangd_client but all other workspaces are OK;
  • the documentation-install folder is not there.

gd_on

I don't know how to control that header version number, but the code for rev 88 is included with the contrib commit.

CodeBlocks_wx32_64.workspace corrected; Thanks.

The documentation-install folder was left out on purpose and will be included in the CB wiki for Clangd_client so we can just refer to the wiki url to answer questions. A new section will be added for just "using" the plugin vs "compiling from source.

Thanks
Title: Re: Code completion using LSP and clangd
Post by: gd_on on November 14, 2022, 06:49:53 pm
OK.
Nevertheless I see at least four differences :
- in version.h, probably not very important (svn version number)
- in manifest.xml, here too not very important (svn version number)
- in codecompletion.cpp, here too not very important (revision number in the headers)
- in LSP_symbolsparser.cpp, small differences near line 2200. I don't know if it's important
There are other differences but only in $HeadURL lines, so no problems.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 14, 2022, 06:57:11 pm
File clangd_client_wx31.cbp has this linker option:
Code
<Add option="-m64" />
but it is a 32-bit project.
Fixed rev 13031. Thanks
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 14, 2022, 06:58:10 pm
Conversely, clangd_client_wx32.cbp is missing although CodeBlocks_wx32.workspace includes it (ticket #1327).
Fixed rev 13031. Thanks
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on November 14, 2022, 07:12:12 pm
Thank you for the fix. The new clangd_client_wx32.cbp has some issues:

<Add option="-m64" /> and <Add option="-D_WIN64" /> in compiler options.

References to devel32_64 and .objs32_64

Global variables use #WX32_64
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on November 14, 2022, 07:46:55 pm
[r12032] fixed most issues, but this compiler options are still invalid for a 32-bit project.
Code
<Add option="-m64" />
<Add option="-D_WIN64" />
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 14, 2022, 09:08:37 pm
[r12032] fixed most issues, but this compiler options are still invalid for a 32-bit project.
Code
<Add option="-m64" />
<Add option="-D_WIN64" />

Thanks, fixed in rev 13033
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on November 15, 2022, 12:09:48 pm
*.depend and *.layout files should be added to svn:ignore

The MSW project creates a clangd_client.zip file in the project folder; If this is OK, it should be added also to svn:ignore

The unix_30 project creates .obj30 and devel30 under the project folder, is this OK?.
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 15, 2022, 07:16:00 pm
*.depend and *.layout files should be added to svn:ignore

The MSW project creates a clangd_client.zip file in the project folder; If this is OK, it should be added also to svn:ignore

The unix_30 project creates .obj30 and devel30 under the project folder, is this OK?.

Fixed in commit CB rev 13035
.depend was already in the ignore list.
Added .layout to ignore list.
Added clangd_client.zip to the ignore list
Made corrections to clangd_client_wx30.cbp

Thanks
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on November 16, 2022, 11:45:10 am
The .depend is still "active", after compiling the plugin:
Code
c:\Codeblocks>svn status
X       src\plugins\contrib\FortranProject
X       src\plugins\contrib\PythonPlugins
?       src\plugins\contrib\clangd_client\clangd_client_wx32.depend

c:\Codeblocks\src\plugins\contrib\clangd_client>svn proplist -v
Properties on '.':
  svn:ignore
    *.layout
    clangd_client.zip
so *.depends is missing. Other folders (p.e. src/src) add also *_build_log.html, because saving build log to HTML leaves this files around.

IMHO the ignore list should be:
Code
Properties on '.':
  svn:ignore
    *.depend
    *.layout
    *_build_log.html
    clangd_client.zip
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 16, 2022, 09:37:36 pm
The .depend is still "active", after compiling the plugin:
Code
c:\Codeblocks>svn status
X       src\plugins\contrib\FortranProject
X       src\plugins\contrib\PythonPlugins
?       src\plugins\contrib\clangd_client\clangd_client_wx32.depend

c:\Codeblocks\src\plugins\contrib\clangd_client>svn proplist -v
Properties on '.':
  svn:ignore
    *.layout
    clangd_client.zip
so *.depends is missing. Other folders (p.e. src/src) add also *_build_log.html, because saving build log to HTML leaves this files around.

IMHO the ignore list should be:
Code
Properties on '.':
  svn:ignore
    *.depend
    *.layout
    *_build_log.html
    clangd_client.zip

Please go ahead and change them as you see fit.
I've read "svn propset -h" three times now, and I still can't figure out how to set ignores.
Title: Re: Code completion using LSP and clangd
Post by: Miguel Gimenez on November 17, 2022, 07:46:57 am
Quote
Please go ahead and change them as you see fit.
Done. Just go to the plugin directory and write:
Code
svn propedit svn:ignore .
Title: Re: Code completion using LSP and clangd
Post by: Pecan on November 17, 2022, 10:14:53 pm
Quote
Please go ahead and change them as you see fit.
Done. Just go to the plugin directory and write:
Code
svn propedit svn:ignore .

The result of this is:
Code
F:\usr\Proj\cbHead\trunk\src\plugins>svn propedit svn:ignore .
svn: E205007: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found
It wants me to set some editor like:
Code
set SVN_EDITOR=notepad.exe

Then, running the svn command brings up notepad with the svn:ignore file settings.

I suppose I'm suppose to save it. But who knows....

[rant]Some day I hope to trash svn. It trades intuitiveness for utter confusion plus hours and hours to try and understand it.
[/rant]
Title: Re: Code completion using LSP and clangd
Post by: ollydbg on November 18, 2022, 05:10:46 am
....

The code is trying to parse out the ancestor of a class to add to the symbols tree. Clangd has no protocol msg to achieve that, so I was trying to use the old CodeCompletion code to parse it from the source line.

Do you have any steps you can give me to re-create the situation.

Thanks

Code
/// comment

class A
{
    int m_X;
    int m_Y;
};

To reproduce this issue, you can

first put the caret after the line "/// comment", and just continuously hit the Enter key several times.
Title: Re: Code completion using LSP and clangd
Post by: sodev on November 18, 2022, 06:38:08 pm
@Pecan

You are using Windows, you simply don't use cli tools on Windows :P. Install https://tortoisesvn.net/ (https://tortoisesvn.net/) for your SVN needs.