Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Better support for clangd extenstion out of the box (VSC-1527) #1352

Open
mmrein opened this issue Nov 27, 2024 · 9 comments
Labels
Feature / Enhancement Request Request for Feature/ Enhancement

Comments

@mmrein
Copy link

mmrein commented Nov 27, 2024

Is your feature request related to a problem? Please describe.

  1. clangd extension does not recognize correct system headers

    • Temporary workaround is to add Arguments for clangd server with path to xtensa compiler, for example: --query-driver=/home/user/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.
    • This command has to be changed manually every time target or IDF version changes
  2. clangd extension only works correctly with clangd path set to espressif one

    • For example: /home/user/.espressif/tools/esp-clang/esp-18.1.2_20240912/esp-clang/bin/clangd
    • This path has to be changed manually every time IDF version changes

Describe the solution you'd like

I would prefer to use clangd for code navigation over MS C/C++ extension. Main reason being that it supports Inactive code block background highlight. AFAIK this is at this point the only IDE option for Espressif devices that supports this feature.

As new user of ESP-IDF in VSCode and clang in general, it took me far too much time to find at least those workarounds so I could work on my project in a way I was used to.

There is c_cpp_properties.json file for MS C/C++ extension - I would expect something simillar could be done for clangd support too?

Describe alternatives you've considered

  • MS C/C++ extension highlights just the text background, not whole block
  • Eclipse based Espressif IDE currently only colours inactive code as comment. It used to have this feature, but recently had to update to LSP based editor, which has very limited functionality and configuration options.
@mmrein mmrein added the Feature / Enhancement Request Request for Feature/ Enhancement label Nov 27, 2024
@github-actions github-actions bot changed the title [Feature Request]: Better support for clangd extenstion out of the box [Feature Request]: Better support for clangd extenstion out of the box (VSC-1527) Nov 27, 2024
@brianignacio5
Copy link
Collaborator

You can:

  1. Configure Microsoft C/C++ extension to use Clang as described here: https://code.visualstudio.com/docs/cpp/config-clang-mac

  2. Use the clang vscode extension: https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd

Then when you build your project, a compile_commands.json is generated which can be used for these extensions as described in https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/configureproject.html#c-and-c-code-navigation-and-syntax-highlight

@mmrein
Copy link
Author

mmrein commented Dec 2, 2024

  1. Using MS C/C++ together with clangd extension results in following warning:
You have both the Microsoft C++ (cpptools) extension and clangd extension enabled. 
The Microsoft IntelliSense features conflict with clangd's code completion, diagnostics etc.
  1. Using clangd extension without configuring it as in described workarounds (or maybe some better way) results in clangd errors as it can not find correct xtensa system libraries.

Providing clangd extension with --compile-commands-dir=/path/to/compile_commands.json argument results in different set of errors ("Too many errors emitted").

This is using existing project that builds without errors in terminal. After opening project folder in vscode I Add .vscode subdirectory files with Espressif extension, select IDF version and build. Also, Ubuntu 20.04 if that matters.

@brianignacio5
Copy link
Collaborator

The idea is to use one or the other not both extension at the same time.

Also need to pass compile_commands.json to the extension to resolve such errors

@mmrein
Copy link
Author

mmrein commented Dec 5, 2024

Also need to pass compile_commands.json to the extension to resolve such errors

Ok so the question is why this results in errors:

Providing clangd extension with --compile-commands-dir=/path/to/compile_commands.json argument results in different set of errors ("Too many errors emitted").

I've got "Too many errors emitted" on one bigger project and "stdio.h not found" on another, very simple project.

Edit: judging by the Eclipse plugin all three should be set: clangd path, --query-driver and --compile-commands-dir. Yet this still results in errors.

@brianignacio5
Copy link
Collaborator

The Clangd vscode extension will search for compile_commands.json in the <current-project-directory>/build/compile_commands.json. If you a custom build directory it might not find it. This also means you have to build first or run the ESP-IDF: Run idf.py reconfigure task command.

Besides these tasks I'm not sure why the project is not picking up. Initially when you install the clang extension you need to download the clangd server in order for the extension to work. Since it is a third party extension we don't maintain it, but we can help if you can share an example project to reproduce your issue.

@mmrein
Copy link
Author

mmrein commented Dec 6, 2024

So that is strange. I did initially install clangd server as recommended by extension, but later tried with clangd from IDF and results seemed better at first. But I tried swapping multiple times too.

At this point even the workarounds not work anymore and any project is showing errors. It still builds and runs on HW without issues.

I can share this for example: cert_test.zip I've packed it including build folder so you can see build logs too, just removed esp-idf subfolder to reduce size.

@nidefawl
Copy link

Clangd still emits errors with this workaround.
Most code navigation and refactoring works.

I installed clangd with:
idf_tools.py install esp-clang
and added following to .vscode/settings.json

  "clangd.path": "/home/user/esp-dev/esp32/tools/esp-clang/16.0.1-fe4f10a809/esp-clang/bin/clangd",
  "clangd.arguments": ["--query-driver=/home/user/esp-dev/esp32/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc"],

Copy link

github-actions bot commented Jan 4, 2025

This issue has been marked as stale since there are no activities, and this will be closed in 5 days if there are no further activities

@github-actions github-actions bot added the stale Stale PR or Issue label Jan 4, 2025
@mmrein
Copy link
Author

mmrein commented Jan 6, 2025

This issue has been marked as stale since there are no activities, and this will be closed in 5 days if there are no further activities

Issue still present

@brianignacio5 brianignacio5 removed the stale Stale PR or Issue label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature / Enhancement Request Request for Feature/ Enhancement
Projects
None yet
Development

No branches or pull requests

3 participants