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

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2398
Re: Code completion using LSP and clangd
« Reply #15 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.

Offline AndrewCot

  • Lives here!
  • ****
  • Posts: 502
Re: Code completion using LSP and clangd
« Reply #16 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

Offline AndrewCot

  • Lives here!
  • ****
  • Posts: 502
Re: Code completion using LSP and clangd
« Reply #17 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

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2398
Re: Code completion using LSP and clangd
« Reply #18 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".

« Last Edit: January 09, 2022, 05:51:29 pm by Pecan »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5342
Re: Code completion using LSP and clangd
« Reply #19 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.

Offline sodev

  • Regular
  • ***
  • Posts: 457
Re: Code completion using LSP and clangd
« Reply #20 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.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3189
Re: Code completion using LSP and clangd
« Reply #21 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 :)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2398
Re: Code completion using LSP and clangd
« Reply #22 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.
« Last Edit: January 11, 2022, 03:25:04 pm by Pecan »

Offline AndrewCot

  • Lives here!
  • ****
  • Posts: 502
Re: Code completion using LSP and clangd
« Reply #23 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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5524
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #24 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:



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline AndrewCot

  • Lives here!
  • ****
  • Posts: 502
Re: Code completion using LSP and clangd
« Reply #25 on: January 12, 2022, 12:20:11 pm »
File in SVN has been updated, so the next update will include the typo fixed.


Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5524
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion using LSP and clangd
« Reply #26 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, 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?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1029
Re: Code completion using LSP and clangd
« Reply #27 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.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1029
Re: Code completion using LSP and clangd
« Reply #28 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

It is a draft based on the source code, if somebody has more information or spots an error please edit it.
« Last Edit: January 12, 2022, 06:27:58 pm by Miguel Gimenez »

Offline AndrewCot

  • Lives here!
  • ****
  • Posts: 502
Re: Code completion using LSP and clangd
« Reply #29 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.
« Last Edit: January 13, 2022, 08:19:29 am by AndrewCot »