Skip to content

Commit

Permalink
Add fish highlighting (helix-editor#1308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flakebi authored Dec 21, 2021
1 parent f16651b commit 205dc87
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,7 @@
path = helix-syntax/languages/tree-sitter-dart
url = https://github.com/UserNobody14/tree-sitter-dart.git
shallow = true
[submodule "helix-syntax/languages/tree-sitter-fish"]
path = helix-syntax/languages/tree-sitter-fish
url = https://github.com/ram02z/tree-sitter-fish
shallow = true
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| css || | | |
| dart || || `dart` |
| elixir || | | `elixir-ls` |
| fish |||| |
| glsl || || |
| go |||| `gopls` |
| html || | | |
Expand Down
1 change: 1 addition & 0 deletions helix-syntax/languages/tree-sitter-fish
Submodule tree-sitter-fish added at 04e54a
11 changes: 11 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ comment-token = "#"
language-server = { command = "elixir-ls" }
indent = { tab-width = 2, unit = " " }

[[language]]
name = "fish"
scope = "source.fish"
injection-regex = "fish"
file-types = ["fish"]
shebangs = ["fish"]
roots = []
comment-token = "#"

indent = { tab-width = 4, unit = " " }

[[language]]
name = "mint"
scope = "source.mint"
Expand Down
156 changes: 156 additions & 0 deletions runtime/queries/fish/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
;; Operators

[
"&&"
"||"
"|"
"&"
"="
"!="
".."
"!"
(direction)
(stream_redirect)
(test_option)
] @operator

[
"not"
"and"
"or"
] @keyword.operator

;; Conditionals

(if_statement
[
"if"
"end"
] @keyword.control.conditional)

(switch_statement
[
"switch"
"end"
] @keyword.control.conditional)

(case_clause
[
"case"
] @keyword.control.conditional)

(else_clause
[
"else"
] @keyword.control.conditional)

(else_if_clause
[
"else"
"if"
] @keyword.control.conditional)

;; Loops/Blocks

(while_statement
[
"while"
"end"
] @keyword.control.repeat)

(for_statement
[
"for"
"end"
] @keyword.control.repeat)

(begin_statement
[
"begin"
"end"
] @keyword.control.repeat)

;; Keywords

[
"in"
(break)
(continue)
] @keyword

"return" @keyword.control.return

;; Punctuation

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

"," @punctuation.delimiter

;; Commands

(command
argument: [
(word) @variable.parameter (#match? @variable.parameter "^-")
]
)

; non-bultin command names
(command name: (word) @function)

; derived from builtin -n (fish 3.2.2)
(command
name: [
(word) @function.builtin
(#match? @function.builtin "^(\.|:|_|alias|argparse|bg|bind|block|breakpoint|builtin|cd|command|commandline|complete|contains|count|disown|echo|emit|eval|exec|exit|fg|functions|history|isatty|jobs|math|printf|pwd|random|read|realpath|set|set_color|source|status|string|test|time|type|ulimit|wait)$")
]
)

(test_command "test" @function.builtin)

;; Functions

(function_definition ["function" "end"] @keyword.function)

(function_definition
name: [
(word) (concatenation)
]
@function)

(function_definition
option: [
(word)
(concatenation (word))
] @variable.parameter (#match? @variable.parameter "^-")
)

;; Strings

[(double_quote_string) (single_quote_string)] @string
(escape_sequence) @constant.character.escape

;; Variables

(variable_name) @variable
(variable_expansion) @constant

;; Nodes

(integer) @constant.numeric.integer
(float) @constant.numeric.float
(comment) @comment
(test_option) @string

((word) @constant.builtin.boolean
(#match? @constant.builtin.boolean "^(true|false)$"))

;; Error

(ERROR) @error
12 changes: 12 additions & 0 deletions runtime/queries/fish/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
indent = [
"function_definition",
"while_statement",
"for_statement",
"if_statement",
"begin_statement",
"switch_statement",
]

outdent = [
"end"
]
2 changes: 2 additions & 0 deletions runtime/queries/fish/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))
1 change: 1 addition & 0 deletions runtime/queries/fish/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(function_definition) @function.around

0 comments on commit 205dc87

Please sign in to comment.