scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Syntax coloring for using directives in Metals

Open Gedochao opened this issue 3 years ago • 6 comments

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.

Gedochao avatar Jun 01 '22 12:06 Gedochao

cc @tgodzik

romanowski avatar Jun 01 '22 14:06 romanowski

This could be included via scala syntax or semantic tokens. Maybe it's actually easier in scala-syntax :thinking:

tgodzik avatar Jun 03 '22 12:06 tgodzik

I'll take a look at vscode-scala-syntax https://github.com/scala/vscode-scala-syntax

tanishiking avatar Jul 20 '22 05:07 tanishiking

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

tanishiking avatar Jul 20 '22 07:07 tanishiking

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.

tgodzik avatar Jul 20 '22 08:07 tgodzik

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

romanowski avatar Jul 21 '22 08:07 romanowski

Fixed by https://github.com/scala/vscode-scala-syntax/pull/237

lwronski avatar Sep 13 '22 09:09 lwronski