Update query highlights and add tests

pull/481/head
Anton Sviridov 2023-01-08 13:42:33 +07:00
parent f6bc02526a
commit c69a3eccc8
4 changed files with 105 additions and 41 deletions

@ -141,9 +141,9 @@ module.exports = grammar({
) )
), ),
simple_enum_case: $ => $.identifier, simple_enum_case: $ => field('name', $.identifier),
full_enum_case: $ => seq($.identifier, $._extended_enum_def), full_enum_case: $ => seq(field('name', $.identifier), $._extended_enum_def),
_extended_enum_def: $ => seq( _extended_enum_def: $ => seq(
field('type_parameters', optional($.type_parameters)), field('type_parameters', optional($.type_parameters)),

@ -1,56 +1,60 @@
; CREDITS @stumash (stuart.mashaal@gmail.com) ; CREDITS @stumash (stuart.mashaal@gmail.com)
(class_definition
name: (identifier) @type.definition)
(enum_definition
name: (identifier) @type.definition)
(object_definition
name: (identifier) @type.definition)
(trait_definition
name: (identifier) @type.definition)
(full_enum_case
name: (identifier) @type.definition)
(simple_enum_case
name: (identifier) @type.definition)
;; variables ;; variables
(identifier) @variable (class_parameter
name: (identifier) @parameter)
((identifier) @variable.builtin
(#lua-match? @variable.builtin "^this$"))
(interpolation) @none (interpolation) @none
; Assume other uppercase names constants.
; NOTE: In order to distinguish constants we highlight
; all the identifiers that are uppercased. But this solution
; is not suitable for all occurrences e.g. it will highlight
; an uppercased method as a constant if used with no params.
; Introducing highlighting for those specific cases, is probably
; best way to resolve the issue.
((identifier) @constant (#lua-match? @constant "^[A-Z]"))
;; types ;; types
(type_definition
name: (type_identifier) @type.definition)
(type_identifier) @type (type_identifier) @type
(class_definition
name: (identifier) @type)
(enum_definition ;; val/var definitions/declarations
name: (identifier) @type)
(object_definition (val_definition
name: (identifier) @type) pattern: (identifier) @variable)
(trait_definition (var_definition
name: (identifier) @type) pattern: (identifier) @variable)
(type_definition (val_declaration
name: (type_identifier) @type.definition) name: (identifier) @variable)
(var_declaration
name: (identifier) @variable)
; method definition ; method definition
(class_definition (function_declaration
body: (template_body name: (identifier) @method)
(function_definition
name: (identifier) @method))) (function_definition
(object_definition name: (identifier) @method)
body: (template_body
(function_definition
name: (identifier) @method)))
(trait_definition
body: (template_body
(function_definition
name: (identifier) @method)))
; imports ; imports
@ -81,10 +85,11 @@
(generic_function (generic_function
function: (identifier) @function.call) function: (identifier) @function.call)
( ;; I think this is broken
(identifier) @function.builtin ; (
(#lua-match? @function.builtin "^super$") ; (identifier) @function.builtin
) ; (#lua-match? @function.builtin "^super$")
; )
; function definitions ; function definitions
@ -143,12 +148,12 @@
"with" "with"
"given" "given"
"end" "end"
"implicit"
] @keyword ] @keyword
[ [
"abstract" "abstract"
"final" "final"
"implicit"
"using" "using"
"lazy" "lazy"
"private" "private"
@ -217,3 +222,8 @@
(case_block (case_block
(case_clause ("case") @conditional)) (case_clause ("case") @conditional))
((identifier) @constant (#lua-match? @constant "^[A-Z]"))
((identifier) @variable.builtin
(#lua-match? @variable.builtin "^this$"))

@ -0,0 +1,37 @@
object Hello {
// ^ keyword
// ^ type.definition
val x = if (true) (25 * 1.0) else "hello"
// ^keyword
// ^variable
// ^conditional
// ^boolean
// ^number
// ^float
// ^string
// ^conditional
trait Test {
// ^ keyword
// ^ type.definition
def meth(i: Int)(implicit x: Boolean) = ???
// ^keyword.function
// ^keyword
// ^type
// ^method
// ^parameter
}
protected abstract class Bla(test: String)
// ^type.qualifier
// ^keyword
// ^type.qualifier
// ^parameter
// ^type
type Hello = "25"
// ^keyword
// ^type.definition
// ^string
}

@ -0,0 +1,17 @@
enum Test(a: Int):
// ^keyword ^type
// ^type.definition
// ^parameter
case Test(b: String)
// ^keyword ^type
// ^type.definition
// ^parameter
case Hello, Bla
// ^type.definition
// ^type.definition
opaque type Blow <: Int = 25
// ^type.qualifier
// ^keyword
// ^type
// ^type.definition