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 b1d6a79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 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
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 b1d6a79

Please sign in to comment.