8.4 LSP demo
In this brief LSP demo, we will demonstrate how Clangd opens a file and finds a symbol’s definition. Clangd features a comprehensive logging subsystem that offers valuable insights into its interaction with the IDE. We will use the log subsystem to obtain the necessary information.
8.4.1 Demo description
In our example, we open a test file as shown in the following screenshot and retrieve the definition of the doPrivateWork
token:
Figure 8.6: Go-to definition and hover for the doPrivateWork
token
VS Code communicates with Clangd via standard input/output, and we will use Clangd logs to capture the interaction.
This can be achieved by setting up a wrapper shell script instead of using the actual clangd binary in the VS Code settings:
Figure 8.7: Wrapper shell script setup in VS Code
We can use the following script, clangd.sh
:
1 #!/bin/sh 2 $HOME/clangbook/llvm-project/install/bin/clangd -log verbose -pretty 2> /tmp/clangd...