flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

Improve vscode clangd experience

Open dogtopus opened this issue 1 year ago • 3 comments

What's new

  • Resolve and use absolute path for the toolchain. This allows clangd to use compile_commands.json file without running under fbtenv, simplifies setup for vscode clangd extension (AFAIK clangd solely relies on PATH to look for the compiler drivers instead of having a way to specify the location like cpptools. There seems to be an option to specify a compiler override but it seems to be related to compile_flags.txt only and doesn't work for this use case). As a side effect, a rebuild is needed to update compile_commands.json after moving the source tree but it shouldn't cause much trouble in practice.
  • Add the recommended default settings of the extension to settings.json.

Verification

  • (If have ms-vscode.cpptools) Disable ms-vscode.cpptools.
  • Install llvm-vs-code-extensions.vscode-clangd.
  • Run ./fbt and ./fbt vscode_dist LANG_SERVER=clangd, then open the project in vscode.
  • Navigate to furi/flipper.c and other files.
  • Everything should be correctly indexed including the libc headers.

Checklist (For Reviewer)

  • [ ] PR has description of feature/bug or link to Confluence/Jira task
  • [ ] Description contains actions to verify feature/bugfix
  • [ ] I've built this code, uploaded it to the device and verified feature/bugfix

dogtopus avatar Feb 26 '23 03:02 dogtopus

Please fix all issues and un-draft

skotopes avatar Mar 15 '23 14:03 skotopes

OK, I'll have a second look at this.

What are the benefits of using clangd over cpptools?

hedger avatar Mar 25 '23 23:03 hedger

What are the benefits of using clangd over cpptools?

It's less about technical benefits and more about giving more choices to the developers, since cpptools is proprietary and doesn't ship with most third-party/FOSS vscode distributions. Meanwhile clangd is on openvsx and therefore is pretty much available everywhere.

That's why I mentioned that we should keep cpptools as the default and offer clangd as an option instead of flat out replacing cpptools.

(Actually there's one: clangd ships with the full capability of clang-tidy so just saving the file would automatically format it to spec.)

dogtopus avatar Mar 26 '23 16:03 dogtopus