clangd / vscode-clangd

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

huge project add clangd.fallbackFlag -I<dir> don't work #497

Closed CalebDu closed 1 year ago

CalebDu commented 1 year ago

because my huge project can't find some header file. I add -I flag in clangd.fallbackFlag. but i does not work. And in clangd extension "output" there is no "fallbackFlag" information. setting.json

  "clangd.fallbackFlags": [
    "-I/home/caleb.du/code/tops/build/3rdparty/clang_binary/src/lib/clang/11.0.0/include/",
  ],

Logs

I[03:56:08.575] <-- shutdown(3)
I[03:56:08.575] --> reply:shutdown(3) 0 ms
I[03:56:08.621] <-- exit
I[03:56:08.622] LSP finished, exiting with status 0
I[03:56:08.636] clangd version 16.0.2 (https://github.com/llvm/llvm-project 18ddebe1a1a9bde349441631365f0472e9693520)
I[03:56:08.636] Features: linux+grpc
I[03:56:08.636] PID: 29861
I[03:56:08.636] Working directory: /home/caleb.du/code/tops
I[03:56:08.636] argv[0]: /home/caleb.du/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/16.0.2/clangd_16.0.2/bin/clangd
I[03:56:08.636] argv[1]: --compile-commands-dir=/home/caleb.du/code/tops/build
I[03:56:08.636] argv[2]: --completion-style=detailed
I[03:56:08.636] argv[3]: --header-insertion=never
I[03:56:08.636] Starting LSP over stdin/stdout
I[03:56:08.636] <-- initialize(0)
I[03:56:08.638] --> reply:initialize(0) 2 ms
I[03:56:08.643] <-- initialized
I[03:56:08.654] <-- textDocument/didOpen
I[03:56:08.954] Loaded compilation database from /home/caleb.du/code/tops/build/compile_commands.json
I[03:56:08.967] ASTWorker building file /home/caleb.du/code/tops/build/_deps/op_atomic_op-src/src/reduce/softmax_fp32.cc version 1 with command inferred from /home/caleb.du/code/tops/build/_deps/sw_enflame.open_bfloat16-src/src/bfloat16.cc
[/home/caleb.du/code/tops/build]
/opt/efb/efb_x86_64_gcc-5.5.0_glibc-2.17_linux/bin/x86_64-linux-gnu-g++ --target=x86_64-linux-gnu --driver-mode=g++ --sysroot=/opt/efb/efb_x86_64_gcc-5.5.0_glibc-2.17_linux -DEIGEN_MPL2_ONLY -DPROJECT_VERSION_MAJOR=2 -DPROJECT_VERSION_MINOR=2 -DPROJECT_VERSION_PATCH=1 -DPROJECT_VERSION_TWEAK=0 -D_GLIBCXX_USE_CXX11_ABI=0 -I/home/caleb.du/code/tops/build/third_party/install/gflags/include -I/home/caleb.du/code/tops/build/_deps/i_cmake-src/external/protobuf/x86_64-linux-abi0/include -I/home/caleb.du/code/tops/build/usr/include -I/home/caleb.du/code/tops/build/usr/include/dtu/umd -I/home/caleb.du/code/tops/build/_deps/sw_enflame.open_bfloat16-src/include -O3 -g0 -DNDEBUG -fPIC --sysroot=/opt/efb/efb_x86_64_gcc-5.5.0_glibc-2.17_linux -m64 -march=x86-64 -mtune=generic -D TOPSRIDER_FALLTHROUGH= -Werror=array-bounds -Werror=empty-body -Werror=format-extra-args -Werror=bool-compare -Werror=address -Werror=free-nonheap-object -Werror=overflow -Werror=return-local-addr -Werror=unused-value -Werror=switch-bool -Werror=switch -Werror=write-strings -Werror=unused-function -Werror=conversion-null -Werror=delete-incomplete -Werror=delete-non-virtual-dtor -Werror=shift-count-overflow -Werror=sizeof-pointer-memaccess -Werror=unused-label -Werror=unreachable-code -Werror=format -Werror=format-security -Werror=varargs -Wdouble-promotion -Wno-error=narrowing -Wno-error=format= -fno-canonical-system-headers -Wno-narrowing -Wno-attributes -Wno-reorder -Wno-sign-compare -Wno-double-promotion -Wno-unused-function -c -std=gnu++14 -resource-dir=/home/caleb.du/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/16.0.2/clangd_16.0.2/lib/clang/16 -- /home/caleb.du/code/tops/build/_deps/op_atomic_op-src/src/reduce/softmax_fp32.cc
I[03:56:08.981] --> textDocument/clangd.fileStatus
I[03:56:09.005] <-- textDocument/semanticTokens/full(1)
I[03:56:09.427] --> window/workDoneProgress/create(0)
I[03:56:09.429] <-- reply(0)
I[03:56:09.429] --> $/progress
I[03:56:09.429] --> $/progress
I[03:56:09.429] --> $/progress
I[03:56:09.430] Enqueueing 4730 commands for indexing
I[03:56:09.822] Indexing c++14 standard library in the context of /home/caleb.du/code/tops/build/_deps/op_atomic_op-src/src/reduce/softmax_fp32.cc
I[03:56:10.107] Built preamble of size 1842080 for file /home/caleb.du/code/tops/build/_deps/op_atomic_op-src/src/reduce/softmax_fp32.cc version 1 in 1.12 seconds
I[03:56:10.107] --> workspace/semanticTokens/refresh(1)
I[03:56:10.111] <-- reply(1)
I[03:56:10.200] --> textDocument/publishDiagnostics
I[03:56:10.212] --> reply:textDocument/semanticTokens/full(1) 1206 ms
I[03:56:10.214] --> textDocument/clangd.fileStatus
I[03:56:11.517] <-- textDocument/semanticTokens/full/delta(2)
I[03:56:11.519] --> reply:textDocument/semanticTokens/full/delta(2) 1 ms
I[03:56:11.519] --> textDocument/clangd.fileStatus
I[03:56:14.223] Indexed c++14 standard library: 10387 symbols, 7922 filtered
I[03:56:36.943] --> $/progress
I[03:56:36.944] --> $/progress
I[03:56:45.160] <-- textDocument/documentSymbol(3)
I[03:56:45.160] --> reply:textDocument/documentSymbol(3) 0 ms
I[03:56:45.160] --> textDocument/clangd.fileStatus
I[03:56:45.160] <-- textDocument/codeAction(4)
I[03:56:45.161] --> reply:textDocument/codeAction(4) 0 ms
I[03:56:45.161] --> textDocument/clangd.fileStatus
I[03:56:45.165] <-- textDocument/documentLink(5)
I[03:56:45.165] --> reply:textDocument/documentLink(5) 0 ms
I[03:56:45.165] --> textDocument/clangd.fileStatus
I[03:56:45.165] <-- textDocument/inlayHint(6)
I[03:56:45.166] --> reply:textDocument/inlayHint(6) 0 ms
I[03:56:45.166] --> textDocument/clangd.fileStatus
I[03:56:45.296] <-- textDocument/foldingRange(7)
I[03:56:45.297] --> reply:textDocument/foldingRange(7) 1 ms
I[03:56:45.412] <-- textDocument/codeAction(8)
I[03:56:45.413] --> reply:textDocument/codeAction(8) 0 ms
I[03:56:45.413] --> textDocument/clangd.fileStatus
I[03:56:45.909] <-- textDocument/inlayHint(9)
I[03:56:45.910] --> reply:textDocument/inlayHint(9) 0 ms
I[03:56:45.910] --> textDocument/clangd.fileStatus
I[03:56:46.294] <-- textDocument/inlayHint(10)
I[03:56:46.295] --> reply:textDocument/inlayHint(10) 0 ms
I[03:56:46.295] --> textDocument/clangd.fileStatus
I[03:56:46.565] <-- textDocument/hover(11)
I[03:56:46.566] --> reply:textDocument/hover(11) 1 ms
I[03:56:46.566] --> textDocument/clangd.fileStatus
I[03:56:46.993] <-- textDocument/hover(12)
I[03:56:46.995] --> reply:textDocument/hover(12) 1 ms
I[03:56:46.995] --> textDocument/clangd.fileStatus
I[03:56:47.647] <-- textDocument/hover(13)
I[03:56:47.648] --> reply:textDocument/hover(13) 1 ms
I[03:56:47.648] --> textDocument/clangd.fileStatus
I[03:56:49.883] <-- textDocument/hover(14)
I[03:56:49.886] --> reply:textDocument/hover(14) 2 ms
I[03:56:49.886] --> textDocument/clangd.fileStatus
I[03:56:50.483] <-- textDocument/hover(15)
I[03:56:50.487] --> reply:textDocument/hover(15) 3 ms
I[03:56:50.487] --> textDocument/clangd.fileStatus
I[03:57:00.094] <-- textDocument/codeAction(16)
I[03:57:00.094] --> reply:textDocument/codeAction(16) 0 ms
I[03:57:00.095] --> textDocument/clangd.fileStatus
I[03:57:00.127] <-- textDocument/documentLink(17)
I[03:57:00.129] --> reply:textDocument/documentLink(17) 2 ms
I[03:57:00.130] --> textDocument/clangd.fileStatus
I[03:57:00.138] <-- textDocument/inlayHint(18)
I[03:57:00.142] --> reply:textDocument/inlayHint(18) 4 ms
I[03:57:00.142] --> textDocument/clangd.fileStatus
I[03:57:00.260] <-- textDocument/foldingRange(19)
I[03:57:00.262] --> reply:textDocument/foldingRange(19) 2 ms
I[03:57:00.352] <-- textDocument/codeAction(20)
I[03:57:00.354] --> reply:textDocument/codeAction(20) 1 ms
I[03:57:00.354] --> textDocument/clangd.fileStatus

System information Clangd version (from the log, or clangd --version): 16.0.2 clangd extension version:0.1.24 Operating system:ubuntu16.04 docker

HighCommander4 commented 1 year ago

clangd.fallbackFlags is only used for source files for which a compile_commands.json file cannot be found. In this case, clangd is successfully finding /home/caleb.du/code/tops/build/compile_commands.json, so fallbackFlags will not be used.

For adding an extra flag to the command from compile_commands.json, you can create a .clangd config file containing:

CompileFlags:
  Add: [-I/home/caleb.du/code/tops/build/3rdparty/clang_binary/src/lib/clang/11.0.0/include/]

See https://clangd.llvm.org/config.html#add for more details.

CalebDu commented 1 year ago

clangd.fallbackFlags is only used for source files for which a compile_commands.json file cannot be found. In this case, clangd is successfully finding /home/caleb.du/code/tops/build/compile_commands.json, so fallbackFlags will not be used.

For adding an extra flag to the command from compile_commands.json, you can create a .clangd config file containing:

CompileFlags:
  Add: [-I/home/caleb.du/code/tops/build/3rdparty/clang_binary/src/lib/clang/11.0.0/include/]

See https://clangd.llvm.org/config.html#add for more details.

thank you, i fix it.