@@ -18,6 +18,7 @@ import dotty.tools.dotc.interactive.Interactive
18
18
import dotty .tools .dotc .interactive .InteractiveDriver
19
19
import dotty .tools .dotc .util .SourcePosition
20
20
import dotty .tools .pc .utils .InteractiveEnrichments .*
21
+ import dotty .tools .pc .IndexedContext .Result
21
22
22
23
import org .eclipse .lsp4j as l
23
24
@@ -49,7 +50,9 @@ final class PcInlineValueProviderImpl(
49
50
DefinitionTree (defn, pos)
50
51
}
51
52
.toRight(Errors .didNotFindDefinition)
52
- symbols = symbolsUsedInDefn(definition.tree.rhs)
53
+ path = Interactive .pathTo(unit.tpdTree, definition.tree.rhs.span)(using newctx)
54
+ indexedContext = IndexedContext (Interactive .contextOfPath(path)(using newctx))
55
+ symbols = symbolsUsedInDefn(definition.tree.rhs).filter(indexedContext.lookupSym(_) == Result .InScope )
53
56
references <- getReferencesToInline(definition, allOccurences, symbols)
54
57
yield
55
58
val (deleteDefinition, refsEdits) = references
@@ -111,27 +114,25 @@ final class PcInlineValueProviderImpl(
111
114
val adjustedEnd = extend(pos.end - 1 , ')' , 1 ) + 1
112
115
text.slice(adjustedStart, adjustedEnd).mkString
113
116
114
- private def symbolsUsedInDefn (
115
- rhs : Tree
116
- ): List [Symbol ] =
117
+ private def symbolsUsedInDefn (rhs : Tree ): Set [Symbol ] =
117
118
def collectNames (
118
- symbols : List [Symbol ],
119
+ symbols : Set [Symbol ],
119
120
tree : Tree
120
- ): List [Symbol ] =
121
+ ): Set [Symbol ] =
121
122
tree match
122
123
case id : (Ident | Select )
123
124
if ! id.symbol.is(Synthetic ) && ! id.symbol.is(Implicit ) =>
124
- tree.symbol :: symbols
125
+ symbols + tree.symbol
125
126
case _ => symbols
126
127
127
- val traverser = new DeepFolder [List [Symbol ]](collectNames)
128
- traverser(List (), rhs)
128
+ val traverser = new DeepFolder [Set [Symbol ]](collectNames)
129
+ traverser(Set (), rhs)
129
130
end symbolsUsedInDefn
130
131
131
132
private def getReferencesToInline (
132
133
definition : DefinitionTree ,
133
134
allOccurences : List [Occurence ],
134
- symbols : List [Symbol ]
135
+ symbols : Set [Symbol ]
135
136
): Either [String , (Boolean , List [Reference ])] =
136
137
val defIsLocal = definition.tree.symbol.ownersIterator
137
138
.drop(1 )
@@ -156,7 +157,7 @@ final class PcInlineValueProviderImpl(
156
157
157
158
private def makeRefsEdits (
158
159
refs : List [Occurence ],
159
- symbols : List [Symbol ]
160
+ symbols : Set [Symbol ]
160
161
): Either [String , List [Reference ]] =
161
162
val newctx = driver.currentCtx.fresh.setCompilationUnit(unit)
162
163
def buildRef (occurrence : Occurence ): Either [String , Reference ] =
0 commit comments