Skip to content

Commit c4bcba4

Browse files
committed
Add annotations to semanticdb
Previously, it was not possible to find if a given method was for example annotated with @main, which will be useful for run/debug code lenses. Now, they should be correctly saved. The only issue seems to be `@specialized` which is currently producing empty type, anone knows what is going on?
1 parent 968dd1b commit c4bcba4

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

compiler/src/dotty/tools/dotc/semanticdb/PPrint.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class SymbolInformationPrinter (symtab: PrinterSymtab):
3535
case Reference, Definition
3636
def pprint(info: SymbolInformation): String =
3737
val sb = new StringBuilder()
38+
val annotStr = info.annotations.map(pprint).mkString(" ")
39+
if annotStr.nonEmpty then
40+
sb.append(annotStr + " ")
3841
sb.append(accessString(info.access))
3942
if info.isAbstract then sb.append("abstract ")
4043
if info.isFinal then sb.append("final ")

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ object Scala3:
9595
val kind = s.symbolKind(symkinds)
9696
val sname = sym.symbolName
9797
val signature = s.info.toSemanticSig(s)
98+
val symbolAnnotations = s.annotations.collect{
99+
case annot if annot.symbol != defn.BodyAnnot && annot.symbol != defn.ChildAnnot =>
100+
Annotation(annot.symbol.typeRef.toSemanticType(annot.symbol))
101+
}
98102
SymbolInformation(
99103
symbol = sname,
100104
language = Language.SCALA,
@@ -104,6 +108,7 @@ object Scala3:
104108
signature = signature,
105109
access = s.symbolAccess(kind),
106110
overriddenSymbols = s.overriddenSymbols,
111+
annotations = symbolAnnotations
107112
)
108113
case s: WildcardTypeSymbol =>
109114
SymbolInformation(

tests/semanticdb/metac.expect

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,26 @@ Occurrences => 48 entries
228228
Symbols:
229229
annot/Alias. => final object Alias extends Object { self: Alias.type => +2 decls }
230230
annot/Alias.A# => type A = ClassAnnotation @param
231-
annot/Annotations# => class Annotations [typeparam T ] extends Object { self: AnyRef & Annotations[T] => +6 decls }
232-
annot/Annotations#S# => type S
233-
annot/Annotations#[T] => typeparam T
234-
annot/Annotations#`<init>`(). => primary ctor <init> [typeparam T ](param x: T): Annotations[T]
235-
annot/Annotations#`<init>`().(x) => param x: T
236-
annot/Annotations#field. => val method field Int
237-
annot/Annotations#method(). => method method => Int
238-
annot/Annotations#x. => private[this] val method x T
231+
annot/Annotations# => @ClassAnnotation class Annotations [@TypeParameterAnnotation typeparam T ] extends Object { self: AnyRef & Annotations[T] => +6 decls }
232+
annot/Annotations#S# => @TypeAnnotation type S
233+
annot/Annotations#[T] => @TypeParameterAnnotation typeparam T
234+
annot/Annotations#`<init>`(). => primary ctor <init> [@TypeParameterAnnotation typeparam T ](@ParameterAnnotation param x: T): Annotations[T]
235+
annot/Annotations#`<init>`().(x) => @ParameterAnnotation param x: T
236+
annot/Annotations#field. => @FieldAnnotation val method field Int
237+
annot/Annotations#method(). => @MethodAnnotation method method => Int
238+
annot/Annotations#x. => @ParameterAnnotation private[this] val method x T
239239
annot/B# => class B extends Object { self: B => +3 decls }
240-
annot/B#`<init>`(). => primary ctor <init> (param x: Int): B
240+
annot/B#`<init>`(). => @ConstructorAnnotation primary ctor <init> (param x: Int): B
241241
annot/B#`<init>`().(x) => param x: Int
242-
annot/B#`<init>`(+1). => ctor <init> (): B
242+
annot/B#`<init>`(+1). => @ConstructorAnnotation ctor <init> (): B
243243
annot/B#x. => private[this] val method x Int
244-
annot/M. => final object M extends Object { self: M.type => +1 decls }
245-
annot/M.m(). => macro m [typeparam TT ]: Int
244+
annot/M. => @ObjectAnnotation final object M extends Object { self: M.type => +1 decls }
245+
annot/M.m(). => @MacroAnnotation macro m [typeparam TT ]: Int
246246
annot/M.m().[TT] => typeparam TT
247-
annot/T# => trait T extends Object { self: T => +1 decls }
247+
annot/T# => @TraitAnnotation trait T extends Object { self: T => +1 decls }
248248
annot/T#`<init>`(). => primary ctor <init> (): T
249249
local0 => selfparam self: AnyRef
250-
local1 => val local local: Int
250+
local1 => @LocalAnnotation val local local: Int
251251

252252
Occurrences:
253253
[0:8..0:13): annot <- annot/
@@ -4082,9 +4082,9 @@ flags/p/package.C#w(). => abstract method w => Int
40824082
flags/p/package.C#x. => private[this] val method x T
40834083
flags/p/package.C#y. => private[this] val method y U
40844084
flags/p/package.C#z. => private[this] val method z V
4085-
flags/p/package.S# => class S [typeparam T ] extends Object { self: S[T] => +2 decls }
4086-
flags/p/package.S#[T] => typeparam T
4087-
flags/p/package.S#`<init>`(). => primary ctor <init> [typeparam T ](): S[T]
4085+
flags/p/package.S# => class S [@specialized typeparam T ] extends Object { self: S[T] => +2 decls }
4086+
flags/p/package.S#[T] => @specialized typeparam T
4087+
flags/p/package.S#`<init>`(). => primary ctor <init> [@specialized typeparam T ](): S[T]
40884088
flags/p/package.T1# => type T1 = Int
40894089
flags/p/package.T2# => type T2 [typeparam T ] = S[T]
40904090
flags/p/package.T2#[T] => typeparam T
@@ -4635,7 +4635,7 @@ Symbols:
46354635
_empty_/MyProgram# => final class MyProgram extends Object { self: MyProgram => +2 decls }
46364636
_empty_/readInts# => final class readInts extends Object { self: readInts => +2 decls }
46374637
_empty_/toplevel$package. => final package object _empty_ extends Object { self: _empty_.type => +9 decls }
4638-
_empty_/toplevel$package.MyProgram(). => method MyProgram (param times: Int): Unit
4638+
_empty_/toplevel$package.MyProgram(). => @main method MyProgram (param times: Int): Unit
46394639
_empty_/toplevel$package.MyProgram().(times) => param times: Int
46404640
_empty_/toplevel$package.a. => val inline method a ""
46414641
_empty_/toplevel$package.combine(). => method combine (param x: Int)(param y: Int): Int
@@ -4648,7 +4648,7 @@ _empty_/toplevel$package.combine(+1).(z) => param z: Int
46484648
_empty_/toplevel$package.combine(+2). => method combine => Int
46494649
_empty_/toplevel$package.foo(). => method foo => String
46504650
_empty_/toplevel$package.fooRef(). => method fooRef => String
4651-
_empty_/toplevel$package.readInts(). => method readInts (param ints: Int*): Unit
4651+
_empty_/toplevel$package.readInts(). => @main method readInts (param ints: Int*): Unit
46524652
_empty_/toplevel$package.readInts().(ints) => param ints: Int*
46534653

46544654
Occurrences:

0 commit comments

Comments
 (0)