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
- Generate Semanticdb's data structures (e.g.
SymbolInformation
,ClassSignature
, and etc, see https://scalameta.org/docs/semanticdb/specification.html#data-model)- Some
data structures are already defined [here https://github.com/lampepfl/dotty/tree/b7d2a122555a6aa44cc7590852a80f12512c535e/compiler/src/dotty/tools/dotc/semanticdb]. They are copy-paste from generated code and adjusted for Scala3.
- Some
- Extend Semanticdb proto for new Scala3 types
- Type Lambdas
- Match Types
- Dependent Function Types
- Polymorphic Function Types
- Semanticdb already have
Union Type
andIntersection Type
- Extract
Sginature
information for Scala3
(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
.
Opened issues we mentioned in #12885