flipperzero-firmware
flipperzero-firmware copied to clipboard
Improve vscode clangd experience
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 tocompile_flags.txt
only and doesn't work for this use case). As a side effect, a rebuild is needed to updatecompile_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
) Disablems-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
Please fix all issues and un-draft
OK, I'll have a second look at this.
What are the benefits of using clangd over cpptools?
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.)