diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/PcSemanticTokensProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/PcSemanticTokensProvider.scala index 142c901102a..75179a44975 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/PcSemanticTokensProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/PcSemanticTokensProvider.scala @@ -119,7 +119,7 @@ final class PcSemanticTokensProvider( if (sym.isAccessor) getTypeId(SemanticTokenTypes.Variable) else getTypeId(SemanticTokenTypes.Method) // "def" - else if (isPredefClass(sym)) getTypeId(SemanticTokenTypes.Class) + else if (isValObject(sym)) getTypeId(SemanticTokenTypes.Class) else if (sym.isTerm && (!sym.isParameter || sym.isParamAccessor)) { addPwrToMod(SemanticTokenModifiers.Readonly) getTypeId(SemanticTokenTypes.Variable) // "val" @@ -132,16 +132,18 @@ final class PcSemanticTokensProvider( if (isDefinition) addPwrToMod(SemanticTokenModifiers.Definition) TokenNode(pos.start, pos.end, typ, mod) - } - private def isPredefClass(sym: Collector.compiler.Symbol) = + // eg. val Foo = List + private def isValObject(sym: Collector.compiler.Symbol) = { sym.info match { case Collector.compiler.NullaryMethodType( Collector.compiler.SingleType(_, value) - ) if value.isModule => - true + ) => + value.isModule + case Collector.compiler.SingleType(_, value) => value.isModule case _ => false } + } } diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/PcSemanticTokensProvider.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/PcSemanticTokensProvider.scala index 67d1ba0f622..baeae4508a3 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/PcSemanticTokensProvider.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/PcSemanticTokensProvider.scala @@ -131,7 +131,7 @@ final class PcSemanticTokensProvider( if sym.isGetter | sym.isSetter then getTypeId(SemanticTokenTypes.Variable) else getTypeId(SemanticTokenTypes.Method) // "def" - else if isPredefClass(sym) then + else if sym.isTerm && sym.info.typeSymbol.is(Flags.Module) then getTypeId(SemanticTokenTypes.Class) // "class" else if sym.isTerm && (!sym.is(Flags.Param) || sym.is(Flags.ParamAccessor)) @@ -153,7 +153,4 @@ final class PcSemanticTokensProvider( TokenNode(pos.start, pos.`end`, typ, mod) end makeNode - def isPredefClass(sym: Symbol)(using Context) = - sym.is(Flags.Method) && sym.info.resultType.typeSymbol.is(Flags.Module) - end PcSemanticTokensProvider diff --git a/tests/cross/src/test/scala/tests/tokens/SemanticTokensSuite.scala b/tests/cross/src/test/scala/tests/tokens/SemanticTokensSuite.scala index 45401f74576..872776e561f 100644 --- a/tests/cross/src/test/scala/tests/tokens/SemanticTokensSuite.scala +++ b/tests/cross/src/test/scala/tests/tokens/SemanticTokensSuite.scala @@ -293,6 +293,29 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite { |""".stripMargin ) + check( + "predef", + """ + |object <
>/*class*/ { + | val <>/*variable,definition,readonly*/ = <>/*class*/(1,2,3) + | val <>/*class,definition*/ = <>/*class*/ + | val <>/*class,definition*/ = <>/*namespace*/.<>/*namespace*/.<>/*namespace*/.<>/*class*/ + |} + |""".stripMargin + ) + + check( + "val-object", + """|case class <>/*class*/(<>/*variable,declaration,readonly*/: <>/*class,abstract*/) + |object <>/*class*/ + | + |object <
>/*class*/ { + | val <>/*class,definition*/ = <>/*class*/ + | val <>/*variable,definition,readonly*/ = <>/*class*/(1) + |} + |""".stripMargin + ) + // When for-comprehension includes line with `=`, we get `scala.x$1`, `scala.x$2` symbols on `foo`. // Both `scala` and `x$#` have position on `foo`, and we don't want to highlight it as a `scala` package, // so we need `namespace` to have lower priority than `variable`. diff --git a/tests/unit/src/test/resources/semanticTokens3/example/GivenAlias.scala b/tests/unit/src/test/resources/semanticTokens3/example/GivenAlias.scala index 683bb4a92ce..7b5b048c6e4 100644 --- a/tests/unit/src/test/resources/semanticTokens3/example/GivenAlias.scala +++ b/tests/unit/src/test/resources/semanticTokens3/example/GivenAlias.scala @@ -42,6 +42,6 @@ <>/*keyword*/ <>/*variable,definition,readonly*/ = <>/*variable,readonly*/ <>/*keyword*/ <>/*variable,definition,readonly*/ = <<`* *`>>/*variable,readonly*/ <>/*keyword*/ <>/*variable,definition,readonly*/ = <>/*class*/.<>/*method*/[<>/*class,abstract*/] -<>/*keyword*/ <>/*variable,definition,readonly*/ = <>/*class*/ +<>/*keyword*/ <>/*class,definition*/ = <>/*class*/ <>/*keyword*/ <>/*variable,definition,readonly*/ = <>/*method*/ <>/*keyword*/ <>/*variable,definition,readonly*/ = <>/*method*/[<>/*type*/] \ No newline at end of file