FRR development and Visual Studio Code #12398
rzalamena
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Visual Studio Code is a popular code editor (Stack Overflow Developer Survey) that I have been trying recently and I noticed that it doesn't work out-of-the-box for FRR development. Since I never saw people commenting about it I decided to document the problems I found in case anyone else wants to use the editor at its best capacity.
You need the C/C++ extension in order to get code linting/completion. It will be suggested to you when you open a C.
For the linter/completion to work in a project with autotools (and without CMake or visual studio project file) we'll need to generate a
compile_commands.json
file. This step is necessary because otherwise the C/C++ extension won't be able to figure out the include paths and the compilation dependencies (like the flag-DHAVE_CONFIG_H
).To generate a
compile_commands.json
file there are several tools available, but I'll focus in the one I use:bear
. In an Ubuntu system you can grab it with the command:Before using
bear
we need to configure our FRR sources with the parameters we want. If you are unfamiliar with the FRR build procedure please read the build manual.Here are the steps I use for generating the
compile_commands.json
file:Visual Studio code will ask about using it next time you open a C file. You may also open the project configuration and manually specify it in the
compileCommands
settings. Example:Visual Studio Code will still complain about some errors in files that compile cleanly. This is due some compiler extensions that FRR uses and the editor doesn't know about. To get the linter/completion to work in these files you will need to address these errors either by fixing them (preferably) or, if not possible, by ignoring them.
I've fixed some of the most annoying errors in this PR: lib: handle visual studio code C/C++ extension #12397.
Happy coding
Beta Was this translation helpful? Give feedback.
All reactions