Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment syntax highlighting support #9082

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ tree-sitter-astro = { git = "https://github.com/virchau13/tree-sitter-astro.git"
tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "7331995b19b8f8aba2d5e26deb51d2195c18bc94" }
tree-sitter-c = "0.20.1"
tree-sitter-clojure = { git = "https://github.com/prcastro/tree-sitter-clojure", branch = "update-ts" }
tree-sitter-comment = { git = "https://github.com/stsewd/tree-sitter-comment", rev = "aefcc2813392eb6ffe509aa0fc8b4e9b57413ee1" }
tree-sitter-c-sharp = { git = "https://github.com/tree-sitter/tree-sitter-c-sharp", rev = "dd5e59721a5f8dae34604060833902b882023aaf" }
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "f44509141e7e483323d2ec178f2d2e6c0fc041c1" }
tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" }
Expand Down
1 change: 1 addition & 0 deletions crates/languages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tree-sitter-bash.workspace = true
tree-sitter-c-sharp.workspace = true
tree-sitter-c.workspace = true
tree-sitter-clojure.workspace = true
tree-sitter-comment.workspace = true
tree-sitter-cpp.workspace = true
tree-sitter-css.workspace = true
tree-sitter-dart.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/languages/src/bash/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
7 changes: 7 additions & 0 deletions crates/languages/src/comment/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "Comment"
grammar = "comment"
path_suffixes = []
line_comments = []
brackets = [
{ start = "(", end = ")", close = true, newline = false }
]
75 changes: 75 additions & 0 deletions crates/languages/src/comment/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
; The highlight need to override the color yourself e.g.
; {
; "experimental.theme_overrides": {
; "syntax": {
; "hint": {
; "color": "#576cdbff",
; "font_style": "italic",
; "font_weight": 700
; },
; "info": {
; "color": "#36a165ff",
; "font_style": "oblique",
; "font_weight": 700
; },
; "error": {
; "color": "#d73837ff",
; "font_style": "oblique",
; "font_weight": 700
; },
; "warning": {
; "color": "#ae9414ff",
; "font_style": "italic",
; "font_weight": 700
; }
; }
; }
; }

[
"("
")"
] @punctuation.bracket

":" @punctuation.delimiter

(tag
(user)? @constant)

; Hint level tags
((tag (name) @hint)
(#match? @hint "^(HINT|MARK|PASSED|STUB|MOCK)$"))

("text" @hint
(#match? @hint "^(HINT|MARK|PASSED|STUB|MOCK)$"))

; Info level tags
((tag (name) @info)
(#match? @info "^(INFO|NOTE|TODO|PERF|OPTIMIZE|PERFORMANCE|QUESTION|ASK)$"))

("text" @info
(#match? @info "^(INFO|NOTE|TODO|PERF|OPTIMIZE|PERFORMANCE|QUESTION|ASK)$"))

; Warning level tags
((tag (name) @warning)
(#match? @warning "^(HACK|WARN|WARNING|TEST|TEMP)$"))

("text" @warning
(#match? @warning "^(HACK|WARN|WARNING|TEST|TEMP)$"))

; Error level tags
((tag (name) @error)
(#match? @error "^(BUG|FIXME|ISSUE|XXX|FIX|SAFETY|FIXIT|FAILED|DEBUG)$"))

("text" @error
(#match? @error "^(BUG|FIXME|ISSUE|XXX|FIX|SAFETY|FIXIT|FAILED|DEBUG)$"))

; Issue number (#123)
("text" @link_uri
(#match? @link_uri "^#[0-9]+$"))

; User mention (@user)
("text" @tag
(#match? @tag "^[@][a-zA-Z0-9_-]+$"))

(uri) @link_uri
2 changes: 2 additions & 0 deletions crates/languages/src/css/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/dart/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
9 changes: 4 additions & 5 deletions crates/languages/src/dockerfile/injections.scm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
; We need impl this
; ((comment) @injection.content
; (#set! injection.language "comment"))
([(shell_command) (shell_fragment)] @content
(#set! "language" "bash"))

((shell_command) @content
(#set! "language" "bash"))
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/go/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/gomod/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/gowork/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
3 changes: 3 additions & 0 deletions crates/languages/src/html/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
(style_element
(raw_text) @content
(#set! "language" "css"))

((comment) @content
(#set! "language" "comment"))
9 changes: 9 additions & 0 deletions crates/languages/src/javascript/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
((comment) @content
(#set! "language" "comment")
(#match? @content "^//"))

; https://github.com/helix-editor/helix/pull/2763
; Parse JSDoc annotations in multiline comments (#7826)
; ((comment) @content
; (#set! "language" "jsdoc")
; (#match? @content "^/\\*+"))
2 changes: 2 additions & 0 deletions crates/languages/src/json/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn init(
("dockerfile", tree_sitter_dockerfile::language()),
("elixir", tree_sitter_elixir::language()),
("elm", tree_sitter_elm::language()),
("comment", tree_sitter_comment::language()),
(
"embedded_template",
tree_sitter_embedded_template::language(),
Expand Down Expand Up @@ -168,6 +169,7 @@ pub fn init(
Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())),
]
);
language!("comment");
language!("bash");
language!("c", vec![Arc::new(c::CLspAdapter) as Arc<dyn LspAdapter>]);
language!("clojure", vec![Arc::new(clojure::ClojureLspAdapter)]);
Expand Down
2 changes: 2 additions & 0 deletions crates/languages/src/lua/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/python/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/ruby/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
5 changes: 4 additions & 1 deletion crates/languages/src/rust/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

(macro_rule
(token_tree) @content
(#set! "language" "rust"))
(#set! "language" "rust"))

([(line_comment) (block_comment)] @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/toml/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/tsx/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/typescript/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
2 changes: 2 additions & 0 deletions crates/languages/src/yaml/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @content
(#set! "language" "comment"))
Loading