How to make Clangd in VSCode only index the currently open file and standard header files?

359 views Asked by At

I am an algorithmic competition participant, and I have a VSCode workspace where I have organized my code from various online judging systems into folders. The directory tree looks roughly like this:

OI (Workspace Root)
- Codeforces
- - CF001A.cpp
- - CF002B.cpp
- ATCoder
- - abc001_a.cpp
- - abc002_b.cpp
- luogu
- - P1001.cpp
- - P1002.cpp

Clearly, my problem files are independent of each other, and I don't need or want to include the contents of other files in one file. I only need to include system header files like iostream and vector.

However, when my problem repository folder reaches a certain size, I noticed that the response time of clangd becomes significantly slower. Below is a part of the clangd log where it can be observed that many operations take several thousand milliseconds.

I[10:43:16.044] Indexing c++2b standard library in the context of d:/Coding/OI/atcoder/abc261_g.cpp
I[10:43:16.195] Built preamble of size 7253168 for file d:/Coding/OI/atcoder/abc261_g.cpp version 1 in 0.97 seconds
......
I[10:43:18.601] Indexed c++2b standard library: 14142 symbols, 958 filtered
I[10:43:19.203] --> textDocument/publishDiagnostics
I[10:43:19.205] --> reply:textDocument/documentLink(1) 3818 ms, error: Task was cancelled.
[Error - 10:43:19] Request textDocument/documentLink failed.
[object Object]
I[10:43:19.205] --> reply:textDocument/inlayHint(2) 3809 ms, error: Task was cancelled.
I[10:43:19.206] --> reply:textDocument/inlayHint(3) 3801 ms, error: Task was cancelled.
[Error - 10:43:19] Request textDocument/inlayHint failed.
[object Object]
[Error - 10:43:19] Request textDocument/inlayHint failed.
[object Object]
I[10:43:19.207] --> reply:textDocument/semanticTokens/full(5) 3382 ms
I[10:43:19.208] --> reply:textDocument/documentLink(6) 3210 ms
I[10:43:19.209] --> reply:textDocument/documentSymbol(7) 2103 ms
I[10:43:19.210] --> reply:textDocument/inlayHint(8) 1800 ms
I[10:43:19.210] --> reply:textDocument/inlayHint(9) 1800 ms
I[10:43:19.211] --> reply:textDocument/codeAction(11) 793 ms

However, when I created a workspace with only one file, the performance of clangd returned to normal.

Playground (Workspace Root)
- test1.cpp

I suspect that Clangd scans the entire folder (or even the workspace) of code every time it performs autocompletion (even though I haven't included them). How can I change this behavior?

I have tried setting clangd parameters such as -j=8, --background-index=false, --pch-storage=memory, and so on, but they were all ineffective.

EDIT: I conformed that clangd will parse the dictionary the current opened file in.

EDIT: The problem only occurs in Windows.

0

There are 0 answers