diff --git a/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala index 056c7ac5e03..3ea03c2ebee 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/DefinitionProvider.scala @@ -116,7 +116,9 @@ final class DefinitionProvider( fromCompilerOrSemanticdb.map { definition => if (definition.isEmpty && !definition.symbol.endsWith("/")) { val isScala3 = - scalaVersionSelector.scalaVersionForPath(path).startsWith("3") + ScalaVersions.isScala3Version( + scalaVersionSelector.scalaVersionForPath(path) + ) scaladocDefinitionProvider .definition(path, params, isScala3) .orElse(fromSearch(path, params.getPosition(), token)) diff --git a/tests/unit/src/test/scala/tests/DefinitionLspSuite.scala b/tests/unit/src/test/scala/tests/DefinitionLspSuite.scala index 8e6121410eb..c1a1b1dcebb 100644 --- a/tests/unit/src/test/scala/tests/DefinitionLspSuite.scala +++ b/tests/unit/src/test/scala/tests/DefinitionLspSuite.scala @@ -6,7 +6,9 @@ import scala.meta.internal.metals.InitializationOptions import scala.meta.internal.metals.MetalsServerConfig import scala.meta.internal.metals.StatisticsConfig -class DefinitionLspSuite extends BaseLspSuite("definition") { +class DefinitionLspSuite + extends BaseLspSuite("definition") + with ScriptsAssertions { override protected def initializationOptions: Option[InitializationOptions] = Some(TestingServer.TestDefault) @@ -640,19 +642,6 @@ class DefinitionLspSuite extends BaseLspSuite("definition") { } test("scaladoc-definition-this") { - val testCase = - """|package a - | - |object O { - | class A { - | /** - | * Calls [[this@@.g]] - | */ - | def f: Int = g - | def g: Int = ??? - | } - |} - |""".stripMargin for { _ <- initialize( s""" @@ -661,18 +650,25 @@ class DefinitionLspSuite extends BaseLspSuite("definition") { | "a": { } |} |/a/src/main/scala/a/Main.scala - |${testCase.replace("@@", "")} + | package a + | + |object O { + | class A { + | /** + | * Calls [[this.g]] + | */ + | def f: Int = g + | def g: Int = ??? + | } + |} |""".stripMargin ) - _ <- server.didOpen("a/src/main/scala/a/Main.scala") - locations <- server.definition( + _ = assertDefinitionAtLocation( "a/src/main/scala/a/Main.scala", - testCase, - workspace, + "this@@.g", + "a/src/main/scala/a/Main.scala", + expectedLine = 8, ) - _ = assert(locations.length == 1) - _ = assert(locations.head.getUri().endsWith("a/Main.scala")) - _ = assertEquals(locations.head.getRange().getStart().getLine(), 8) } yield () }