Jump to navigation Jump to search
The SDK includes a build of the clangd language server. This allows semantic features of code editors and IDEs that support the Language Server Protocol to work with the SDK.
The specifics of setting up clangd depend on one's choice of editor and build system. There are three general rules, though:
- Make sure that your build system is generating a
compile_commands.jsonfile. Look for this in your build or output directory.
- Make sure that the editor is pointed at the clangd binary included with the SDK, not a system one. The clang included with the SDK supports language extensions that aren't in upstream clang, which can confuse upstream clangd.
- Set your editor so that the argument
--query-driver=/path/to/llvm-mos-sdk/bin/*clang*is passed to clangd. This authorizes clangd to query the SDK clang about what path a specific SDK target uses. Without this, clangd won't have any idea where to look for target headers.
CMake + Visual Studio Code[edit | edit source]
To set up clangd when building using CMake and editing with Visual Studio Code:
- Make sure that you've installed the Clangd extension in the Visual Studio Code marketplace. You should also disable the default C++ extension, since it conflicts with clangd.
-DCMAKE_EXPORT_COMPILE_COMMANDS=ONto CMake when generating the build files. This ensures that a build produces a
compile_commands.jsonfile. Note that this only works with the Makefile and Ninja generators.
- Build the project.
- In Visual Studio Code, open your project, then go to the Settings page. Click the "Workspace" tab and search for "Clangd."
- In the setting titled "Clangd: Arguments", add the argument
--query-driver=/path/to/llvm-mos-sdk/bin/*clang*, substituting the absolute path to your SDK installation for
- Set "Clangd: Path" to
/path/to/llvm-mos-sdk/bin/clangd, again substituting your install path.
- Issue the command "clangd: Restart language server". Clangd integration should now work; you can test this by clicking "Go To Definition" on a
#includeline. This should take you to the corresponding header in your SDK install.