Skip to content

Commit b474209

Browse files
committed
presentation compiler: Show semantic tokens for vals from predef as classes
1 parent 41e7d95 commit b474209

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

presentation-compiler/src/main/dotty/tools/pc/PcSemanticTokensProvider.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ final class PcSemanticTokensProvider(
129129
if sym.isGetter | sym.isSetter then
130130
getTypeId(SemanticTokenTypes.Variable)
131131
else getTypeId(SemanticTokenTypes.Method) // "def"
132-
else if isPredefClass(sym) then
132+
else if sym.isTerm && sym.info.typeSymbol.is(Flags.Module) then
133133
getTypeId(SemanticTokenTypes.Class) // "class"
134134
else if sym.isTerm &&
135135
(!sym.is(Flags.Param) || sym.is(Flags.ParamAccessor))
@@ -151,7 +151,4 @@ final class PcSemanticTokensProvider(
151151
TokenNode(pos.start, pos.`end`, typ, mod)
152152
end makeNode
153153

154-
def isPredefClass(sym: Symbol)(using Context) =
155-
sym.is(Flags.Method) && sym.info.resultType.typeSymbol.is(Flags.Module)
156-
157154
end PcSemanticTokensProvider

presentation-compiler/test/dotty/tools/pc/tests/tokens/SemanticTokensSuite.scala

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
194194
s"""|package <<example>>/*namespace*/
195195
|
196196
|object <<A>>/*class*/ {
197-
| val <<x>>/*variable,definition,readonly*/ = <<List>>/*variable,readonly*/(1,2,3)
197+
| val <<x>>/*variable,definition,readonly*/ = <<List>>/*class*/(1,2,3)
198198
| val <<s>>/*variable,definition,readonly*/ = <<Some>>/*class*/(1)
199199
| val <<Some>>/*class*/(<<s1>>/*variable,definition,readonly*/) = <<s>>/*variable,readonly*/
200200
| val <<Some>>/*class*/(<<s2>>/*variable,definition,readonly*/) = <<s>>/*variable,readonly*/
@@ -269,7 +269,7 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
269269
|object <<A>>/*class*/ {
270270
| val <<a>>/*variable,definition,readonly*/ = 1
271271
| var <<b>>/*variable,definition*/ = 2
272-
| val <<c>>/*variable,definition,readonly*/ = <<List>>/*variable,readonly*/(1,<<a>>/*variable,readonly*/,<<b>>/*variable*/)
272+
| val <<c>>/*variable,definition,readonly*/ = <<List>>/*class*/(1,<<a>>/*variable,readonly*/,<<b>>/*variable*/)
273273
| <<b>>/*variable*/ = <<a>>/*variable,readonly*/
274274
|""".stripMargin
275275
)
@@ -278,13 +278,37 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
278278
check(
279279
"""
280280
|object <<Main>>/*class*/ {
281-
|val <<a>>/*variable,definition,readonly*/ = <<List>>/*variable,readonly*/(1,2,3)
282-
|val <<y>>/*variable,definition,readonly*/ = <<Vector>>/*variable,readonly*/(1,2)
283-
|val <<z>>/*variable,definition,readonly*/ = <<Set>>/*variable,readonly*/(1,2,3)
284-
|val <<w>>/*variable,definition,readonly*/ = <<Right>>/*variable,readonly*/(1)
281+
|val <<a>>/*variable,definition,readonly*/ = <<List>>/*class*/(1,2,3)
282+
|val <<y>>/*variable,definition,readonly*/ = <<Vector>>/*class*/(1,2)
283+
|val <<z>>/*variable,definition,readonly*/ = <<Set>>/*class*/(1,2,3)
284+
|val <<w>>/*variable,definition,readonly*/ = <<Right>>/*class*/(1)
285285
|}""".stripMargin
286286
)
287287

288+
@Test def `predef1` =
289+
check(
290+
"""
291+
|object <<Main>>/*class*/ {
292+
| val <<a>>/*variable,definition,readonly*/ = <<List>>/*class*/(1,2,3)
293+
| val <<y>>/*class,definition*/ = <<List>>/*class*/
294+
| val <<z>>/*class,definition*/ = <<scala>>/*namespace*/.<<collection>>/*namespace*/.<<immutable>>/*namespace*/.<<List>>/*class*/
295+
|}
296+
|""".stripMargin
297+
)
298+
299+
@Test def `val-object` =
300+
check(
301+
"""
302+
|case class <<X>>/*class*/(<<a>>/*variable,declaration,readonly*/: <<Int>>/*class,abstract*/)
303+
|object <<X>>/*class*/
304+
|
305+
|object <<Main>>/*class*/ {
306+
| val <<x>>/*class,definition*/ = <<X>>/*class*/
307+
| val <<y>>/*variable,definition,readonly*/ = <<X>>/*class*/(1)
308+
|}
309+
|""".stripMargin
310+
)
311+
288312
@Test def `case-class` =
289313
check(
290314
"""|case class <<Foo>>/*class*/(<<i>>/*variable,declaration,readonly*/: <<Int>>/*class,abstract*/, <<j>>/*variable,declaration,readonly*/: <<Int>>/*class,abstract*/)
@@ -326,7 +350,7 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite:
326350
|
327351
|object <<B>>/*class*/ {
328352
| val <<a>>/*variable,definition,readonly*/ = for {
329-
| <<foo>>/*variable,definition,readonly*/ <- <<List>>/*variable,readonly*/("a", "b", "c")
353+
| <<foo>>/*variable,definition,readonly*/ <- <<List>>/*class*/("a", "b", "c")
330354
| <<_>>/*class,abstract*/ = <<println>>/*method*/("print!")
331355
| } yield <<foo>>/*variable,readonly*/
332356
|}

0 commit comments

Comments
 (0)