aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStuart Mashaal <stumash@users.noreply.github.com>2021-08-25 19:38:45 -0400
committerStephan Seitz <stephan.seitz@fau.de>2021-09-17 21:06:36 +0200
commit88d5356d61528cf5cadfc57756bc4038cc440564 (patch)
treefb94d9436d290193130447b1d6338f700bef79d5
parentAdd support for json5 (diff)
downloadnvim-treesitter-88d5356d61528cf5cadfc57756bc4038cc440564.tar
nvim-treesitter-88d5356d61528cf5cadfc57756bc4038cc440564.tar.gz
nvim-treesitter-88d5356d61528cf5cadfc57756bc4038cc440564.tar.bz2
nvim-treesitter-88d5356d61528cf5cadfc57756bc4038cc440564.tar.lz
nvim-treesitter-88d5356d61528cf5cadfc57756bc4038cc440564.tar.xz
nvim-treesitter-88d5356d61528cf5cadfc57756bc4038cc440564.tar.zst
nvim-treesitter-88d5356d61528cf5cadfc57756bc4038cc440564.zip
add keywords to scala highlights (#1662)
* add keywords to scala highlights * special capture for special keywords * add while to 'repeat' capture * pr cleanup, exmaples in CONTRIBUTING.md * add backquotes for consistency in docs * group @repeat keywords, fix null * comment-out 'macro' and 'forSome' * fix 'this' and 'super' keyword * remove accidental files :facepalm: * update revision * fix "super" and "this" * godammit these .metals files are killing me * why did I commit this??? Co-authored-by: Stuart Mashaal <smashaal@hopper.com>
-rw-r--r--CONTRIBUTING.md8
-rw-r--r--queries/scala/highlights.scm96
2 files changed, 100 insertions, 4 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index b5e214386..d75688df7 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -131,15 +131,15 @@ effect on highlighting. We will work on improving highlighting in the near futur
#### Keywords
```
-@conditional
-@repeat
+@conditional (e.g. `if`, `else`)
+@repeat (e.g. `for`, `while`)
@label for C/Lua-like labels
@keyword
-@keyword.function
+@keyword.function (keyword to define a function, e.g. `func` in Go, `def` in Python)
@keyword.operator (for operators that are English words, e.g. `and`, `or`)
@keyword.return
@operator (for symbolic operators, e.g. `+`, `*`)
-@exception
+@exception (e.g. `throw`, `catch`)
@include keywords for including modules (e.g. import/from in Python)
@type
diff --git a/queries/scala/highlights.scm b/queries/scala/highlights.scm
new file mode 100644
index 000000000..aecbdf487
--- /dev/null
+++ b/queries/scala/highlights.scm
@@ -0,0 +1,96 @@
+; CREDITS @stumash (stuart.mashaal@gmail.com)
+
+;; variables
+
+(
+ (identifier) @variable.builtin
+ (#match? @variable.builtin "^this$")
+)
+
+;; method calls
+
+; 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)))
+
+; method invocation
+(call_expression
+ function: (field_expression
+ field: (identifier) @method))
+
+(
+ (identifier) @function.builtin
+ (#match? @function.builtin "^super$")
+)
+
+;; keywords
+
+[
+ "abstract"
+ "case"
+ "class"
+ "extends"
+ "final"
+ "finally"
+;; `forSome` existential types not implemented yet
+ "implicit"
+ "lazy"
+;; `macro` not implemented yet
+ "object"
+ "override"
+ "package"
+ "private"
+ "protected"
+ "sealed"
+ "trait"
+ "type"
+ "val"
+ "var"
+ "with"
+] @keyword
+
+(null_literal) @keyword
+
+;; special keywords
+
+"new" @keyword.operator
+
+[
+ "else"
+ "if"
+ "match"
+] @conditional
+
+[
+ "do"
+ "for"
+ "while"
+ "yield"
+] @repeat
+
+"def" @keyword.function
+
+"import" @include
+
+[
+ "try"
+ "catch"
+ "throw"
+] @exception
+
+"return" @keyword.return
+
+;; `case` is a conditional keyword in case_block
+
+(case_block
+ (case_clause ("case") @conditional))