zed icon indicating copy to clipboard operation
zed copied to clipboard

Included header not resolved

Open lszsrd opened this issue 1 year ago • 5 comments
trafficstars

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

Capture d’écran 2024-04-14 à 18 28 04

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 2024-04-14T01:56:31+02:00 [ERROR] point Point { row: 1, column: 26 } is beyond the end of a line with length 0 2024-04-14T01:57:08+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T01:58:36+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T01:58:36+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T01:58:37+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T01:58:39+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T01:58:44+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T01:58:44+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T01:59:05+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include/unistd.h" 2024-04-14T02:18:07+02:00 [ERROR] point Point { row: 0, column: 51 } is beyond the end of a line with length 0 2024-04-14T02:21:41+02:00 [ERROR] point Point { row: 1, column: 23 } is beyond the end of a line with length 0 2024-04-14T02:21:41+02:00 [ERROR] point Point { row: 1, column: 23 } is beyond the end of a line with length 0 2024-04-14T11:35:23+02:00 [ERROR] point Point { row: 0, column: 40 } is beyond the end of a line with length 0 2024-04-14T11:35:23+02:00 [ERROR] point Point { row: 0, column: 40 } is beyond the end of a line with length 0 2024-04-14T11:35:47+02:00 [ERROR] point Point { row: 0, column: 11 } is beyond the end of a line with length 0 2024-04-14T11:35:47+02:00 [ERROR] point Point { row: 0, column: 11 } is beyond the end of a line with length 0 2024-04-14T11:42:31+02:00 [ERROR] error reading file "/Users/laszlo/Desktop/Shared/42sh/42shv1/stBlAjjY" on event: No such file or directory (os error 2) 2024-04-14T11:44:37+02:00 [ERROR] stream did not contain valid UTF-8 2024-04-14T11:57:55+02:00 [ERROR] point Point { row: 0, column: 30 } is beyond the end of a line with length 0 2024-04-14T11:57:55+02:00 [ERROR] point Point { row: 0, column: 30 } is beyond the end of a line with length 0 2024-04-14T11:58:08+02:00 [ERROR] point Point { row: 1, column: 8 } is beyond the end of a line with length 0 2024-04-14T11:58:08+02:00 [ERROR] point Point { row: 1, column: 8 } is beyond the end of a line with length 0 2024-04-14T12:00:08+02:00 [ERROR] stream did not contain valid UTF-8 2024-04-14T12:02:41+02:00 [ERROR] point Point { row: 2, column: 31 } is beyond the end of a line with length 0 2024-04-14T12:02:41+02:00 [ERROR] point Point { row: 2, column: 30 } is beyond the end of a line with length 0 2024-04-14T12:02:41+02:00 [ERROR] point Point { row: 2, column: 30 } is beyond the end of a line with length 0 2024-04-14T12:02:44+02:00 [ERROR] point Point { row: 0, column: 17 } is beyond the end of a line with length 0 2024-04-14T12:02:44+02:00 [ERROR] point Point { row: 0, column: 17 } is beyond the end of a line with length 0 2024-04-14T12:07:58+02:00 [ERROR] unexpected item event after pane was dropped 2024-04-14T12:08:07+02:00 [ERROR] unexpected item event after pane was dropped 2024-04-14T15:15:41+02:00 [ERROR] unexpected item event after pane was dropped 2024-04-14T15:26:36+02:00 [ERROR] unexpected item event after pane was dropped 2024-04-14T15:31:36+02:00 [ERROR] unexpected item event after pane was dropped 2024-04-14T15:35:39+02:00 [INFO] reload git repository ".git" 2024-04-14T15:35:40+02:00 [INFO] reload git repository ".git" 2024-04-14T15:35:40+02:00 [INFO] reload git repository ".git" 2024-04-14T15:36:52+02:00 [INFO] reload git repository ".git" 2024-04-14T15:36:52+02:00 [INFO] reload git repository ".git" 2024-04-14T15:36:56+02:00 [INFO] reload git repository ".git" 2024-04-14T15:40:20+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/stddef.h" 2024-04-14T15:40:20+02:00 [ERROR] crates/project/src/project.rs:3139: no worktree found for diagnostics path "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/stddef.h" 2024-04-14T15:42:40+02:00 [ERROR] unexpected item event after pane was dropped 2024-04-14T16:57:26+02:00 [ERROR] crates/lsp/src/lsp.rs:721: oneshot canceled 2024-04-14T16:57:26+02:00 [INFO] ========== starting zed ========== 2024-04-14T16:57:26+02:00 [INFO] Opening main db 2024-04-14T16:57:26+02:00 [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git") 2024-04-14T16:57:26+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:26+02:00 [ERROR] crates/theme/src/settings.rs:371: theme not found: Xcode High Contrast Dark 2024-04-14T16:57:26+02:00 [INFO] extensions updated. loading 3, reloading 0, unloading 0 2024-04-14T16:57:26+02:00 [ERROR] crates/zed/src/zed.rs:631: EOF while parsing a value at line 1 column 0 2024-04-14T16:57:26+02:00 [INFO] Opening main db 2024-04-14T16:57:26+02:00 [INFO] building git repository, .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: []

lszsrd avatar Apr 14 '24 16:04 lszsrd

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.

leftbones avatar May 11 '24 04:05 leftbones

I am having the same problem

Christofon avatar May 11 '24 10:05 Christofon

Same problem, i use CMake to build C++ project, how can clang find my dependencies?

jryxxx avatar May 12 '24 07:05 jryxxx

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.

leftbones avatar May 20 '24 19:05 leftbones

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.

leftbones avatar May 20 '24 19:05 leftbones

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

williamd1k0 avatar Jul 02 '24 21:07 williamd1k0