Reader small image

You're reading from  Clang Compiler Frontend

Product typeBook
Published inMar 2024
PublisherPackt
ISBN-139781837630981
Edition1st Edition
Right arrow
Author (1)
Ivan Murashko
Ivan Murashko
author image
Ivan Murashko

Ivan V. Murashko is a C++ software engineer: He got his PhD from Peter the Great St.Petersburg Polytechnic University and has over 20 years of C++ programming experience; since 2020 he has worked with LLVM compilers. His area of interest includes clang compiler frontend and clang tools (clang-tidy, clangd).
Read more about Ivan Murashko

Right arrow

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

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

Figure 8.7: Wrapper shell script setup in VS Code

We can use the following script, clangd.sh :

#!/bin/sh 
 
$HOME/clangbook/llvm-project/install/bin/clangd -log verbose -pretty 2> /tmp/clangd...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Clang Compiler Frontend
Published in: Mar 2024Publisher: PacktISBN-13: 9781837630981

Author (1)

author image
Ivan Murashko

Ivan V. Murashko is a C++ software engineer: He got his PhD from Peter the Great St.Petersburg Polytechnic University and has over 20 years of C++ programming experience; since 2020 he has worked with LLVM compilers. His area of interest includes clang compiler frontend and clang tools (clang-tidy, clangd).
Read more about Ivan Murashko