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.4k stars 2.62k forks source link

(Rust) C-String literals break syntax highlighting #14775

Open blu-dev opened 1 month ago

blu-dev commented 1 month ago

Check for existing issues

Describe the bug / provide steps to reproduce it

I doubt this is a Zed bug and probably more of a syntax tree bug (I think zed uses treesitter?) but regardless I figured I would post it here since I have no idea where to go to address it. C-String literals are a relatively new addition to rust

The actual symptoms of the bug seem to be inconsistent, ranging from simply strings not highlighting separately to breaking syntax highlighting for many tokens until a new quote appears.

Taking the following code and pasting it into a new rust file/module should provide the same result as the screenshots attached below (it appears this also happens in GitHub Markdown Preview)

use std::ffi::CStr;

pub fn invalid_highlighted_sample_code() -> &'static CStr {
    c"b" // When the string literal contains exactly one character, it continues string literal
         // highlighting until the next open quote
}

pub fn normal_highlighted_sample_code() -> &'static str {
    "this is a normal string"
}

pub fn non_highlighted_sample_code() -> &'static CStr {
    c"this is a broken string"
}

Environment

Zed: v0.144.3 (Zed) OS: Linux X11 ubuntu 22.04 Memory: 61.9 GiB Architecture: x86_64

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

image

If applicable, attach your Zed.log file to this issue.

No response

lylythechosenone commented 1 month ago

I wonder if this is actually an issue in tree-sitter-rust.

bbb651 commented 1 month ago

I cannot reproduce it on neovim with nvim-treesitter image

d1y commented 1 month ago

I think this commit fixes this syntax omission /cc @maxbrunsfeld

https://github.com/tree-sitter/tree-sitter-rust/releases/tag/v0.21.2

https://github.com/tree-sitter/tree-sitter-rust/commit/17ce09d7b4b29bd4c37c5b3ad3b5d5c98a84b076