scala-cli
scala-cli copied to clipboard
Syntax coloring for using directives in Metals
Is your feature request related to a problem? Please describe. Even though the using directives aren't currently a part of the Scala language standard, we'd like to have reasonable syntax coloring for it in the supported IDEs, among them - in Metals.
cc @tgodzik
This could be included via scala syntax or semantic tokens. Maybe it's actually easier in scala-syntax :thinking:
I'll take a look at vscode-scala-syntax https://github.com/scala/vscode-scala-syntax
So I will focus on the syntax highlight for comment-based syntax //> using ... because @romanowski mentioned
After many discussions, I get convinced to stick to the comment syntax for now. Usability gains with dropping special syntax for comments are small, and there is non-zero potential to confuse users. It also seems that early adopters of Scala CLI are content with comment-based syntax. https://contributors.scala-lang.org/t/pre-sip-using-directives/5700/16
Also, I realized that multiline using directive is also valid https://github.com/VirtusLab/using_directives/blob/4a4ca9c7c28eee58e4814b1abaad87348fdcbc03/src/main/java/com/virtuslab/using_directives/custom/Parser.java#L177-L193
//> using
//> oneKey ...
//> secondKey ...
//> thirdKey {
//> nestedKey1
//> nestedKey2
//> }
but I would leave it out of scope for now, because it's extremely difficult to capture (even I'm not sure it's possible) with the regex-based TextMate grammar as we can't tell what is the end of using directive with regex AFAIK. (it would be much easier if we have tokens that represent start and end of the directive).
Therefore, I'll focus on one-line, comment-based using directive like //> using scala 3.1.3.
Is there a something formal definition of using directive syntax? (Is it still valid https://contributors.scala-lang.org/t/pre-sip-using-directives/5700 except it's in //> ?)
UsingDirective ::= "using" (Setting | Settings)
Settings ::= "{" Setting { ";" Setting } [";"] "}"
Setting ::= Ident [Values | Settings]
Ident ::= ScalaIdent { “.” ScalaIdent }
Values ::= Value { "," Value} [","]
Value ::= stringLiteral | ["-"] numericLiteral | true | false
Therefore, I'll focus on one-line, comment-based using directive like //> using scala 3.1.3.
Yeah, let's not start too big, it would already be a nice improvement.
Is it still valid https://contributors.scala-lang.org/t/pre-sip-using-directives/5700 except it's in //>
Yes, grammar is the same it is only included in the comments. Under the hood, processing using directives is a 2 step process: first we extract the special comment, remove the comment markers and then parses it using the syntax above
Fixed by https://github.com/scala/vscode-scala-syntax/pull/237