clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
592 stars 97 forks source link

Configuring clangd to Parse Multiple compile_commands.json Files in Different Directories #638

Closed DYAAL closed 2 weeks ago

DYAAL commented 2 weeks ago

Hello, sorry to bother you, I have a question. If my current working directory contains two folders, A and B, each with its own compile_commands.json file that needs to be parsed because A and B are two separate projects. After compiling, two compile_commands.json files are generated. I want to be able to parse them both simultaneously and use clangd to navigate between them.

How can I configure the --compile-commands-dir attribute of the clangd plugin in my current workspace to achieve this effect?

HighCommander4 commented 2 weeks ago

Clangd automatically loads a compile_commands.json file when a source file in its directory tree is opened.

So, as long as you've opened both a file in A and a file in B, navigation across the two projects should work as expected.

DYAAL commented 2 weeks ago

Should I include two separate directories in the --compile-commands-dir property? For example, if I have both files in the 'build' directory under the current folder, do I need to set --compile-commands-dir=${workspaceFolder}/A/build and then set it again as --compile-commands-dir=${workspaceFolder}/B/build

DYAAL commented 2 weeks ago

I have generated two compile_commands.json files through compilation, located respectively in A/build and B/build relative to the current workspaceFolder. How can I configure clangd to load both of these compile_commands.json files simultaneously?

HighCommander4 commented 2 weeks ago

Should I include two separate directories in the --compile-commands-dir property? For example, if I have both files in the 'build' directory under the current folder, do I need to set --compile-commands-dir=${workspaceFolder}/A/build and then set it again as --compile-commands-dir=${workspaceFolder}/B/build

In this situation, you would not use the --compile-commands-dir argument, as that only takes one directory and can only be specified once.

How can I configure clangd to load both of these compile_commands.json files simultaneously?

There isn't a way to do that currently. Clangd loads the CDB when a source file in the respective directory is opened.

Note that --compile-commands-dir does not cause clangd to eagerly load the CDB, either; it still only happens when a source file is opened for the first time.

DYAAL commented 2 weeks ago

ok, thanks a lot for your help! Have a nice day.