This is a bit hacky. Injections cannot stack on each other like
highlights because layers can have their own injections. So this new
language `rust-format-args-macro` emulates that. It unconditionally
injects `rust-format-args` into all strings. Rust injects this new
language into known format-args macros like `println!`.
The downside is that this can cause false-positive highlights within
these macros for strings which happen to contain format-args syntax
println!("Hello, {}!", "{}");
// ^ format args syntax
// ^ not format args syntax, but highlighted
// as if it were :(
This false-positive case is expected to be rare.
Injecting this fake language fixes regular non-string highlights in
macro invocations: macro invocations need to inject the entire token
tree and use `injection.include-children` for proper highlighting.
See attached issue. I don't love the solution, but am not sure how else
to attack the problem. We want to match *almost* every `identifier` in
the scope. We don't want to match scoped identifiers, so the best I
could come up with (without restating large chunks of `highlights.scm`)
was to repeat the negative case. I think this could be another use case
for `#has-ancestor?`, (or `#not-has-ancestor?` technically), but unless
that gets added, I think this is the most straightforward solution.
Closes: #13194
Note that this injection doesn't work currently because precedence is
not handled by the current syntax highlighter. The switch to tree-house
will properly handle the precedence of this pattern.
You may pass constants as type arguments the const generics feature.
This is used in spellbook for example as a poor man's enum, for example
`self.strip_suffix_only::<FULL_WORD>(word, hidden_homonym)`. With this
change that `FULL_WORD` part is highlighted as a constant instead of
a type.
This change also highlight the underscore in type placeholders - this
is similar to the highlighting done for bindings in Elixir or Erlang
for example. In `Vec<_>` the underscore is highlighted the same as a
comment.
* Add some rust builtins
* rust queries: Add everything in the 2021 prelude
* Update runtime/queries/rust/highlights.scm
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
---------
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Enum variants and (tuple) structs are indistinguishable in general, so we
mark any PascalCase pattern or expression as a "constructor", which
covers all three.
This stanza highlights functions within trait definitions. For example,
in:
pub trait Widget {
fn render(self, area: Rect, buf: &mut Buffer);
}
`render` is currently highlighted as a variable. With this change it's
highlighted as a function.
There don't appear to be any regressions from the updates.
Also included is a fix which highlights the "#" as in attributes
as punctuation. This was previously unhighlighted.