From 5beadef0d4c4c64abdb8cdeb7fa45873b1cd0a1f Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 03:31:04 +0000 Subject: [PATCH 1/9] feat: add `tree-sitter-rustfmt` --- languages.toml | 10 +++++++++ runtime/queries/rust/injections.scm | 4 ++++ runtime/queries/rustfmt/highlights.scm | 30 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 runtime/queries/rustfmt/highlights.scm diff --git a/languages.toml b/languages.toml index a3cb0cfa134a..3a4cd53c7d34 100644 --- a/languages.toml +++ b/languages.toml @@ -4111,3 +4111,13 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "ghostty" source = { git = "https://github.com/bezhermoso/tree-sitter-ghostty" , rev = "8438a93b44367e962b2ea3a3b6511885bebd196a" } + +[[language]] +name = "rustfmt" +scope = "source.rustfmt" +file-types = [] +injection-regex = "rustfmt" + +[[grammar]] +name = "rustfmt" +source = { git = "https://github.com/nik-rev/tree-sitter-rustfmt", rev = "d8e517d9aca1905261a378b25688e4500ae4dd22" } diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index b05b9d9750a4..719d33afa279 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -75,3 +75,7 @@ [(string_literal) (raw_string_literal)] @injection.content ) (#set! injection.language "sql")) + +; TODO: change this so it injects into all strings within a macro call +((string_content) @injection.content + (#set! injection.language "rustfmt")) diff --git a/runtime/queries/rustfmt/highlights.scm b/runtime/queries/rustfmt/highlights.scm new file mode 100644 index 000000000000..4018897db1d5 --- /dev/null +++ b/runtime/queries/rustfmt/highlights.scm @@ -0,0 +1,30 @@ +; (format_string) @string + +(escaped) @constant.character.escape + +[ + "#" + (type) +] @special + +[ + (sign) + (fill) + (align) +] @operator + +(number) @constant.numeric + +(colon) @punctuation + +(identifier) @variable + +((identifier) @constant + (#match? @constant "^[A-Z_]+$")) + +[ + "{" + "}" +] @punctuation.special + +(ERROR) @error From a5250628384d85a0440db291b0d0558235820c32 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 03:37:19 +0000 Subject: [PATCH 2/9] docs: add lang support info for `rustfmt` --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 906548e651db..33e8f03a5593 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -188,6 +188,7 @@ | rst | ✓ | | | | | ruby | ✓ | ✓ | ✓ | `ruby-lsp`, `solargraph` | | rust | ✓ | ✓ | ✓ | `rust-analyzer` | +| rustfmt | ✓ | | | | | sage | ✓ | ✓ | | | | scala | ✓ | ✓ | ✓ | `metals` | | scheme | ✓ | | ✓ | | From aa0b1402421cd266b403c811eb9dbb562f7bf36c Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 03:43:19 +0000 Subject: [PATCH 3/9] feat: add `width` to operator highlights for rustfmt lang --- runtime/queries/rustfmt/highlights.scm | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/queries/rustfmt/highlights.scm b/runtime/queries/rustfmt/highlights.scm index 4018897db1d5..a213950ce3c2 100644 --- a/runtime/queries/rustfmt/highlights.scm +++ b/runtime/queries/rustfmt/highlights.scm @@ -11,6 +11,7 @@ (sign) (fill) (align) + (width) ] @operator (number) @constant.numeric From 1649e52bd413870063955f67ba11b3702f05be45 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 12:53:22 +0000 Subject: [PATCH 4/9] tree-sitter-0.25 --- Cargo.lock | 19 +++++++++++++++++-- Cargo.toml | 2 +- helix-core/Cargo.toml | 5 ++++- runtime/queries/rust/injections.scm | 20 +++++++++++++++++--- rust-toolchain.toml | 2 +- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c11a21584400..b10e9e2411bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2437,6 +2437,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9557cb6521e8d009c51a8666f09356f4b817ba9ba0981a305bd86aee47bd35c" +[[package]] +name = "streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" + [[package]] name = "syn" version = "2.0.87" @@ -2643,14 +2649,23 @@ dependencies = [ [[package]] name = "tree-sitter" -version = "0.22.6" +version = "0.24.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca" +checksum = "a5387dffa7ffc7d2dae12b50c6f7aab8ff79d6210147c6613561fc3d474c6f75" dependencies = [ "cc", "regex", + "regex-syntax", + "streaming-iterator", + "tree-sitter-language", ] +[[package]] +name = "tree-sitter-language" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38eee4db33814de3d004de9d8d825627ed3320d0989cce0dea30efaf5be4736c" + [[package]] name = "unicase" version = "2.7.0" diff --git a/Cargo.toml b/Cargo.toml index 762ec8fea19d..665ed75448b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ package.helix-tui.opt-level = 2 package.helix-term.opt-level = 2 [workspace.dependencies] -tree-sitter = { version = "0.22" } +tree-sitter = { version = "0.24" } nucleo = "0.5.0" slotmap = "1.0.7" thiserror = "2.0" diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 6903141b7a5b..96eea93c2151 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -52,7 +52,10 @@ imara-diff = "0.1.7" encoding_rs = "0.8" -chrono = { version = "0.4", default-features = false, features = ["alloc", "std"] } +chrono = { version = "0.4", default-features = false, features = [ + "alloc", + "std", +] } etcetera = "0.8" textwrap = "0.16.1" diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index 719d33afa279..04a119fea463 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -13,6 +13,20 @@ (#set! injection.language "html") (#set! injection.include-children)) +; std::fmt + +((macro_invocation + macro: + [ + (scoped_identifier + name: (_) @_macro_name) + (identifier) @_macro_name + ] + (token_tree . (string_literal) @injection.content)) + (#any-of? @_macro_name "format_args") + (#set! injection.language "rustfmt") + (#set! injection.include-children)) + ((macro_invocation macro: [ @@ -76,6 +90,6 @@ ) (#set! injection.language "sql")) -; TODO: change this so it injects into all strings within a macro call -((string_content) @injection.content - (#set! injection.language "rustfmt")) +; ; TODO: change this so it injects into all strings within a macro call +; ((string_content) @injection.content +; (#set! injection.language "rustfmt")) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 70e85c40b4af..74c6fc7a2d28 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.76.0" +channel = "1.82.0" components = ["rustfmt", "rust-src", "clippy"] From 44076a9a1a0c3623a542b4d19907539683f0746d Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 14:10:23 +0000 Subject: [PATCH 5/9] feat: inject `rustfmt` into Rust's standard library macros --- runtime/queries/rust/injections.scm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index 04a119fea463..24d0bccb2c53 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -22,8 +22,16 @@ name: (_) @_macro_name) (identifier) @_macro_name ] - (token_tree . (string_literal) @injection.content)) - (#any-of? @_macro_name "format_args") + (token_tree) @injection.content) + (#any-of? @_macro_name + "format" + "write" + "writeln" + "print" + "println" + "eprint" + "eprintln" + "format_args") (#set! injection.language "rustfmt") (#set! injection.include-children)) From 05fe31f1b19016fcc2a5f33c94b15aed31b49182 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 14:14:59 +0000 Subject: [PATCH 6/9] chore: remove unneeded changes --- Cargo.lock | 19 ++----------------- Cargo.toml | 2 +- helix-core/Cargo.toml | 5 +---- runtime/queries/rust/injections.scm | 4 ---- rust-toolchain.toml | 2 +- 5 files changed, 5 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b10e9e2411bf..c11a21584400 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2437,12 +2437,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9557cb6521e8d009c51a8666f09356f4b817ba9ba0981a305bd86aee47bd35c" -[[package]] -name = "streaming-iterator" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" - [[package]] name = "syn" version = "2.0.87" @@ -2649,23 +2643,14 @@ dependencies = [ [[package]] name = "tree-sitter" -version = "0.24.7" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5387dffa7ffc7d2dae12b50c6f7aab8ff79d6210147c6613561fc3d474c6f75" +checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca" dependencies = [ "cc", "regex", - "regex-syntax", - "streaming-iterator", - "tree-sitter-language", ] -[[package]] -name = "tree-sitter-language" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38eee4db33814de3d004de9d8d825627ed3320d0989cce0dea30efaf5be4736c" - [[package]] name = "unicase" version = "2.7.0" diff --git a/Cargo.toml b/Cargo.toml index 665ed75448b3..762ec8fea19d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ package.helix-tui.opt-level = 2 package.helix-term.opt-level = 2 [workspace.dependencies] -tree-sitter = { version = "0.24" } +tree-sitter = { version = "0.22" } nucleo = "0.5.0" slotmap = "1.0.7" thiserror = "2.0" diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 96eea93c2151..6903141b7a5b 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -52,10 +52,7 @@ imara-diff = "0.1.7" encoding_rs = "0.8" -chrono = { version = "0.4", default-features = false, features = [ - "alloc", - "std", -] } +chrono = { version = "0.4", default-features = false, features = ["alloc", "std"] } etcetera = "0.8" textwrap = "0.16.1" diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index 24d0bccb2c53..27aae70693b2 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -97,7 +97,3 @@ [(string_literal) (raw_string_literal)] @injection.content ) (#set! injection.language "sql")) - -; ; TODO: change this so it injects into all strings within a macro call -; ((string_content) @injection.content -; (#set! injection.language "rustfmt")) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 74c6fc7a2d28..70e85c40b4af 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.82.0" +channel = "1.76.0" components = ["rustfmt", "rust-src", "clippy"] From 17f43d4cb9a2a22f41b8c60fb3c7f33182801941 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 14:21:20 +0000 Subject: [PATCH 7/9] feat: add more crates to `rustfmt` injection --- runtime/queries/rust/injections.scm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index 27aae70693b2..490811c3b3fd 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -24,6 +24,7 @@ ] (token_tree) @injection.content) (#any-of? @_macro_name + ; std "format" "write" "writeln" @@ -31,7 +32,18 @@ "println" "eprint" "eprintln" - "format_args") + "format_args" + ; log + "crit" + "error" + "warn" + "info" + "debug" + "trace" + ; anyhow + "anyhow" + "bail" + "ensure") (#set! injection.language "rustfmt") (#set! injection.include-children)) From a98b433ab5c6d14dd7f6a2b20655ba6c261534bb Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 14:24:08 +0000 Subject: [PATCH 8/9] feat: remove `ensure!` macro --- runtime/queries/rust/injections.scm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index 490811c3b3fd..acc9a9cdfab6 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -42,8 +42,7 @@ "trace" ; anyhow "anyhow" - "bail" - "ensure") + "bail") (#set! injection.language "rustfmt") (#set! injection.include-children)) From 9ce5fd979444554ba3b4648f2a09b4f97b5fd548 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 4 Feb 2025 14:50:26 +0000 Subject: [PATCH 9/9] feat: remove ERROR highlight --- runtime/queries/rustfmt/highlights.scm | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/queries/rustfmt/highlights.scm b/runtime/queries/rustfmt/highlights.scm index a213950ce3c2..a4a99f999024 100644 --- a/runtime/queries/rustfmt/highlights.scm +++ b/runtime/queries/rustfmt/highlights.scm @@ -27,5 +27,3 @@ "{" "}" ] @punctuation.special - -(ERROR) @error