Skip to content

Commit

Permalink
fix: prefer non-export definition locations (#20252)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Apr 29, 2024
2 parents 837ed3a + 41c735e commit 5c8e5e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dotty.tools.dotc.ast.NavigateAST
import dotty.tools.dotc.ast.tpd.*
import dotty.tools.dotc.ast.untpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Flags.ModuleClass
import dotty.tools.dotc.core.Flags.{Exported, ModuleClass}
import dotty.tools.dotc.core.Symbols.*
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
Expand Down Expand Up @@ -123,9 +123,12 @@ class PcDefinitionProvider(
case symbols @ (sym :: other) =>
val isLocal = sym.source == pos.source
if isLocal then
val defs =
Interactive.findDefinitions(List(sym), driver, false, false).filter(_.source == sym.source)
defs.headOption match
val (exportedDefs, otherDefs) =
Interactive.findDefinitions(List(sym), driver, false, false)
.filter(_.source == sym.source)
.partition(_.tree.symbol.is(Exported))

otherDefs.headOption.orElse(exportedDefs.headOption) match
case Some(srcTree) =>
val pos = srcTree.namePos
pos.toLocation match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ class PcDefinitionSuite extends BasePcDefinitionSuite:
|""".stripMargin
)

@Test def exportTermExtension =
check(
"""|package a
|class Test extends A {
| assert("Hello".fo@@o == "HelloFoo")
|}
|
|trait A {
| export B.*
|}
|
|object B {
| extension (value: String) def <<foo>>: String = s"${value}Foo"
|}
|""".stripMargin
)

@Test def `named-arg-local` =
check(
"""|
Expand Down

0 comments on commit 5c8e5e2

Please sign in to comment.