zed icon indicating copy to clipboard operation
zed copied to clipboard

Improve Rust highlight queries

Open everdrone opened this issue 1 year ago • 3 comments

Release Notes:

  • Add @variable.parameter highlight scope

    parameters are colored pink

  • Add @attribute highlight scope

    attributes are colored yellow

  • Add markdown injection inside doc_comments

    markdown highlighting

everdrone avatar Aug 23 '24 12:08 everdrone

We require contributors to sign our Contributor License Agreement, and we don't have @everdrone on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

cla-bot[bot] avatar Aug 23 '24 12:08 cla-bot[bot]

@cla-bot check

everdrone avatar Aug 23 '24 12:08 everdrone

The cla-bot has been summoned, and re-checked this pull request!

cla-bot[bot] avatar Aug 23 '24 12:08 cla-bot[bot]

Thanks!

mikayla-maki avatar Aug 29 '24 05:08 mikayla-maki

Had started to get panics after this got merged.

Repro case: check out fresh https://github.com/rust-lang/rust-analyzer/ and either open crates/rust-analyzer/src/config.rs (note that this makes reopening this project harder in dev build, as it will always try to restore the same file active and panics after a few — you'll need to close and rerun or adjust the DB to fix this) or do a project search for param_names_for_lifetime_elision_hints (won't be resurrected on restarts).

Backtrace
2024-08-29 13:50:22.475 zed[47979:1926555] TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit
Thread "<unnamed>" panicked with "assertion failed: layer.range.end.cmp(&prev_range.end, text).is_ge()" at crates/language/src/syntax_map.rs:742:29
   0: backtrace::backtrace::libunwind::trace
             at /Users/someonetoignore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.73/src/backtrace/libunwind.rs:116:5
      backtrace::backtrace::trace_unsynchronized::<<backtrace::capture::Backtrace>::create::{closure#0}>
             at /Users/someonetoignore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.73/src/backtrace/mod.rs:66:5
   1: backtrace::backtrace::trace::<<backtrace::capture::Backtrace>::create::{closure#0}>
             at /Users/someonetoignore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.73/src/backtrace/mod.rs:53:14
   2: <backtrace::capture::Backtrace>::create
             at /Users/someonetoignore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.73/src/capture.rs:197:9
   3: <backtrace::capture::Backtrace>::new
             at /Users/someonetoignore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/backtrace-0.3.73/src/capture.rs:162:22
   4: zed::reliability::init_panic_hook::{closure#0}
             at /Users/someonetoignore/work/zed/zed/crates/zed/src/reliability.rs:58:29
   5: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2077:9
      std::panicking::rust_panic_with_hook
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:799:13
   6: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:656:13
   7: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:171:18
   8: rust_begin_unwind
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:652:5
   9: core::panicking::panic_fmt
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:72:14
  10: core::panicking::panic
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:146:5
  11: <language::syntax_map::SyntaxSnapshot>::check_invariants
             at /Users/someonetoignore/work/zed/zed/crates/language/src/syntax_map.rs:742:29
  12: <language::syntax_map::SyntaxSnapshot>::reparse_with_ranges
             at /Users/someonetoignore/work/zed/zed/crates/language/src/syntax_map.rs:729:9
  13: <language::syntax_map::SyntaxSnapshot>::reparse
             at /Users/someonetoignore/work/zed/zed/crates/language/src/syntax_map.rs:384:9
  14: <language::buffer::Buffer>::reparse::{closure#0}
             at /Users/someonetoignore/work/zed/zed/crates/language/src/buffer.rs:1077:17
  15: <core::pin::Pin<alloc::boxed::Box<dyn core::future::future::Future<Output = language::syntax_map::SyntaxSnapshot> + core::marker::Send>> as core::future::future::Future>::poll
             at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/future/future.rs:123:9
  16: <async_task::raw::RawTask<core::pin::Pin<alloc::boxed::Box<dyn core::future::future::Future<Output = language::syntax_map::SyntaxSnapshot> + core::marker::Send>>, language::syntax_map::SyntaxSnapshot, <gpui::executor::BackgroundExecutor>::spawn_internal<language::syntax_map::SyntaxSnapshot>::{closure#0}, ()>>::run
             at /Users/someonetoignore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/raw.rs:557:17
  17: <async_task::runnable::Runnable>::run
             at /Users/someonetoignore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.1/src/runnable.rs:781:18
  18: gpui::platform::mac::dispatcher::trampoline
             at /Users/someonetoignore/work/zed/zed/crates/gpui/src/platform/mac/dispatcher.rs:106:5
  19: <unknown>
  20: <unknown>
  21: <unknown>
  22: _pthread_mach_thread_np

I work on the outline panel fixes right now, and use rust-analyzer extensively for that, also I have no good idea about tree-sitter queries, so I have to revert this PR for now without any useful ideas on top, sorry.

SomeoneToIgnore avatar Aug 29 '24 11:08 SomeoneToIgnore

That's interesting, I think I would say it's the markdown injection that could mess things up? I don't see how simple tree-sitter highlight groups could do that.

Maybe I should open a new PR for just the highlight attributes?

everdrone avatar Aug 29 '24 11:08 everdrone

Sure, any follow-up PRs are welcome.

Markdown can be the key, there are two markdown languages and one of them is a "utility" one that is used to parse the triple backtick-backed code regions. I wonder if we need to use both? https://github.com/zed-industries/zed/blob/main/crates/languages/src/markdown-inline/highlights.scm

SomeoneToIgnore avatar Aug 29 '24 11:08 SomeoneToIgnore

Markdown can be the key, there are two markdown languages and one of them is a "utility" one that is used to parse the triple backtick-backed code regions.

I'm not experienced enough with tree sitter to know. My initial goal was to make zed highlight the code in between triple backticks inside doc comments as Rust code by default. But I started to think that it would require a custom markdown grammar inside just for the Rust grammar.

Vscode already does this and it's helpful to have it highlighted when writing examples.

Also the doc-comment links because when they're not resolved they'll appear as a regular comment.

For example [Element] would appear gray unless we write the fully qualified path as [Element](crate::element::Element) depending on the location of the doc comment.

everdrone avatar Aug 31 '24 10:08 everdrone

Hey, just downloaded v0.152.0-pre and the markdown injection doesn't appear to be working

Screenshot 2024-09-04 at 10 03 11 AM

valentinegb avatar Sep 04 '24 17:09 valentinegb

Those where reverted for causing some panics :)

mikayla-maki avatar Sep 04 '24 17:09 mikayla-maki

Oh okay that's fine, it is in the changelog though

valentinegb avatar Sep 04 '24 17:09 valentinegb