vscode-clangd icon indicating copy to clipboard operation
vscode-clangd copied to clipboard

clangd is not indexing files in the background

Open ninok opened this issue 3 years ago • 9 comments

clangd is not indexing files in the background. The status bar is showing 'clangd: idle'

When opening a file clangd is triggered transitively on the file. This not enough when I for example open a header file I cannot jump to the definitions in that file b/c the according cpp is not indexed.

I also added this to my .clangd config file explicitly but it changes nothing:

Index:
  Background: Build

System information Clangd version 15.0.1 clangd extension version: 0.1.21 Operating system: AmazonLinux2 via. remote-ssh

ninok avatar Oct 07 '22 12:10 ninok

Please note that background indexing requires your project to have a compile_commands.json; see https://clangd.llvm.org/installation#project-setup.

If your project does have a compile_commands.json, please attach clangd logs.

HighCommander4 avatar Oct 07 '22 15:10 HighCommander4

Hi @HighCommander4,

I'm using compile_commands.json but I'm afraid that I cannot share the logs b/c they would contain proprietary source code. This is the beginning of the log:

I[19:07:19.855] clangd version 15.0.1 (https://github.com/llvm/llvm-project b73d2c8c720a8c8e6e73b11be4e27afa6cb75bdf)
I[19:07:19.855] Features: linux+grpc
I[19:07:19.855] PID: 48027
I[19:07:19.855] Working directory: /local/home/ninokett/*****
I[19:07:19.855] argv[0]: /home/ninokett/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.1/clangd_15.0.1/bin/clangd
I[19:07:19.855] argv[1]: -background-index
I[19:07:19.855] Starting LSP over stdin/stdout
I[19:07:19.856] <-- initialize(0)
I[19:07:19.857] --> reply:initialize(0) 1 ms
I[19:07:19.857] <-- initialized
I[19:07:19.860] <-- textDocument/didOpen
I[19:07:19.860] --> textDocument/publishDiagnostics
I[19:07:19.887] Loaded compilation database from /local/home/ninokett/******/compile_commands.json
I[19:07:19.887] ASTWorker building file /local/home/ninokett/*****.hpp version 1 with command inferred from /home/ninokett/******.cpp
[/home/ninokett/****/build]

So there is no indication that background indexing is failing.

ninok avatar Oct 07 '22 19:10 ninok

Shortly after Loaded compilation database from <path>, do you see Enqueuing <N> commands for indexing? And if so, does <N> look roughly the right size (number of source files listed in compile_commands.json)?

Note, the count here includes files which are already indexed (indexing them is then a no-op if the file is not more recent than its index entry).

HighCommander4 avatar Oct 07 '22 20:10 HighCommander4

No, I only see the commands for the files that are currently opened.

ninok avatar Oct 07 '22 22:10 ninok

Could you try running clangd with --log=verbose as a command-line argument, and see if Broadcasting compilation database from <path> appears in the log?

HighCommander4 avatar Oct 12 '22 07:10 HighCommander4

@HighCommander4 Hi, I have the same issue, clangd only indexs open files. I use clangd to index kernel 5.13.19. clangd log has been attached. I have been bothered by this issue for a long time. Thanks for any helping. By the way, I used bear to generate compile_commands.json. clangd.log

qiming-007 avatar Nov 07 '22 14:11 qiming-007

@qiming-007 It sounds like maybe your compile_commands.json does not contain entries for all the project's source files? From the logs, Enqueueing 49 commands for indexing sounds like it only has 49 entries, is that the case? (Seems small for the Linux kernel.)

Also from logs like this one:

ASTWorker building file /root/linux-kernels/linux-5.13.19/net/netfilter/xt_time.c version 1 with command inferred from /root/linux-kernels/linux-5.13.19/build_out/../net/ipv4/netfilter/ip_tables.c

This sounds like you're opening xt_time.c, but clangd has to use a command from a different file (ip_tables.c) because xt_time.c does not have its own entry in the compile_commands.json.

HighCommander4 avatar Nov 07 '22 19:11 HighCommander4

Looking into the other issue mentioned above ticket(clangd/clangd#1608) I think I'm also affected by some symlink confusion. Basically my whole home directory is a symlink: /home/ninokett -> /local/home/ninokett

Nevertheless I don't use the symlink and open vscode in the correct project dir: /local/home/ninokett/xyz Also the entries in compile_commands.json use that directory.

When looking at the clangd logs though, I can see two log entries:

  1. Loaded compilation database from /local/home/ninokett/xyz/compile_commands.json
  2. Loaded compilation database from /home/ninokett/xyz/compile_commands.json

So it seems that the correct path get's replaced with the incorrect one at some point and I think that is most probably causing the indexing to not happen.

I also tried specifying the correct path in my .clangd:

CompilationDatabase: /local/home/ninokett/xyz/compile_commands.json

but I got the same output as above.

ninok avatar Jun 16 '23 12:06 ninok

The symlink path /home/ninokett must be leaking in from somewhere. Maybe an -I path in one of the compile commands? Looking in the logs for the first occurrence of /home/ninokett (with the /local) might provide some clues.

HighCommander4 avatar Jun 16 '23 18:06 HighCommander4