mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 19:00:02 -04:00
Revamp the symbol highlighting
This commit is contained in:
parent
b8b0da006b
commit
16a06b30c2
1 changed files with 106 additions and 83 deletions
|
|
@ -20,109 +20,133 @@
|
||||||
|
|
||||||
;; >> Symbols
|
;; >> Symbols
|
||||||
|
|
||||||
; parameter-related
|
; General symbol highlighting
|
||||||
|
(sym_lit) @variable
|
||||||
|
|
||||||
|
; General function calls
|
||||||
|
(list_lit
|
||||||
|
.
|
||||||
|
(sym_lit) @function)
|
||||||
|
|
||||||
|
; Quoted symbols
|
||||||
|
(quoting_lit
|
||||||
|
(sym_lit) @symbol)
|
||||||
|
(syn_quoting_lit
|
||||||
|
(sym_lit) @symbol)
|
||||||
|
|
||||||
|
; Used in destructure pattern
|
||||||
((sym_lit) @parameter
|
((sym_lit) @parameter
|
||||||
(#match? @parameter "^[&]"))
|
(#match? @parameter "^[&]"))
|
||||||
|
|
||||||
|
; Inline function variables
|
||||||
((sym_lit) @variable.builtin
|
((sym_lit) @variable.builtin
|
||||||
(#match? @variable.builtin "^[%]"))
|
(#match? @variable.builtin "^[%]"))
|
||||||
|
|
||||||
;; TODO: General symbol highlighting
|
; Constants
|
||||||
;; use @variable?
|
;; TODO: Improve?
|
||||||
;((sym_lit) @symbol
|
;; - Mark all symbols as constants?
|
||||||
; (#not-eq? @symbol @variable))
|
;; - Remove, just use @variable?
|
||||||
|
((sym_lit) @constant
|
||||||
|
(#match? @constant "^[A-Z_-]+$"))
|
||||||
|
|
||||||
;; dynamic variables
|
; Constructor
|
||||||
|
((sym_lit) @constructor
|
||||||
|
(#match? @constructor "^-\\>[^\\>].*"))
|
||||||
|
|
||||||
|
; Dynamic variables
|
||||||
((sym_lit) @variable.builtin
|
((sym_lit) @variable.builtin
|
||||||
(#match? @variable.builtin "^[*].+[*]$"))
|
(#match? @variable.builtin "^[*].+[*]$"))
|
||||||
|
|
||||||
;; gensym
|
; Gensym
|
||||||
|
;; TODO: is this needed?
|
||||||
((sym_lit) @variable
|
((sym_lit) @variable
|
||||||
(#match? @variable "^.*#$"))
|
(#match? @variable "^.*#$"))
|
||||||
|
|
||||||
|
; Types
|
||||||
|
;; TODO: improve?
|
||||||
|
;; - symbols with `.` but not `/`?
|
||||||
|
((sym_lit) @type
|
||||||
|
(#match? @type "^[A-Z][^/]*$"))
|
||||||
|
|
||||||
|
; Interop
|
||||||
;; >> Functions
|
((sym_lit) @method
|
||||||
;; TODO: Enforce function-like things are the first thing in a list?
|
(#match? @method "^\\.[^-]"))
|
||||||
|
((sym_lit) @field
|
||||||
;; def & fn
|
(#match? @field "^\\.-"))
|
||||||
; TODO: fix it so that meta isn't marked as @function
|
((sym_lit) @field
|
||||||
; e.g (fn ^:meta name [a] a) marks `^:meta` as @function
|
(#match? @field "^[A-Z].*/.+"))
|
||||||
(list_lit
|
|
||||||
.
|
|
||||||
(sym_lit) @keyword.function
|
|
||||||
(#match? @keyword.function "^(fn|fn[*]|def.*)$")
|
|
||||||
.
|
|
||||||
(sym_lit)? @function
|
|
||||||
.
|
|
||||||
;; This marks strings twice, should probably fix 🤔
|
|
||||||
(str_lit)? @text
|
|
||||||
.
|
|
||||||
;; TODO: Get working
|
|
||||||
[(vec_lit
|
|
||||||
(sym_lit) @parameter)
|
|
||||||
(list_lit
|
|
||||||
(vec_lit
|
|
||||||
(sym_lit) @parameter))+]?)
|
|
||||||
|
|
||||||
|
|
||||||
;; namespaces
|
|
||||||
;; TODO
|
|
||||||
;(list_lit
|
|
||||||
; .
|
|
||||||
; (sym_lit) @keyword.function
|
|
||||||
; (#match? @keyword.function "^(declare|def.*|ns)$")
|
|
||||||
; .
|
|
||||||
; (sym_lit) @function)
|
|
||||||
|
|
||||||
;; TODO: symbols with `.`, mark them as namespaces?
|
|
||||||
|
|
||||||
;; operators
|
|
||||||
((sym_lit) @operator
|
|
||||||
(#any-of? @operator
|
|
||||||
"*" "*'" "+" "+'" "-" "-'" "/"
|
|
||||||
"<" "<=" ">" ">=" "=" "==" "not" "not="))
|
|
||||||
|
|
||||||
;; Ordinary calls
|
|
||||||
;; TODO
|
|
||||||
;; Do this by having a big scope with all symbols in it and
|
|
||||||
;; use `#not-eq? @myvar @parameter etc`
|
|
||||||
;; NOTE: That's a big hack
|
|
||||||
|
|
||||||
;; Ordinary calls
|
|
||||||
;; TODO
|
|
||||||
;; Do this by having a big scope with all symbols in it and
|
|
||||||
;; use `#not-eq? @myvar @parameter etc`
|
|
||||||
|
|
||||||
;; Interop
|
|
||||||
(list_lit
|
(list_lit
|
||||||
.
|
.
|
||||||
(sym_lit) @method
|
(sym_lit) @method
|
||||||
(#match? @method "^\\."))
|
(#match? @method "^[A-Z].*/.+"))
|
||||||
|
;; TODO: Special casing for the `.` macro
|
||||||
|
|
||||||
;; other macros
|
; Operators
|
||||||
|
((sym_lit) @operator
|
||||||
|
(#any-of? @operator
|
||||||
|
"*" "*'" "+" "+'" "-" "-'" "/"
|
||||||
|
"<" "<=" ">" ">=" "=" "=="))
|
||||||
|
((sym_lit) @keyword.operator
|
||||||
|
(#any-of? @keyword.operator
|
||||||
|
"not" "not=" "and" "or"))
|
||||||
|
|
||||||
|
; Definition functions
|
||||||
|
((sym_lit) @keyword
|
||||||
|
(#match? @keyword "^def.*$"))
|
||||||
|
((sym_lit) @keyword
|
||||||
|
(#eq? @keyword "declare"))
|
||||||
|
((sym_lit) @keyword.function
|
||||||
|
(#match? @keyword.function "^(defn|defn-|fn|fn[*])$"))
|
||||||
|
|
||||||
|
; Comment
|
||||||
|
((sym_lit) @comment
|
||||||
|
(#any-of? @comment "comment" "quote"))
|
||||||
|
|
||||||
|
; Conditionals
|
||||||
|
((sym_lit) @conditional
|
||||||
|
(#any-of? @conditional
|
||||||
|
"case" "cond" "cond->" "cond->>" "condp"))
|
||||||
|
((sym_lit) @conditional
|
||||||
|
(#match? @conditional "^if(\\-.*)?$"))
|
||||||
|
((sym_lit) @conditional
|
||||||
|
(#match? @conditional "^when(\\-.*)?$"))
|
||||||
|
|
||||||
|
; Repeats
|
||||||
|
((sym_lit) @repeat
|
||||||
|
(#any-of? @repeat
|
||||||
|
"doseq" "dotimes" "for" "loop" "recur" "while"))
|
||||||
|
|
||||||
|
; Exception
|
||||||
|
((sym_lit) @exception
|
||||||
|
(#any-of? @exception
|
||||||
|
"throw" "try" "catch" "finally" "ex-info"))
|
||||||
|
|
||||||
|
; Includes
|
||||||
|
((sym_lit) @include
|
||||||
|
(#any-of? @include "ns" "import" "require" "use"))
|
||||||
|
|
||||||
|
; Builtin macros
|
||||||
|
;; TODO: Do all these items belong here?
|
||||||
((sym_lit) @function.macro
|
((sym_lit) @function.macro
|
||||||
(#any-of? @function.macro
|
(#any-of? @function.macro
|
||||||
"." ".." "->" "->>" "amap" "and" "areduce" "as->" "assert"
|
"." ".." "->" "->>" "amap" "areduce" "as->" "assert"
|
||||||
"binding" "bound-fn" "case" "catch" "comment" "cond" "cond->"
|
"binding" "bound-fn" "delay" "do" "dosync"
|
||||||
"cond->>" "condp" "delay" "do" "doseq" "dosync" "dotimes"
|
"doto" "extend-protocol" "extend-type" "future"
|
||||||
"doto" "extend-protocol" "extend-type" "finally"
|
"gen-class" "gen-interface" "io!" "lazy-cat"
|
||||||
"for" "future" "gen-class" "gen-interface" "if" "if-let"
|
"lazy-seq" "let" "letfn" "locking" "memfn" "monitor-enter"
|
||||||
"if-not" "if-some" "import" "io!" "lazy-cat" "lazy-seq" "let"
|
"monitor-exit" "proxy" "proxy-super" "pvalues"
|
||||||
"letfn" "locking" "loop" "memfn" "monitor-enter" "monitor-exit"
|
|
||||||
"or" "proxy" "proxy-super" "pvalues" "quote" "recur"
|
|
||||||
"refer-clojure" "reify" "set!" "some->" "some->>" "sync"
|
"refer-clojure" "reify" "set!" "some->" "some->>" "sync"
|
||||||
"throw" "time" "try" "unquote" "unquote-splicing" "var"
|
"time" "unquote" "unquote-splicing" "var" "vswap!"
|
||||||
"vswap!" "while"))
|
"ex-cause" "ex-data" "ex-message"))
|
||||||
|
|
||||||
((sym_lit) @function.macro
|
|
||||||
(#match? @function.macro "^when(\\-.+)$"))
|
|
||||||
|
|
||||||
((sym_lit) @function.macro
|
((sym_lit) @function.macro
|
||||||
(#match? @function.macro "^with\\-.*$"))
|
(#match? @function.macro "^with\\-.*$"))
|
||||||
|
|
||||||
;; clojure.core=> (cp/pprint (sort (keep (fn [[s v]] (when-not (:macro (meta v)) s)) (ns-publics *ns*))))
|
; All builtin functions
|
||||||
;; ...and then some manual filtering...
|
; (->> (ns-publics *ns*)
|
||||||
|
; (keep (fn [[s v]] (when-not (:macro (meta v)) s)))
|
||||||
|
; sort
|
||||||
|
; cp/print))
|
||||||
|
;; ...and then lots of manual filtering...
|
||||||
((sym_lit) @function.builtin
|
((sym_lit) @function.builtin
|
||||||
(#any-of? @function.builtin
|
(#any-of? @function.builtin
|
||||||
"->ArrayChunk" "->Eduction" "->Vec" "->VecNode" "->VecSeq"
|
"->ArrayChunk" "->Eduction" "->Vec" "->VecNode" "->VecSeq"
|
||||||
|
|
@ -156,8 +180,7 @@
|
||||||
"dissoc!" "distinct" "distinct?" "doall" "dorun" "double"
|
"dissoc!" "distinct" "distinct?" "doall" "dorun" "double"
|
||||||
"double-array" "eduction" "empty" "empty?" "ensure" "ensure-reduced"
|
"double-array" "eduction" "empty" "empty?" "ensure" "ensure-reduced"
|
||||||
"enumeration-seq" "error-handler" "error-mode" "eval"
|
"enumeration-seq" "error-handler" "error-mode" "eval"
|
||||||
"even?" "every-pred" "every?" "ex-cause" "ex-data"
|
"even?" "every-pred" "every?" "extend" "extenders" "extends?"
|
||||||
"ex-info" "ex-message" "extend" "extenders" "extends?"
|
|
||||||
"false?" "ffirst" "file-seq" "filter" "filterv" "find"
|
"false?" "ffirst" "file-seq" "filter" "filterv" "find"
|
||||||
"find-keyword" "find-ns" "find-protocol-impl"
|
"find-keyword" "find-ns" "find-protocol-impl"
|
||||||
"find-protocol-method" "find-var" "first" "flatten"
|
"find-protocol-method" "find-var" "first" "flatten"
|
||||||
|
|
@ -203,7 +226,7 @@
|
||||||
"ref-max-history" "ref-min-history" "ref-set" "refer"
|
"ref-max-history" "ref-min-history" "ref-set" "refer"
|
||||||
"release-pending-sends" "rem" "remove" "remove-all-methods"
|
"release-pending-sends" "rem" "remove" "remove-all-methods"
|
||||||
"remove-method" "remove-ns" "remove-tap" "remove-watch"
|
"remove-method" "remove-ns" "remove-tap" "remove-watch"
|
||||||
"repeat" "repeatedly" "replace" "replicate" "require"
|
"repeat" "repeatedly" "replace" "replicate"
|
||||||
"requiring-resolve" "reset!" "reset-meta!" "reset-vals!"
|
"requiring-resolve" "reset!" "reset-meta!" "reset-vals!"
|
||||||
"resolve" "rest" "restart-agent" "resultset-seq" "reverse"
|
"resolve" "rest" "restart-agent" "resultset-seq" "reverse"
|
||||||
"reversible?" "rseq" "rsubseq" "run!" "satisfies?"
|
"reversible?" "rseq" "rsubseq" "run!" "satisfies?"
|
||||||
|
|
@ -231,7 +254,7 @@
|
||||||
"unchecked-remainder-int" "unchecked-short" "unchecked-subtract"
|
"unchecked-remainder-int" "unchecked-short" "unchecked-subtract"
|
||||||
"unchecked-subtract-int" "underive" "unquote"
|
"unchecked-subtract-int" "underive" "unquote"
|
||||||
"unquote-splicing" "unreduced" "unsigned-bit-shift-right"
|
"unquote-splicing" "unreduced" "unsigned-bit-shift-right"
|
||||||
"update" "update-in" "update-proxy" "uri?" "use" "uuid?"
|
"update" "update-in" "update-proxy" "uri?" "uuid?"
|
||||||
"val" "vals" "var-get" "var-set" "var?" "vary-meta" "vec"
|
"val" "vals" "var-get" "var-set" "var?" "vary-meta" "vec"
|
||||||
"vector" "vector-of" "vector?" "volatile!" "volatile?"
|
"vector" "vector-of" "vector?" "volatile!" "volatile?"
|
||||||
"vreset!" "with-bindings*" "with-meta" "with-redefs-fn" "xml-seq"
|
"vreset!" "with-bindings*" "with-meta" "with-redefs-fn" "xml-seq"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue