-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clangd: Third-party header file not found #468
Comments
Above behavior is by-designed, we use a plugin call https://github.com/ahmedkhalf/project.nvim, which set the U can set this line: nvimdots/lua/modules/tools/config.lua Line 82 in b984ad0
to true to see if that helps.
U might want to check if their any file in Footnotes |
thanks for your advice. I tried both of them whereas the
Is there something wrong with what I did? or anything should be done after changing the config file to make config file work? |
@csyJoy No, the core issue is how you generate |
Do you also have
How did you generate this Also on macOS you may specify global nvim ~/Library/Preferences/clangd/config.yaml See #193 (comment) for details.
As @CharlesChiuGit metioned, this is the actual behavior when using
This would be expected, as your
As explained above. So the solution is to put your You would then see (a small CMake project): Client: clangd (id: 1, bufnr: [19])
filetypes: c, cpp, objc, objcpp, cuda, proto
autostart: true
--> root directory: /Users/jint/Desktop/test_proj
cmd: clangd -j=12 --enable-config --query-driver=/usr/bin/clang++,/usr/bin/**/clang-*,/bin/clang,/bin/clang++,/usr/bin/gcc,/usr/bin/g++ --all-scopes-completion --background-index --clang-tidy --completion-parse=auto --completion-style=detailed --header-insertion-decorators --header-insertion=iwyu --limit-references=3000 --limit-results=500 --pch-storage=memory You can also write a script to automate this process: #!/bin/bash
if [[ -d build && -e CMakeLists.txt ]]; then
cmake -S . -B ./build >/dev/null 2>&1
cmake -S . -B ./build && make --directory ./build && ([[ -e ./build/compile_commands.json ]] && mv -f ./build/compile_commands.json ./)
else
if [[ -e CMakeLists.txt ]]; then
mkdir build
cmake -S . -B ./build >/dev/null 2>&1
cmake -S . -B ./build && make --directory ./build && ([[ -e ./build/compile_commands.json ]] && mv -f ./build/compile_commands.json ./)
else
printf "\033[1;31mError: \033[0mNot a valid CMake directory.\n"
fi
fi |
A quick note here, |
Wow, I learn a lot too. Maybe we should pin this issue. edit: Oh no, we can only have three pinned issues. Maybe we can add a wiki page for some valuable issues and comments. |
What's the point of that? The purpose of root dir is to load user-defined projects quickly. Since you won't modify third-party libraries in most cases, then why would you set that as the project root directory? All you need is to inform But it's true that the relevant documents are quite vague. I also encountered a lot of issues when I first started to use LSPs. If you have any further questions, feel free to point that out! |
@Jint-lzxy Thank a lot for your detailed answer. after generating |
@csyJoy Please read #468 (comment) first 👍 |
I would recommend you to have a look at http://www.compsci.hunter.cuny.edu/~sweiss/resources/about_gcc.pdf to better understand why |
To be short, you need to put this file in the root directory of your project |
I know, but if I only do this, the clangd still throw the error, after copying the |
What was the specific error - you mean "clangd doesn't find the header file correctly"? Is it convenient for you to share your |
Is this file located at |
I checked the |
Try export CPATH="${CPATH}:/opt/homebrew/include"
export BOOST_ROOT="${BOOST_ROOT:-$(brew --prefix boost)}"
export BOOST_INCLUDE_DIRS="${BOOST_ROOT}/include"
export BOOST_LIBRARY_DIRS="${BOOST_ROOT}/lib" before starting neovim to see if that helps. If this works, then you may specify the include dir first: include_directories(<your-include-search-dir>) |
I export the variable and it works, but when I try to use |
Then this should have nothing to do with |
Yes, I just use your shell script to generate |
If you can build this project, it is recommended that you add |
See #193 (comment) |
Finally It works fine 🎉 Thank you all for the help, I learn a lot from this issue, I think I should close this issue now. |
Version confirmation
Neovim version
NVIM v0.8.2
Operating system/version
macOS 13.2
Terminal name/version
iTerm2 Build 3.4.18
$TERM environment variable
No response
Branch info
main (Default/Latest)
Fetch Preferences
SSH (use_ssh = true)
Affected language servers
clangd
How to reproduce the issue
gD
on a third party header filepath/file file not found
on a cpp header fileActual behavior
clangd doesn't find the header file correctly
Expected behavior
clangd finds the header file correctly
Support info
:LspInfo
:Mason
Logs
No response
Additional information
what I did to solve this problem:
-DCMAKE_CXX_COMPILER=clang++
compile_command.json
, in the:LspInfo
you can see/Users/csy/cpp_test/build
which is the correct path..gitignore
file by adding!/Cellar
I find something that may cause this problem:
:pwd
in the third party headers file's buffer, It print/opt/homebrew
, not the actual path of the file:LspInfo
the root directory is/opt/homebrew
nvim-tree
in /opt/homebrew, It doesn't showCellar
dir, after I change the.gitignore
file of homebrew by add!/Cellar
,nvim-tree
shows theCellar
dir, but clangd still throws the file not found errorIMO, buffer's path and the root directory and the wired
Cellar
directory cause this problem, but what happened actually?The text was updated successfully, but these errors were encountered: