Merge branch 'master' into rust-better-fns

pull/13932/head
Nik Revenco 2025-07-14 02:00:34 +01:00
commit b273b89249
11 changed files with 44 additions and 59 deletions

6
Cargo.lock generated
View File

@ -1986,7 +1986,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c"
dependencies = [
"cfg-if",
"windows-targets 0.53.2",
"windows-targets 0.52.6",
]
[[package]]
@ -2844,9 +2844,9 @@ dependencies = [
[[package]]
name = "tree-house-bindings"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "690809022f44e3d2329882649724b6e0027ade3fada65e4631d303e744dc32b4"
checksum = "3f1646788fe0afdbf8e191b5d0f558df7333d8857665a67053c532ec811e6086"
dependencies = [
"cc",
"libloading",

View File

@ -208,6 +208,7 @@
| ruby | ✓ | ✓ | ✓ | `ruby-lsp`, `solargraph` |
| rust | ✓ | ✓ | ✓ | `rust-analyzer` |
| rust-format-args | ✓ | | | |
| rust-format-args-macro | ✓ | ✓ | ✓ | |
| sage | ✓ | ✓ | | |
| scala | ✓ | ✓ | ✓ | `metals` |
| scheme | ✓ | | ✓ | |

View File

@ -90,7 +90,13 @@ pub fn highlighted_code_block<'a>(
if pos == start {
continue;
}
assert!(pos > start);
// The highlighter should always move forward.
// If the highlighter malfunctions, bail on syntax highlighting and log an error.
debug_assert!(pos > start);
if pos < start {
log::error!("Failed to highlight '{language}': {text:?}");
return styled_multiline_text(text, code_style);
}
let style = syntax_highlight_stack
.iter()

View File

@ -300,7 +300,7 @@ impl Theme {
/// Interpret a Highlight with the RGB foreground
fn decode_rgb_highlight(highlight: Highlight) -> Option<(u8, u8, u8)> {
(highlight.get() > Self::RGB_START).then(|| {
let [b, g, r, ..] = (highlight.get() + 1).to_ne_bytes();
let [b, g, r, ..] = (highlight.get() + 1).to_le_bytes();
(r, g, b)
})
}
@ -309,7 +309,7 @@ impl Theme {
pub fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight {
// -1 because highlight is "non-max": u32::MAX is reserved for the null pointer
// optimization.
Highlight::new(u32::from_ne_bytes([b, g, r, u8::MAX]) - 1)
Highlight::new(u32::from_le_bytes([b, g, r, u8::MAX]) - 1)
}
#[inline]

View File

@ -4445,6 +4445,12 @@ injection-regex = "rust-format-args"
name = "rust-format-args"
source = { git = "https://github.com/nik-rev/tree-sitter-rust-format-args", rev = "84ffe550e261cf5ea40a0ec31849ba2443bae99f" }
[[language]]
name = "rust-format-args-macro"
scope = "source.rust-format-args-macro"
file-types = []
grammar = "rust"
[[language]]
name = "clarity"
scope = "source.clar"

View File

@ -0,0 +1 @@
; inherits: rust

View File

@ -0,0 +1 @@
; inherits: rust

View File

@ -0,0 +1,13 @@
; inherits: rust
; HACK: This language is the same as Rust but all strings are injected
; with rust-format-args. Rust injects this into known macros which use
; the format args syntax. This can cause false-positive highlights but
; those are expected to be rare.
([
(string_literal (string_content) @injection.content)
(raw_string_literal (string_content) @injection.content)
]
(#set! injection.language "rust-format-args")
(#set! injection.include-children))

View File

@ -0,0 +1 @@
; inherits: rust

View File

@ -0,0 +1 @@
; inherits: rust

View File

@ -103,8 +103,6 @@
; the `format_args!` syntax.
;
; This language is injected into a hard-coded set of macros.
; 1st argument is `format_args!`
(
(macro_invocation
macro:
@ -113,13 +111,11 @@
name: (_) @_macro_name)
(identifier) @_macro_name
]
(token_tree . [
(string_literal (string_content) @injection.content)
(raw_string_literal (string_content) @injection.content)
]
)
(token_tree) @injection.content
)
(#any-of? @_macro_name
; 1st argument is `format_args!`
; std
"print" "println" "eprint" "eprintln"
"format" "format_args" "todo" "panic"
@ -140,63 +136,22 @@
"eyre"
; miette
"miette"
)
(#set! injection.language "rust-format-args")
(#set! injection.include-children)
)
; 2nd argument is `format_args!`
(
(macro_invocation
macro:
[
(scoped_identifier
name: (_) @_macro_name)
(identifier) @_macro_name
]
(token_tree
. (_)
. [
(string_literal (string_content) @injection.content)
(raw_string_literal (string_content) @injection.content)
]
)
)
(#any-of? @_macro_name
; 2nd argument is `format_args!`
; std
"write" "writeln" "assert" "debug_assert"
; defmt
"expect" "unwrap"
; ratatui
"span"
)
(#set! injection.language "rust-format-args")
(#set! injection.include-children)
)
; 3rd argument is `format_args!`
(
(macro_invocation
macro:
[
(scoped_identifier
name: (_) @_macro_name)
(identifier) @_macro_name
]
(token_tree
. (_)
. (_)
. [
(string_literal (string_content) @injection.content)
(raw_string_literal (string_content) @injection.content)
]
)
)
(#any-of? @_macro_name
; 3rd argument is `format_args!`
; std
"assert_eq" "debug_assert_eq" "assert_ne" "debug_assert_ne"
)
(#set! injection.language "rust-format-args")
(#set! injection.language "rust-format-args-macro")
(#set! injection.include-children)
)