Skip to content

Commit

Permalink
fix: don't cancel previous references search for rename
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Aug 20, 2024
1 parent daca5d6 commit 5523636
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,15 @@ final class ReferenceProvider(
}
}
}
val chosen = results.flatMap(_._2).toSet
val pcResult =
pcReferences(
source,
results.flatMap(_._2).toList,
chosen.toList,
params.getContext().isIncludeDeclaration(),
findRealRange,
)
isForRename,
).map(_.filter(ref => chosen(ref.symbol)))

Future
.sequence(List(semanticdbResult, pcResult))
Expand Down Expand Up @@ -326,6 +328,7 @@ final class ReferenceProvider(
chosen.toList,
includeDeclaration,
findRealRange,
isForRename,
)
}
} yield {
Expand Down Expand Up @@ -502,6 +505,7 @@ final class ReferenceProvider(
symbols: List[String],
includeDeclaration: Boolean,
adjustLocation: AdjustRange,
isForRename: Boolean,
): Future[List[ReferencesResult]] = {
val visited = mutable.Set[AbsolutePath]()
val names = symbols.map(nameFromSymbol(_)).toSet
Expand Down Expand Up @@ -540,12 +544,14 @@ final class ReferenceProvider(
.toList
val lock = new Lock
val result =
pcReferencesLock.getAndSet(lock).cancelAndWaitUntilCompleted().flatMap {
_ =>
pcReferencesLock
.getAndSet(lock)
.cancelAndWaitUntilCompleted(isForRename)
.flatMap { _ =>
val maxPcsNumber = Runtime.getRuntime().availableProcessors() / 2
executeBatched(lazyResults, maxPcsNumber, () => lock.isCancelled)
.map(_.flatten)
}
}
result.onComplete(_ => lock.complete())
result
}
Expand Down Expand Up @@ -1021,8 +1027,8 @@ class Lock {

def isCancelled = cancelPromise.isCompleted
def complete(): Unit = completedPromise.trySuccess(())
def cancelAndWaitUntilCompleted(): Future[Unit] = {
cancelPromise.trySuccess(())
def cancelAndWaitUntilCompleted(isForRename: Boolean): Future[Unit] = {
if (!isForRename) cancelPromise.trySuccess(())
completedPromise.future
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ trait PcCollector[T]:

def soughtOrOverride(sym: Symbol) =
sought(sym) || sym.allOverriddenSymbols.exists(sought(_))
lazy val constructorOwners = sought.collect:
lazy val constructorOwners = sought.collect {
case sym if sym.isPrimaryConstructor => sym.owner
}

def soughtTreeFilter(tree: Tree): Boolean =
tree match
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/src/main/scala/tests/BaseRangesSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ abstract class BaseRangesSuite(name: String) extends BaseLspSuite(name) {
quickPickReferencesSymbol(params.items.asScala.toList)
.map(item => RawMetalsQuickPickResult(item.id))
.getOrElse(RawMetalsQuickPickResult(cancelled = true))
case params =>
pprint.log(params)
case _ =>
RawMetalsQuickPickResult(cancelled = true)
}
_ <- Future.sequence(
Expand Down

0 comments on commit 5523636

Please sign in to comment.