Skip to content

Commit

Permalink
bugfix: fix typeDefinition on backticked identifier
Browse files Browse the repository at this point in the history
One of the short-circuiting conditions in the type definition logic was
a bit too broad, leading to `typeDefinition` not returning a result if
the position queried happened to precede a space in an identifier (see
the test that was added).
  • Loading branch information
harpocrates committed Jan 14, 2025
1 parent 262a892 commit fccc6d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scala.meta.internal.pc

import java.{util => ju}

import scala.meta.internal.mtags.MtagsEnrichments._
import scala.meta.internal.semanticdb.Scala._
import scala.meta.pc.DefinitionResult
import scala.meta.pc.OffsetParams
Expand Down Expand Up @@ -55,7 +54,7 @@ class PcDefinitionProvider(val compiler: MetalsGlobal, params: OffsetParams) {
}

private def definition(findTypeDef: Boolean): DefinitionResult = {
if (params.isWhitespace || params.isDelimiter || params.offset() == 0) {
if (params.offset() == 0) {
DefinitionResultImpl.empty
} else {
val unit = addCompilationUnit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,13 @@ class TypeDefinitionSuite extends BasePcDefinitionSuite {
|""".stripMargin
)

check(
"backticked identifier",
"""|
|class Main {
| def `Foo/*scala/Int# Int.scala*/@@ Bar` = 1 + 2
|}
|""".stripMargin
)

}

0 comments on commit fccc6d1

Please sign in to comment.