From b1d6a7922c49e9986391e2054b50739bdae92023 Mon Sep 17 00:00:00 2001 From: kasiaMarek Date: Tue, 20 Aug 2024 12:44:21 +0200 Subject: [PATCH] fix: don't cancel previous references search for rename --- .../internal/metals/ReferenceProvider.scala | 20 ++++++++++++------- .../main/scala/tests/BaseRangesSuite.scala | 3 +-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala index d8726268222..05cd787df4e 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/ReferenceProvider.scala @@ -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)) @@ -326,6 +328,7 @@ final class ReferenceProvider( chosen.toList, includeDeclaration, findRealRange, + isForRename, ) } } yield { @@ -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 @@ -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 } @@ -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 } } diff --git a/tests/unit/src/main/scala/tests/BaseRangesSuite.scala b/tests/unit/src/main/scala/tests/BaseRangesSuite.scala index 75a2a667b27..cf86892550d 100644 --- a/tests/unit/src/main/scala/tests/BaseRangesSuite.scala +++ b/tests/unit/src/main/scala/tests/BaseRangesSuite.scala @@ -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(