zed-extensions / kotlin

Syntax highlighting for Kotlin in Zed.
MIT License
19 stars 9 forks source link

`hightlights.scm` failing to highlight many keywords, inconsistent with other language implementations #6

Closed spaceunifyfifty closed 3 months ago

spaceunifyfifty commented 5 months ago

The extension currently does not highlight keywords if,else,when,for,while,do,try,catch,throw,finally properly.

image

I have found this can be fixed by modifying the highlights.scm.

First, I noticed that the highlights.scm does not classify them as @keyword, but instead their own distinct classifications @conditional, @repeat, @exception

[
    "val"
    "var"
    "enum"
    "class"
    "object"
    "interface"
;   "typeof" ; NOTE: It is reserved for future use
] @keyword

("fun") @keyword.function

(jump_expression) @keyword.return

[
    "if"
    "else"
    "when"
] @conditional

[
    "for"
    "do"
    "while"
] @repeat

[
    "try"
    "catch"
    "throw"
    "finally"
] @exception

while the highlights.scm for TypeScript has all of them in the @keyword list and lacks @conditional,@repeat,@exception classification's entirely.

[
  "as"
  "async"
  "await"
  "break"
  "case"
  "catch"
  "class"
  "const"
  "continue"
  "debugger"
  "default"
  "delete"
  "do"
  "else"
  "export"
  "extends"
  "finally"
  "for"
  "from"
  "function"
  "get"
  "if"
  "import"
  "in"
  "instanceof"
  "let"
  "new"
  "of"
  "return"
  "satisfies"
  "set"
  "static"
  "switch"
  "target"
  "throw"
  "try"
  "typeof"
  "var"
  "void"
  "while"
  "with"
  "yield"
] @keyword

I have tested locally and found that if you add the tokens into the @keyword list and remove them from the @conditional,@repeat,@exception lists (and so removing those classifications entirely), syntax highlighting works.

image

This makes me suspect that the scheme file was incorrectly written, or that it relies on other parts of the extension that are not yet making use of the @conditional,@repeat,@exception identifiers. Why is it inconsistent with TypeScript's implementation?

nervenes commented 5 months ago

Hi, I take responsibility for this, I copied the scheme code from https://github.com/fwcd/tree-sitter-kotlin/tree/main/queries