iTranslated by AI
Setting up LSP for Autoware
The Motivation
Due to various reasons, I need to study autonomous driving, so I've started learning about TIER IV's Autoware. Recently, however, I've become dependent on AI to read code I'm unfamiliar with:
Because of this, setting up LSP became necessary even just to read the Autoware codebase. However, the only article I could find on Autoware LSP configuration was:
And even when I set up LSP using the command provided there:
colcon build --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=1
I often ran into issues where compile_commands.json wasn't working correctly. So, I am documenting the method for setting up LSP in Autoware for those who may want to read Autoware code using LSP in the future.
What is Autoware?
Autoware is one of the world's largest open-source software (OSS) projects for autonomous driving, led by the Autoware Foundation. It originated in Japan and is positioned as a practical autonomous driving stack intended for everything from research purposes to real-vehicle and commercial operations.
In short, it is a modular (partitioned design) autonomous driving software stack based on ROS 2. Its main features are:
- Clearly separated processes from sensor input to vehicle control
- Emphasis on practical operation, safety, and accountability
- Pipeline/Modular design rather than End-to-End
Why is LSP needed for Autoware?
Because Autoware's code is complex, you will basically end up reading it with the help of AI. In that scenario, LSP serves as a way to divide labor by providing only the minimal context to the AI, rather than giving it too much unnecessary context. Of course, you can read code using the chat features of Cursor or Copilot without LSP, but when you don't want to use hundreds of thousands of tokens in a single query, you can use the following VSCode extension (this is for C++, as that's the language used here, but there are also extensions for Java, C, Ruby, etc.):
How to set up LSP in Autoware
Now, let's look at how to set up LSP in Autoware. For the initial steps, I refer to:
- Clone the Autoware repository and open it in VSCode.
git clone https://github.com/autowarefoundation/autoware.git
cd autoware
code . # Open with vscode
- Install the "Dev Containers" VSCode extension.
-
Press "Command + Shift + p" in VSCode to open the command palette, select "Dev Containers: Reopen in Container," and open "autoware:core-devel."
-
Once the Docker build and setup are complete, the Autoware codebase will be displayed again in a new window. Since this is an environment inside Docker, it is fundamentally a Linux environment.
-
Run the following command to source the environment variables:
./setup-dev-env.sh
- Run the following command to download the entire Autoware repository:
cd /workspaces/autoware
mkdir -p src
vcs import src < repositories/autoware.repos
- Download the ROS packages:
source /opt/ros/humble/setup.bash
# Make sure all previously installed ros-$ROS_DISTRO-* packages are upgraded to their latest version
sudo apt update && sudo apt upgrade
rosdep update
rosdep install -y --from-paths src --ignore-src --rosdistro $ROS_DISTRO
- In the Docker Desktop settings, set the CPU Limit to 8 or higher and the Memory Limit to 15GB or higher.

-
Note: This differs from the documentation method, so please be careful. Especially if you only have 16GB of memory. Here, we perform a build once to generate
compile_commands.json. Use the following commands:
# Perform an initial build. If you have 16GB of memory, this often fails; if it fails, start over. Caches will remain.
colcon build --symlink-install \
--executor sequential \
--cmake-args \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
--cmake-force-configure
# Once the build succeeds once, build in parallel. I suspect compile_commands.json might not be correct if you don't build it this way.
colcon build --symlink-install \
--cmake-args \
-DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-
compile_commands.jsonis generated underbuild, but it might not work as is. Therefore, run the following script (if node is not installed in the Docker, run it from your local machine to generate it). This code converts thecommandfield incompile_commands.jsontoarguments.
import fs from "fs/promises";
import shellQuote from "shell-quote";
function commandToArguments(command) {
return shellQuote.parse(command).filter(x => typeof x === "string");
}
async function readAndEditFile() {
try {
const content = await fs.readFile("./compile_commands.json", "utf-8");
const commands = JSON.parse(content);
for (const entry of commands) {
const args = commandToArguments(entry.command);
entry.command = undefined;
entry.arguments = args;
}
await fs.writeFile("./compile_commands_arg2.json", JSON.stringify(commands, null, 2));
} catch(e) {
console.error(e);
return;
}
}
readAndEditFile();
mkdir node
cp fixArguments.js node/fixArguments.js
cp build/compile_commands.json node/compile_commands.json
cd node
npm init -y
npm i shell-quote
node fixArguments.js # This will generate compile_commands_arg2.json
- Delete the following line from the generated "compile_commands_arg2.json":
"-fopenmp",
-
Replace the "compile_commands.json" located under "/workspaces/autoware" with the "compile_commands_arg2.json" created up to this point.
-
Once this is done, install
clangdand use your preferred C++ VSCode extension. Clangd should create a.cachedirectory under "build" and start generating the cache; verify that this is happening.
sudo wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
sudo ./llvm.sh 20
The VSCode extension I use:
Final Notes
If there are any mistakes, please let me know.
Discussion