From cd5dc8141334ce44a9119c6352dfa28f3035a13a Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Fri, 26 Nov 2021 09:43:03 +0800 Subject: [PATCH 1/9] Add tree-sitter-comment Fix #1164 --- .gitmodules | 4 ++++ helix-syntax/languages/tree-sitter-comment | 1 + runtime/queries/comment/highlights.scm | 25 ++++++++++++++++++++++ runtime/queries/python/injections.scm | 2 ++ runtime/queries/rust/injections.scm | 6 ++++++ runtime/queries/tsq/injections.scm | 2 ++ 6 files changed, 40 insertions(+) create mode 160000 helix-syntax/languages/tree-sitter-comment create mode 100644 runtime/queries/comment/highlights.scm create mode 100644 runtime/queries/python/injections.scm create mode 100644 runtime/queries/tsq/injections.scm diff --git a/.gitmodules b/.gitmodules index bf596bdc1cc4..0d4f007eec89 100644 --- a/.gitmodules +++ b/.gitmodules @@ -142,3 +142,7 @@ path = helix-syntax/languages/tree-sitter-perl url = https://github.com/ganezdragon/tree-sitter-perl shallow = true +[submodule "helix-syntax/languages/tree-sitter-comment"] + path = helix-syntax/languages/tree-sitter-comment + url = https://github.com/stsewd/tree-sitter-comment + shallow = true diff --git a/helix-syntax/languages/tree-sitter-comment b/helix-syntax/languages/tree-sitter-comment new file mode 160000 index 000000000000..5dd3c62f1bbe --- /dev/null +++ b/helix-syntax/languages/tree-sitter-comment @@ -0,0 +1 @@ +Subproject commit 5dd3c62f1bbe378b220fe16b317b85247898639e diff --git a/runtime/queries/comment/highlights.scm b/runtime/queries/comment/highlights.scm new file mode 100644 index 000000000000..8e182321bf5a --- /dev/null +++ b/runtime/queries/comment/highlights.scm @@ -0,0 +1,25 @@ +[ + "(" + ")" +] @punctuation.bracket + +":" @punctuation.delimiter + +(tag (name) @ui.text (user)? @constant) + +((tag ((name) @warning)) + (#any-of? @warning "TODO" "HACK" "WARNING")) + +("text" @warning + (#any-of? @warning "TODO" "HACK" "WARNING")) + +((tag ((name) @error)) + (#any-of? @error "FIXME" "XXX" "BUG")) + +("text" @error + (#any-of? @error "FIXME" "XXX" "BUG")) + +; Issue number (#123) +; ("text" @number (#lua-match? @number "^#[0-9]+$")) +; User mention (@user) +; ("text" @constant-numeric (#lua-match? @constant-numeric "^[@][a-zA-Z0-9_-]+$")) \ No newline at end of file diff --git a/runtime/queries/python/injections.scm b/runtime/queries/python/injections.scm new file mode 100644 index 000000000000..321c90add371 --- /dev/null +++ b/runtime/queries/python/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index 6035d4189ba9..c31694fa19e7 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -1,3 +1,9 @@ +((line_comment) @injection.content + (#set! injection.language "comment")) + +((block_comment) @injection.content + (#set! injection.language "comment")) + ((macro_invocation (token_tree) @injection.content) (#set! injection.language "rust") diff --git a/runtime/queries/tsq/injections.scm b/runtime/queries/tsq/injections.scm new file mode 100644 index 000000000000..321c90add371 --- /dev/null +++ b/runtime/queries/tsq/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) From ea5f397d21ff1fd6b30fd0934e7a602e247f29a5 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 16:40:40 -0600 Subject: [PATCH 2/9] fix precedence in tree-sitter-comment highlights connects https://github.com/helix-editor/helix/pull/1170 --- f.comment | 5 +++++ languages.toml | 6 ++++++ runtime/queries/comment/highlights.scm | 25 +++++++++++++++---------- 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 f.comment diff --git a/f.comment b/f.comment new file mode 100644 index 000000000000..b00203885be3 --- /dev/null +++ b/f.comment @@ -0,0 +1,5 @@ +This was originally reported in #123 by @alice & @bob + +TODO(rendering): font bug +HACK: hackhackhack +BUG: whoops! diff --git a/languages.toml b/languages.toml index 5326f9176c24..9a58ffe62d3e 100644 --- a/languages.toml +++ b/languages.toml @@ -405,3 +405,9 @@ file-types = ["rkt"] shebangs = ["racket"] comment-token = ";" language-server = { command = "racket", args = ["-l", "racket-langserver"] } + +[[language]] +name = "comment" +scope = "scope.comment" +roots = [] +file-types = ["comment"] diff --git a/runtime/queries/comment/highlights.scm b/runtime/queries/comment/highlights.scm index 8e182321bf5a..88685d59a1aa 100644 --- a/runtime/queries/comment/highlights.scm +++ b/runtime/queries/comment/highlights.scm @@ -5,21 +5,26 @@ ":" @punctuation.delimiter -(tag (name) @ui.text (user)? @constant) - -((tag ((name) @warning)) - (#any-of? @warning "TODO" "HACK" "WARNING")) +((tag (name) @warning) + (#match? @warning "^(TODO|HACK|WARNING)$")) ("text" @warning - (#any-of? @warning "TODO" "HACK" "WARNING")) + (#match? @warning "^(TODO|HACK|WARNING)$")) -((tag ((name) @error)) - (#any-of? @error "FIXME" "XXX" "BUG")) +((tag (name) @error) + (match? @error "^(FIXME|XXX|BUG)$")) ("text" @error - (#any-of? @error "FIXME" "XXX" "BUG")) + (match? @error "^(FIXME|XXX|BUG)$")) + +(tag + (name) @ui.text + (user)? @constant) ; Issue number (#123) -; ("text" @number (#lua-match? @number "^#[0-9]+$")) +("text" @constant.numeric + (#match? @constant.numeric "^#[0-9]+$")) + ; User mention (@user) -; ("text" @constant-numeric (#lua-match? @constant-numeric "^[@][a-zA-Z0-9_-]+$")) \ No newline at end of file +("text" @tag + (#match? @tag "^[@][a-zA-Z0-9_-]+$")) From 24a3b2dbc4262c68336fad68efef5b5e5836c1cc Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 16:52:34 -0600 Subject: [PATCH 3/9] set injection-regex for comment language --- languages.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/languages.toml b/languages.toml index 9a58ffe62d3e..921dfb94befc 100644 --- a/languages.toml +++ b/languages.toml @@ -411,3 +411,4 @@ name = "comment" scope = "scope.comment" roots = [] file-types = ["comment"] +injection-regex = "comment" From c6877a30bb7a6f1ea2cff7699c5e30fe5d7693a9 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 21:01:17 -0600 Subject: [PATCH 4/9] remove comment filetype --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 921dfb94befc..efe593f466de 100644 --- a/languages.toml +++ b/languages.toml @@ -410,5 +410,5 @@ language-server = { command = "racket", args = ["-l", "racket-langserver"] } name = "comment" scope = "scope.comment" roots = [] -file-types = ["comment"] +file-types = [] injection-regex = "comment" From aa311c52f6d08e6a4f8646eb1e658505e3456702 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 21:08:03 -0600 Subject: [PATCH 5/9] fix comment injections for neovim-style injections tags --- runtime/queries/glsl/injections.scm | 6 ++++-- runtime/queries/julia/injections.scm | 8 +++++--- runtime/queries/ledger/injections.scm | 4 ++-- runtime/queries/rust/injections.scm | 5 +---- runtime/queries/svelte/injections.scm | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/runtime/queries/glsl/injections.scm b/runtime/queries/glsl/injections.scm index 7d3323b16451..b01b8b4b07c7 100644 --- a/runtime/queries/glsl/injections.scm +++ b/runtime/queries/glsl/injections.scm @@ -1,3 +1,5 @@ -(preproc_arg) @glsl +((preproc_arg) @injection.content + (#set! injection.language "glsl")) -(comment) @comment +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/julia/injections.scm b/runtime/queries/julia/injections.scm index be2412c06d10..3cf7339fd03a 100644 --- a/runtime/queries/julia/injections.scm +++ b/runtime/queries/julia/injections.scm @@ -1,5 +1,7 @@ ; TODO: re-add when markdown is added. -; ((triple_string) @markdown -; (#offset! @markdown 0 3 0 -3)) +; ((triple_string) @injection.content +; (#offset! @injection.content 0 3 0 -3) +; (#set! injection.language "markdown")) -(comment) @comment +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/ledger/injections.scm b/runtime/queries/ledger/injections.scm index 2d9481414af8..c1714786fa25 100644 --- a/runtime/queries/ledger/injections.scm +++ b/runtime/queries/ledger/injections.scm @@ -1,2 +1,2 @@ -(comment) @comment -(note) @comment +([(comment) (note)] @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/rust/injections.scm b/runtime/queries/rust/injections.scm index c31694fa19e7..d8382e499b5e 100644 --- a/runtime/queries/rust/injections.scm +++ b/runtime/queries/rust/injections.scm @@ -1,7 +1,4 @@ -((line_comment) @injection.content - (#set! injection.language "comment")) - -((block_comment) @injection.content +([(line_comment) (block_comment)] @injection.content (#set! injection.language "comment")) ((macro_invocation diff --git a/runtime/queries/svelte/injections.scm b/runtime/queries/svelte/injections.scm index 266f4701613b..04e860cf0841 100644 --- a/runtime/queries/svelte/injections.scm +++ b/runtime/queries/svelte/injections.scm @@ -26,5 +26,5 @@ (#set! injection.language "typescript") ) -(comment) @comment - +((comment) @injection.content + (#set! injection.language "comment")) From 1086c57f20dfa4db2bf53073e067d8365f12e45f Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 21:08:43 -0600 Subject: [PATCH 6/9] add comment injections for elixir --- runtime/queries/elixir/injections.scm | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 runtime/queries/elixir/injections.scm diff --git a/runtime/queries/elixir/injections.scm b/runtime/queries/elixir/injections.scm new file mode 100644 index 000000000000..321c90add371 --- /dev/null +++ b/runtime/queries/elixir/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) From 97bec10dafdc2c13e8db45800496494597dc8803 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 21:09:28 -0600 Subject: [PATCH 7/9] remove f.comment --- f.comment | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 f.comment diff --git a/f.comment b/f.comment deleted file mode 100644 index b00203885be3..000000000000 --- a/f.comment +++ /dev/null @@ -1,5 +0,0 @@ -This was originally reported in #123 by @alice & @bob - -TODO(rendering): font bug -HACK: hackhackhack -BUG: whoops! From 6b89b2b3a09837a01a8049aa57bf993d7757f796 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 21:15:09 -0600 Subject: [PATCH 8/9] fix spacing in .gitmodules --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 01e6e46400fe..c7b813367edf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -145,7 +145,7 @@ [submodule "helix-syntax/languages/tree-sitter-comment"] path = helix-syntax/languages/tree-sitter-comment url = https://github.com/stsewd/tree-sitter-comment - shallow = true + shallow = true [submodule "helix-syntax/languages/tree-sitter-wgsl"] path = helix-syntax/languages/tree-sitter-wgsl url = https://github.com/szebniok/tree-sitter-wgsl From 4441b2ff8abe0b952811f55aba5c0012f04c0aff Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 18 Dec 2021 21:43:53 -0600 Subject: [PATCH 9/9] run 'cargo xtask docgen' --- 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 3255b9af30e6..cb91872bed59 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -4,6 +4,7 @@ | c | ✓ | | | `clangd` | | c-sharp | ✓ | | | | | cmake | ✓ | | | `cmake-language-server` | +| comment | ✓ | | | | | cpp | ✓ | | | `clangd` | | css | ✓ | | | | | dart | ✓ | | ✓ | `dart` |