Start `clangd` when a file of any type is opened if `compile_commands.json` is in a parent directory
See original GitHub issueI’ve built a database for my project, which has .c
, .h
. and .S
(assembly) files. When I open VSCode and navigate to a .c
file, clangd
is started and I can use commands like “Go to Symbol in Workspace” just fine, even if I navigate to other files like a .S
file.
However, if I close VSCode while in a .S
file (or any file that’s not a.c
or .h
file, like a Makefile
), then reopen VSCode, I start in the last file I opened, and because it’s not a .c
or .h
file clangd
isn’t started, and I can’t use any clangd
features until I open a .c
or .h
file, which is inconvenient.
Can we add an option to start clangd
when any file is opened, as long as there’s a compile_commands.json
in some parent directory?
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
parent directory (..) in compile_commands.json might prevent ...
in compile_commands.json might prevent background indexing #1317 ... editor (Emacs) starts one clangd process for each project for which I have a file...
Read more >Getting started with clangd - LLVM releases
json file provides compile commands for all source files in the project. This file is usually generated by the build system, or tools...
Read more >Configuration - What is clangd? - LLVM
Configuration is stored in YAML files. These are either: project configuration: a file named .clangd in the source tree. (clangd searches in all...
Read more >Getting started - What is clangd? - LLVM
This file provides compile commands for every source file in a project. It is usually generated by tools. clangd will look in the...
Read more >JSON Compilation Database Format Specification - Clang
Figuring out whether things have changed is often an IO bound process; this makes it ... A compilation database is a JSON file,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That sounds like a solid plan, but I’d extend it to also look for the fallback
CompileFlags.txt
I’d find this behavior useful with or without strong workspace mode.
It seems like
clangd
needs to receive at least onetextDocument/didOpen
before it loads the index (see https://github.com/microsoft/language-server-protocol/issues/861 and https://discourse.llvm.org/t/clangd-explicit-and-implicit-doc-open/205).While ideally I think this could be improved in
clangd
, I think it would be worth it to implement a small workaround invscode-clangd
to get the desired behavior. One idea is that if we detect acompile_commands.json
, we can just send that toclangd
in atextDocument/didOpen
request.clangd
will load the index regardless of whether the file we sent is a valid C++ file. I fully support putting this behind a setting that’s off by default.I did a quick test of this by adding
{scheme: 'file', language: 'json'}
inclangdDocumentSelector
inclangd-context.ts
. After opening thecompile_commands.json
, I was able to find symbols in other C files in the index. This was just a test of course, we shouldn’t be modifyingclangdDocumentSelector
but instead locating thecompile_commands.json
and sending it directly.@sam-mccall Does this solution seem acceptable or too much of a hack?