nvim-treesitter/queries/fish/highlights.scm
Christian Clason 1ae9b0e455 feat!: align standard captures with upstream
Problem: Sharing highlight queries with upstream tree-sitter and
Helix is difficult.

Solution: Where reasonable, use capture names in tree-sitter's standard
list or Helix's Atom-style hierarchy.

Specifically:

* tree-sitter "standard capture names"
  (3f44b89685/highlight/src/lib.rs (L20-L72)):

  - `@parameter` -> `@variable.parameter`
  - `@field` -> `@variable.member`
  - `@namespace` -> `@module`
  - `@float` -> `@number.float`
  - `@symbol` -> `@string.special.symbol`
  - `@string.regex` -> `@string.regexp`
  - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below)
  - `@text.title` -> `@markup.heading`
  - `@text.literal` -> `@markup.raw`
  - `@text.reference` -> `@markup.link`
  - `@text.uri` -> `@markup.link.url` (in markup links)
  - `@string.special` -> `@markup.link.label` (non-url links)
  - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`)

* Helix captures
  (https://docs.helix-editor.com/master/themes.html#syntax-highlighting):

  - `@method` -> `@function.method`
  - `@method.call` -> `@function.method.call`
  - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}`
  - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}`
  - `@text.uri` -> `@string.special.url` (outside markup)
  - `@preproc` -> `@keyword.directive`
  - `@define` -> `@keyword.directive`(`.define`?)
  - `@storageclass` -> `@keyword.storage`
  - `@conditional` -> `@keyword.conditional`
  - `@debug` -> `@keyword.debug`
  - `@exception` -> `@keyword.exception`
  - `@include` -> `@keyword.import`
  - `@repeat` -> `@keyword.repeat`

* cleanup

  - remove some redundant `@conceal` (but still allow it for conceal-only patterns)
  - remove obsolete `@error` (syntax linting is out of scope for this repo)
  - sort, cleanup capture list in `CONTRIBUTING.md`
2024-01-19 16:58:37 +01:00

163 lines
2.6 KiB
Scheme

;; Fish highlighting
;; Operators
[
"&&"
"||"
"|"
"&"
".."
"!"
(direction)
(stream_redirect)
] @operator
;; match operators of test command
(command
name: (word) @function.builtin (#eq? @function.builtin "test")
argument: (word) @operator (#match? @operator "^(!?\\=|-[a-zA-Z]+)$"))
;; match operators of [ command
(command
name: (word) @punctuation.bracket (#eq? @punctuation.bracket "[")
argument: (word) @operator (#match? @operator "^(!?\\=|-[a-zA-Z]+)$"))
[
"not"
"and"
"or"
] @keyword.operator
;; Conditionals
(if_statement
[
"if"
"end"
] @keyword.conditional)
(switch_statement
[
"switch"
"end"
] @keyword.conditional)
(case_clause
[
"case"
] @keyword.conditional)
(else_clause
[
"else"
] @keyword.conditional)
(else_if_clause
[
"else"
"if"
] @keyword.conditional)
;; Loops/Blocks
(while_statement
[
"while"
"end"
] @keyword.repeat)
(for_statement
[
"for"
"end"
] @keyword.repeat)
(begin_statement
[
"begin"
"end"
] @keyword.repeat)
;; Keywords
[
"in"
(break)
(continue)
] @keyword
"return" @keyword.return
;; Punctuation
[
"["
"]"
"{"
"}"
"("
")"
] @punctuation.bracket
"," @punctuation.delimiter
;; Commands
(command
argument: [
(word) @variable.parameter (#lua-match? @variable.parameter "^[-]")
]
)
(command_substitution "$" @punctuation.bracket)
; non-builtin command names
(command name: (word) @function.call)
; derived from builtin -n (fish 3.2.2)
(command
name: [
(word) @function.builtin
(#any-of? @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")
]
)
;; Functions
(function_definition ["function" "end"] @keyword.function)
(function_definition
name: [
(word) (concatenation)
]
@function)
(function_definition
option: [
(word)
(concatenation (word))
] @variable.parameter (#lua-match? @variable.parameter "^[-]")
)
;; Strings
[(double_quote_string) (single_quote_string)] @string
(escape_sequence) @string.escape
;; Variables
(variable_name) @variable
(variable_expansion) @constant
;; Nodes
[(integer) (float)] @number
(comment) @comment
(comment) @spell
((word) @boolean
(#any-of? @boolean "true" "false"))
((program . (comment) @keyword.directive)
(#lua-match? @keyword.directive "^#!/"))