11package  dotty .tools .pc 
22
3+ import  java .net .URI 
34import  java .nio .file .Paths 
45import  java .util .ArrayList 
56
@@ -16,6 +17,7 @@ import dotty.tools.dotc.core.Contexts.Context
1617import  dotty .tools .dotc .core .Flags .{Exported , ModuleClass }
1718import  dotty .tools .dotc .core .Symbols .* 
1819import  dotty .tools .dotc .interactive .Interactive 
20+ import  dotty .tools .dotc .interactive .Interactive .Include 
1921import  dotty .tools .dotc .interactive .InteractiveDriver 
2022import  dotty .tools .dotc .util .SourceFile 
2123import  dotty .tools .dotc .util .SourcePosition 
@@ -51,10 +53,10 @@ class PcDefinitionProvider(
5153    given  ctx :  Context  =  driver.localContext(params)
5254    val  indexedContext  =  IndexedContext (ctx)
5355    val  result  = 
54-       if  findTypeDef then  findTypeDefinitions(path, pos, indexedContext)
55-       else  findDefinitions(path, pos, indexedContext)
56+       if  findTypeDef then  findTypeDefinitions(path, pos, indexedContext, uri )
57+       else  findDefinitions(path, pos, indexedContext, uri )
5658
57-     if  result.locations().nn.isEmpty() then  fallbackToUntyped(pos)(using  ctx)
59+     if  result.locations().nn.isEmpty() then  fallbackToUntyped(pos, uri )(using  ctx)
5860    else  result
5961  end  definitions 
6062
@@ -70,32 +72,35 @@ class PcDefinitionProvider(
7072   * @param  pos  cursor position 
7173   * @return  definition result 
7274   */  
73-   private  def  fallbackToUntyped (pos : SourcePosition )(
75+   private  def  fallbackToUntyped (pos : SourcePosition ,  uri :  URI )(
7476    using ctx : Context 
7577  ) = 
7678    lazy  val  untpdPath  =  NavigateAST 
7779      .untypedPath(pos.span)
7880      .collect { case  t : untpd.Tree  =>  t }
7981
80-     definitionsForSymbol(untpdPath.headOption.map(_.symbol).toList, pos)
82+     definitionsForSymbol(untpdPath.headOption.map(_.symbol).toList, uri,  pos)
8183  end  fallbackToUntyped 
8284
8385  private  def  findDefinitions (
8486      path : List [Tree ],
8587      pos : SourcePosition ,
86-       indexed : IndexedContext 
88+       indexed : IndexedContext ,
89+       uri : URI ,
8790  ):  DefinitionResult  = 
8891    import  indexed .ctx 
8992    definitionsForSymbol(
9093      MetalsInteractive .enclosingSymbols(path, pos, indexed),
94+       uri,
9195      pos
9296    )
9397  end  findDefinitions 
9498
9599  private  def  findTypeDefinitions (
96100      path : List [Tree ],
97101      pos : SourcePosition ,
98-       indexed : IndexedContext 
102+       indexed : IndexedContext ,
103+       uri : URI ,
99104  ):  DefinitionResult  = 
100105    import  indexed .ctx 
101106    val  enclosing  =  path.expandRangeToEnclosingApply(pos)
@@ -108,24 +113,25 @@ class PcDefinitionProvider(
108113      case  Nil  => 
109114        path.headOption match 
110115          case  Some (value : Literal ) => 
111-             definitionsForSymbol(List (value.typeOpt.widen.typeSymbol), pos)
116+             definitionsForSymbol(List (value.typeOpt.widen.typeSymbol), uri,  pos)
112117          case  _ =>  DefinitionResultImpl .empty
113118      case  _ => 
114-         definitionsForSymbol(typeSymbols, pos)
119+         definitionsForSymbol(typeSymbols, uri,  pos)
115120
116121  end  findTypeDefinitions 
117122
118123  private  def  definitionsForSymbol (
119124      symbols : List [Symbol ],
125+       uri : URI ,
120126      pos : SourcePosition 
121127  )(using  ctx : Context ):  DefinitionResult  = 
122128    symbols match 
123129      case  symbols @  (sym ::  other) => 
124130        val  isLocal  =  sym.source ==  pos.source
125131        if  isLocal then 
132+           val  include  =  Include .definitions |  Include .local
126133          val  (exportedDefs, otherDefs) = 
127-             Interactive .findDefinitions(List (sym), driver, false , false )
128-               .filter(_.source ==  sym.source)
134+             Interactive .findTreesMatching(driver.openedTrees(uri), include, sym)
129135              .partition(_.tree.symbol.is(Exported ))
130136
131137          otherDefs.headOption.orElse(exportedDefs.headOption)  match 
0 commit comments