lampepfl / dotty

The Scala 3 compiler, also known as Dotty.

Home Page:https://dotty.epfl.ch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Signature information for Semanticdb

tanishiking opened this issue · comments

Background

Current SemanticdbExtractor in Scala3 doesn't extract `` Signature information, which represents the type information for class, method, type, and local value.

Actually, from the following scala code,

class Simple {
  val a = 123
  a + a
}

symbols section will look like:

Scala 2

 Vector(
        SymbolInformation(
          "_empty_/Simple#",
          SCALA,
          CLASS,
          0,
          "Simple",
          ClassSignature(
            Some(Scope(Vector(), Vector())),
            Vector(TypeRef(Empty, "scala/AnyRef#", Vector())),
            Empty,
            Some(Scope(Vector("_empty_/Simple#`<init>`().", "_empty_/Simple#a."), Vector()))
          ),
          Vector(),
          PublicAccess()
        ),
        SymbolInformation(
          "_empty_/Simple#`<init>`().",
          SCALA,
          CONSTRUCTOR,
          8192,
          "<init>",
          MethodSignature(Some(Scope(Vector(), Vector())), Vector(Scope(Vector(), Vector())), Empty),
          Vector(),
          PublicAccess()
        ),
        SymbolInformation(
          "_empty_/Simple#a.",
          SCALA,
          METHOD,
          1024,
          "a",
          MethodSignature(
            Some(Scope(Vector(), Vector())),
            Vector(),
            TypeRef(Empty, "scala/Int#", Vector())
          ),
          Vector(),
          PublicAccess()
        )
      ),

compared to Scala 3 which is missing all information about signatures.

Scala 3

      Vector(
        SymbolInformation("_empty_/Simple#", SCALA, CLASS, 0, "Simple", Empty, Vector(), Empty),
        SymbolInformation(
          "_empty_/Simple#`<init>`().",
          SCALA,
          CONSTRUCTOR,
          8192,
          "<init>",
          Empty,
          Vector(),
          Empty
        ),
        SymbolInformation("_empty_/Simple#a.", SCALA, METHOD, 1024, "a", Empty, Vector(), Empty)
      ),

(copied from scalameta/metals#2593 (reply in thread))

Without Signature information in extracted SemanticDB, devtools based on Semanticdb lacks some functionalities for Scala3.
For example, metals can't provide textDocument/implementation and type decorations features for scala3 project, we can't implement scalafix rules that depends on Signature information.


TODOs

(details) Generate Semanticdb's data structures

As discussed here scalameta/scalameta#2367 , it would be a good first step to keep copy-and-paste and adjust the generated scala codes.
However, hand-crafting all those data-structure (because there's a lot of data structures that related to Signature) is tedious and it makes harder to catch-up new version of scalapb or new scalameta.proto.

Therefore, we'll create a project that generate the Scala code from scalameta.proto using Scalapb, and adjust them using scalafix (so that Scala3 compiler doesn't need to have dependency on scalapb-runtime.