nvim-treesitter/queries/typescript/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

153 lines
3 KiB
Scheme

; inherits: ecma
"require" @keyword.import
(import_require_clause source: (string) @string.special.url)
[
"declare"
"enum"
"export"
"implements"
"interface"
"type"
"namespace"
"override"
"module"
"asserts"
"infer"
"is"
] @keyword
[
"keyof"
"satisfies"
] @keyword.operator
(as_expression "as" @keyword.operator)
(export_statement "as" @keyword.operator)
(mapped_type_clause "as" @keyword.operator)
[
"abstract"
"private"
"protected"
"public"
"readonly"
] @type.qualifier
; types
(type_identifier) @type
(predefined_type) @type.builtin
(import_statement "type"
(import_clause
(named_imports
((import_specifier
name: (identifier) @type)))))
(template_literal_type) @string
(non_null_expression "!" @operator)
;; punctuation
(type_arguments
["<" ">"] @punctuation.bracket)
(type_parameters
["<" ">"] @punctuation.bracket)
(object_type
["{|" "|}"] @punctuation.bracket)
(union_type
"|" @punctuation.delimiter)
(intersection_type
"&" @punctuation.delimiter)
(type_annotation
":" @punctuation.delimiter)
(type_predicate_annotation
":" @punctuation.delimiter)
(index_signature
":" @punctuation.delimiter)
(omitting_type_annotation
"-?:" @punctuation.delimiter)
(opting_type_annotation
"?:" @punctuation.delimiter)
"?." @punctuation.delimiter
(abstract_method_signature "?" @punctuation.special)
(method_signature "?" @punctuation.special)
(method_definition "?" @punctuation.special)
(property_signature "?" @punctuation.special)
(optional_parameter "?" @punctuation.special)
(optional_type "?" @punctuation.special)
(public_field_definition [ "?" "!" ] @punctuation.special)
(flow_maybe_type "?" @punctuation.special)
(template_type ["${" "}"] @punctuation.special)
(conditional_type ["?" ":"] @keyword.conditional.ternary)
;;; Parameters
(required_parameter (identifier) @variable.parameter)
(optional_parameter (identifier) @variable.parameter)
(required_parameter
(rest_pattern
(identifier) @variable.parameter))
;; ({ a }) => null
(required_parameter
(object_pattern
(shorthand_property_identifier_pattern) @variable.parameter))
;; ({ a = b }) => null
(required_parameter
(object_pattern
(object_assignment_pattern
(shorthand_property_identifier_pattern) @variable.parameter)))
;; ({ a: b }) => null
(required_parameter
(object_pattern
(pair_pattern
value: (identifier) @variable.parameter)))
;; ([ a ]) => null
(required_parameter
(array_pattern
(identifier) @variable.parameter))
;; a => null
(arrow_function
parameter: (identifier) @variable.parameter)
;; global declaration
(ambient_declaration "global" @module)
;; function signatures
(ambient_declaration
(function_signature
name: (identifier) @function))
;; method signatures
(method_signature name: (_) @function.method)
;; property signatures
(property_signature
name: (property_identifier) @function.method
type: (type_annotation
[
(union_type (parenthesized_type (function_type)))
(function_type)
]))