zed
zed copied to clipboard
Included header not resolved
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
On C projects, I have my own library and some header file of the current project I am working on. When including those header files, Zed highlights them with a "clang: 'file_name.h' not found" popup. Header files not being found also highlight all of my functions in red saying they do not exist because it does not find its prototypes.
Environment
Zed: v0.130.6 (Zed) OS: macOS 14.4.1 Memory: 32 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
- Create a header file outside of the current directory
- Include this header file and you should have this bug
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
2024-04-14T01:50:56+02:00 [ERROR] unexpected item event after pane was dropped
2024-04-14T01:56:31+02:00 [ERROR] point Point { row: 1, column: 26 } is beyond the end of a line with length 0
.git path in the worktree: ".git"
2024-04-14T16:57:26+02:00 [INFO] set status on client 0: Authenticating
2024-04-14T16:57:26+02:00 [INFO] Opening main db
2024-04-14T16:57:26+02:00 [INFO] Opening main db
2024-04-14T16:57:26+02:00 [INFO] set status on client 146094: Connecting
2024-04-14T16:57:26+02:00 [INFO] starting language server "clangd", path: "/Users/laszlo/Desktop/Shared/42sh/42shv1", id: 1
2024-04-14T16:57:26+02:00 [INFO] found user-installed language server for C. path: "/usr/bin/clangd", arguments: []
2024-04-14T16:57:26+02:00 [INFO] starting language server. binary path: "/usr/bin/clangd", working directory: "/Users/laszlo/Desktop/Shared/42sh/42shv1", args: []
2024-04-14T16:57:27+02:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-04-14T16:57:27+02:00 [INFO] add connection to peer
2024-04-14T16:57:27+02:00 [INFO] waiting for server hello
2024-04-14T16:57:27+02:00 [INFO] got server hello
2024-04-14T16:57:27+02:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 390, id: 797589 })
2024-04-14T16:57:27+02:00 [INFO] set status on client 146094: Connected { peer_id: PeerId { owner_id: 390, id: 797589 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-04-14T16:57:29+02:00 [INFO] downloaded update. path:"/var/folders/sw/2h6c8j1n1757hz9nq31_s98m0000gn/T/zed-auto-updateJT2JlW/Zed.dmg"
2024-04-14T16:57:36+02:00 [ERROR] crates/lsp/src/lsp.rs:728: oneshot canceled
2024-04-14T16:57:36+02:00 [INFO] ========== starting zed ==========
2024-04-14T16:57:36+02:00 [INFO] Opening main db
2024-04-14T16:57:36+02:00 [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git")
2024-04-14T16:57:36+02:00 [INFO] set environment variables from shell:/bin/zsh, path:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/go/bin:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin
2024-04-14T16:57:37+02:00 [ERROR] crates/theme/src/settings.rs:371: theme not found: Xcode High Contrast Dark
2024-04-14T16:57:37+02:00 [INFO] extensions updated. loading 3, reloading 0, unloading 0
2024-04-14T16:57:37+02:00 [ERROR] crates/zed/src/zed.rs:631: EOF while parsing a value at line 1 column 0
2024-04-14T16:57:37+02:00 [INFO] Opening main db
2024-04-14T16:57:37+02:00 [INFO] building git repository, .git path in the worktree: ".git"
2024-04-14T16:57:37+02:00 [INFO] Opening main db
2024-04-14T16:57:37+02:00 [INFO] set status on client 0: Authenticating
2024-04-14T16:57:37+02:00 [INFO] set status on client 146094: Connecting
2024-04-14T16:57:37+02:00 [INFO] Opening main db
2024-04-14T16:57:37+02:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-04-14T16:57:38+02:00 [INFO] add connection to peer
2024-04-14T16:57:38+02:00 [INFO] waiting for server hello
2024-04-14T16:57:38+02:00 [INFO] got server hello
2024-04-14T16:57:38+02:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 390, id: 797653 })
2024-04-14T16:57:38+02:00 [INFO] set status on client 146094: Connected { peer_id: PeerId { owner_id: 390, id: 797653 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-04-14T16:57:38+02:00 [INFO] starting language server "clangd", path: "/Users/laszlo/Desktop/Shared/42sh/42shv1", id: 1
2024-04-14T16:57:38+02:00 [INFO] found user-installed language server for C. path: "/usr/bin/clangd", arguments: []
2024-04-14T16:57:38+02:00 [INFO] starting language server. binary path: "/usr/bin/clangd", working directory: "/Users/laszlo/Desktop/Shared/42sh/42shv1", args: []
Also having this issue in a C++ project. I can still build and run normally, even though Zed claims my header files don't exist.
EDIT: Confirmed that it also happens in C, it was normal at first, but then suddenly the errors appeared.
I am having the same problem
Same problem, i use CMake to build C++ project, how can clang find my dependencies?
Chiming in again to add some more info. I've tested this now in C with SDL2 and Raylib and in C++ with Raylib and fmt. SDl2 and Raylib in C both are "not found" even though the code compiles and runs normally. Though in C++, for some reason, Raylib is found but fmt is not. Both Raylib and fmt are being added in the same way, using FetchContent in CMake.
I tested again because originally I had only tested with SDL2 and since that's installed on my machine instead of being fetched by CMake, I thought maybe the issue was clang not being able to find it, but using FetchContent in the C project to get Raylib still has the same problem.
I have no idea why Zed doesn't take issue with Raylib in the C++ project, considering it also uses FetchContent and it's pulling from the exact same repo.
I figured it out. Adding set(CMAKE_EXPORT_COMPILE_COMMANDS ON) towards the top of my CMakeLists.txt, building again, and reloading Zed made all of the errors go away!
After searching for people having this issue in other editors, I found that clang (and clangd) need the compile_commands.json file to work properly.
I was having a similar issue.
I have tried to include directories in a .clangd file without success.
Then I tried including directories in a compile_flags.txt (similar to @leftbones approach) and it worked fine.
Docs for reference:
- https://clangd.llvm.org/design/compile-commands#where-do-compile-commands-come-from
- https://clang.llvm.org/docs/JSONCompilationDatabase.html#alternatives