zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
46.52k stars 2.63k forks source link

C language selection is ignored when in header files #12634

Open matthewsanetra opened 3 months ago

matthewsanetra commented 3 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

clangd is not informed of the language currently selected in the editor.

This means that in header files, clangd assumes C++.

A workaround I currently use is to just use CMake and export a compile_commands.json into the project root. This passes the info that we're compiling C to clangd so it works, but I believe the editor shouldn't require us to use CMake to code in C comfortably.

Environment

Zed: v0.137.6 (Zed) OS: macOS 14.4.1 Memory: 16 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

C language is selected:

Screenshot of the bottom right of the Zed editor highlighting that the current selected language is C

Error in a header file:

Screenshot of a snippet of code with a red underlining of bool in a typedef Screenshot of the bottom left of the Zed editor showing an error that bool is redeclaring a C++ built-in type

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

chakkawat-sonaruea commented 1 month ago

I am not expert in clangd. But doesn't clangd always see files as C++.

I think change language in the editor is doesn't changing the fact that both C and C++ in Zed are using clangd, so clangd would show diagnostic according to clangd config.

As for way to configure clangd. One of the recommended way to config clangd that doesn't involve CMake is to use .clangd. I suggest you take a look at clangd's configuration page. https://clangd.llvm.org/config

SomeoneToIgnore commented 1 month ago

I am not expert in clangd. But doesn't clangd always see files as C++.

It seems so, but there's a way to configure it differently, mentioned in

https://github.com/zed-industries/zed/issues/14411#issuecomment-2227324916