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(
field('type_parameters', optional($.type_parameters)),

@ -1,56 +1,60 @@
; 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
(identifier) @variable
(class_parameter
name: (identifier) @parameter)
((identifier) @variable.builtin
(#lua-match? @variable.builtin "^this$"))
(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
(type_definition
name: (type_identifier) @type.definition)
(type_identifier) @type
(class_definition
name: (identifier) @type)
(enum_definition
name: (identifier) @type)
;; val/var definitions/declarations
(object_definition
name: (identifier) @type)
(val_definition
pattern: (identifier) @variable)
(trait_definition
name: (identifier) @type)
(var_definition
pattern: (identifier) @variable)
(type_definition
name: (type_identifier) @type.definition)
(val_declaration
name: (identifier) @variable)
(var_declaration
name: (identifier) @variable)
; method definition
(class_definition
body: (template_body
(function_definition
name: (identifier) @method)))
(object_definition
body: (template_body
(function_definition
name: (identifier) @method)))
(trait_definition
body: (template_body
(function_definition
name: (identifier) @method)))
(function_declaration
name: (identifier) @method)
(function_definition
name: (identifier) @method)
; imports
@ -81,10 +85,11 @@
(generic_function
function: (identifier) @function.call)
(
(identifier) @function.builtin
(#lua-match? @function.builtin "^super$")
)
;; I think this is broken
; (
; (identifier) @function.builtin
; (#lua-match? @function.builtin "^super$")
; )
; function definitions
@ -143,12 +148,12 @@
"with"
"given"
"end"
"implicit"
] @keyword
[
"abstract"
"final"
"implicit"
"using"
"lazy"
"private"
@ -217,3 +222,8 @@
(case_block
(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