I installed clangd for MS VS Code and everything works fine. I wonder how can I manually request clangd via language server protocol? Or is there capability to programmatically include ClangdServer in my code, then add the header for requesting the structure of the code? Thank you.
It’s not clear to me what you’re asking here.
If you’re using clangd via vscode, then you don’t interact directly with clangd, only through the actions supported by vscode.
You could, I suppose, start clangd outside of vscode (in a terminal), and type in a JSON-formatted LSP request via standard input (to which it would return a JSON-formatted response via standard output). Is this what you mean by “manual”? (It doesn’t seem like a very useful mode of operation.)
Including components of clangd is something you would generally only do if you’re extending clangd, or writing your own tool that builds on clangd.
If you describe what you’re trying to do in more detail, I may be able to make a more helpful suggestion.
Yes, this is what I meant. As I know, first clangD loads the header files then analyzes the source code. How can we load the header files in terminal?
And is there anyway to request via network instead of interaction with terminal?
I would like to take advantage of analysis result into my work. I do analyze the source code, but I worry that I do it not fully.
Thank you very much for your answer!
If you’re analyzing a file that
#includes header files, you don’t need to load the header files separately. Clangd will follow the includes as part of parsing the file.
Clangd does need information about the project’s include paths to resolve the includes. This is usually done using
compile_commands.json (see the “Project setup” section of this page).
If you’re just looking to script the interaction, you can certainly do that, using whichever scripting language you prefer. Here is a tool written in Python that can be used to test interactions with language servers, including clangd (see the
If by “via network” you mean that clangd is running on a remote machine, then I’m not sure. You may need to handle the network communication yourself.
Thank you for your answer!