Update Clojure highlights to be metadata aware (#6213)

This commit is contained in:
Noah 2024-03-19 17:10:41 -04:00 committed by GitHub
parent 567a76780c
commit 03f650705c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 99 additions and 30 deletions

View file

@ -77,7 +77,10 @@
; Inline function variables ; Inline function variables
((sym_lit) @variable.builtin ((sym_lit) @variable.builtin
(#lua-match? @variable.builtin "^%%")) (#lua-match? @variable.builtin "^%%%d*$"))
((sym_lit) @variable.builtin
(#eq? @variable.builtin "%&"))
; Constructor ; Constructor
((sym_lit) @constructor ((sym_lit) @constructor
@ -98,39 +101,39 @@
((sym_lit) @variable.builtin ((sym_lit) @variable.builtin
(#any-of? @variable.builtin "*1" "*2" "*3" "*e")) (#any-of? @variable.builtin "*1" "*2" "*3" "*e"))
; Gensym
; Might not be needed
((sym_lit) @variable
(#lua-match? @variable "^.*#$"))
; Types ; Types
; TODO: improve? (sym_lit
((sym_lit) @type name: (sym_name) @_name
(#lua-match? @type "^[%u][^/]*$")) (#lua-match? @_name "^[%u][^/%s]*$")) @type
; Symbols with `.` but not `/` ; Symbols with `.` but not `/`
((sym_lit) @type (sym_lit
(#lua-match? @type "^[^/]+[.][^/]*$")) !namespace
name: (sym_name) @_name
(#lua-match? @_name "^[^.]+[.]")) @type
; Interop ; Interop
; (.instanceMember instance args*) ; (.instanceMember instance args*)
; (.instanceMember Classname args*) ; (.instanceMember Classname args*)
((sym_lit) @function.method ((sym_lit
(#lua-match? @function.method "^%.[^-]")) name: (sym_name) @_name) @function.method
(#lua-match? @_name "^%.[^-]"))
; (.-instanceField instance) ; (.-instanceField instance)
((sym_lit) @variable.member ((sym_name) @variable.member
(#lua-match? @variable.member "^%.%-.*")) (#lua-match? @variable.member "^%.%-%S*"))
; Classname/staticField ; Classname/staticField
((sym_lit) @variable.member (sym_lit
(#lua-match? @variable.member "^[%u].*/.+")) namespace: (sym_ns) @_namespace
(#lua-match? @_namespace "^[%u]%S*$")) @variable.member
; (Classname/staticMethod args*) ; (Classname/staticMethod args*)
(list_lit (list_lit
. .
(sym_lit) @function.method (sym_lit
(#lua-match? @function.method "^[%u].*/.+")) namespace: (sym_ns) @_namespace
(#lua-match? @_namespace "^%u")) @function.method)
; TODO: Special casing for the `.` macro ; TODO: Special casing for the `.` macro
; Operators ; Operators
@ -154,12 +157,13 @@
"alts!" "alts!!" "await" "await-for" "await1" "chan" "close!" "future" "go" "sync" "thread" "alts!" "alts!!" "await" "await-for" "await1" "chan" "close!" "future" "go" "sync" "thread"
"timeout" "<!" "<!!" ">!" ">!!")) "timeout" "<!" "<!!" ">!" ">!!"))
((sym_lit) @keyword.function ((sym_lit
(#any-of? @keyword.function "defn" "defn-" "fn" "fn*")) name: (sym_name) @_keyword.function.name) @keyword.function
(#any-of? @_keyword.function.name "defn" "defn-" "fn" "fn*"))
; Comment ; Comment
((sym_lit) @comment ((sym_lit) @comment
(#any-of? @comment "comment")) (#eq? @comment "comment"))
; Conditionals ; Conditionals
((sym_lit) @keyword.conditional ((sym_lit) @keyword.conditional
@ -185,7 +189,8 @@
; Builtin macros ; Builtin macros
; TODO: Do all these items belong here? ; TODO: Do all these items belong here?
((sym_lit) @function.macro ((sym_lit
name: (sym_name) @function.macro)
(#any-of? @function.macro (#any-of? @function.macro
"." ".." "->" "->>" "amap" "areduce" "as->" "assert" "binding" "bound-fn" "delay" "do" "dosync" "." ".." "->" "->>" "amap" "areduce" "as->" "assert" "binding" "bound-fn" "delay" "do" "dosync"
"doto" "extend-protocol" "extend-type" "gen-class" "gen-interface" "io!" "lazy-cat" "lazy-seq" "doto" "extend-protocol" "extend-type" "gen-class" "gen-interface" "io!" "lazy-cat" "lazy-seq"
@ -200,7 +205,8 @@
; sort ; sort
; clojure.pprint/pprint)) ; clojure.pprint/pprint))
; ...and then lots of manual filtering... ; ...and then lots of manual filtering...
((sym_lit) @function.builtin ((sym_lit
name: (sym_name) @function.builtin)
(#any-of? @function.builtin (#any-of? @function.builtin
"->ArrayChunk" "->Eduction" "->Vec" "->VecNode" "->VecSeq" "-cache-protocol-fn" "-reset-methods" "->ArrayChunk" "->Eduction" "->Vec" "->VecNode" "->VecSeq" "-cache-protocol-fn" "-reset-methods"
"PrintWriter-on" "StackTraceElement->vec" "Throwable->map" "accessor" "aclone" "add-classpath" "PrintWriter-on" "StackTraceElement->vec" "Throwable->map" "accessor" "aclone" "add-classpath"
@ -299,8 +305,9 @@
; Function definitions ; Function definitions
(list_lit (list_lit
. .
(sym_lit) @_keyword.function ((sym_lit
(#any-of? @_keyword.function "fn" "fn*" "defn" "defn-") name: (sym_name) @_keyword.function.name)
(#any-of? @_keyword.function.name "defn" "defn-" "fn" "fn*"))
. .
(sym_lit)? @function (sym_lit)? @function
. .

View file

@ -13,10 +13,14 @@
;^^^^ @function.call ;^^^^ @function.call
; ^^^ @variable ; ^^^ @variable
#(+ % %1 %&) #(+ % %1 %& %a)
;^ @punctuation.special ;^ @punctuation.special
; ^ @function.call ; ^ @function.call
; ^ ^^ ^^ @variable.builtin ; ^ ^^ ^^ @variable.builtin
; ^^ @variable
abc#
;^^^^ @variable
& &
;^ @variable.parameter ;^ @variable.parameter
@ -30,13 +34,16 @@
*1 *2 *3 *e *1 *2 *3 *e
;^^ ^^ ^^ ^^ @variable.builtin ;^^ ^^ ^^ ^^ @variable.builtin
(.method) .method
;^^^^^^^ @function.method ;^^^^^^^ @function.method
(.-field) (.method foo)
;^^^^^^^ @function.method
(.-field foo)
;^^^^^^^ @variable.member ;^^^^^^^ @variable.member
Abc/method Abc/member
;^^^^^^^^^^ @variable.member ;^^^^^^^^^^ @variable.member
(Abc/method) (Abc/method)
@ -50,3 +57,58 @@
^abc ^abc
;^ @punctuation.special ;^ @punctuation.special
^java.io.File file
; <- @punctuation.special
;^^^^^^^^^^^^ @type
; ^^^^ @variable
^java.io.File java.io.File.
; <- @punctuation.special
;^^^^^^^^^^^^ @type
; ^^^^ @variable
^java.io.File file.
; <- @punctuation.special
;^^^^^^^^^^^^ @type
; ^^^^ @variable
(^java.io.File file)
;^ @punctuation.special
; ^^^^^^^^^^^^ @type
; ^^^^ @function.call
(^java.io.File .file foo)
;^ @punctuation.special
; ^^^^^^^^^^^^ @type
; ^^^^ @function.method
; ^^^@variable
(^java.io.File .-file foo)
;^ @punctuation.special
; ^^^^^^^^^^^^ @type
; ^^^^ @variable.member
; ^^^@variable
(^java.io.File Abc/method foo)
;^ @punctuation.special
; ^^^^^^^^^^^^ @type
; ^^^^^^^^^^ @function.method
; ^^^ @variable
(defn foo [arg1] (+ arg1 1))
;^ ^ ^ ^ ^^ @punctuation.bracket
; ^^^^ @keyword.function
; ^^^ @function
; ^^^^ ^^^^ @variable
; ^ @operator
; ^ @number
clojure.core/dfn
;^^^^^^^^^^^^^^^^ @variable
clojure.core/defn
;^^^^^^^^^^^^^^^^ @keyword.function
any-ns/defn
;^^^^^^^^^^^ @keyword.function