Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Dec 21, 2023
1 parent 64412d6 commit 405ac4a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class Compilers(

def references(
params: ReferenceParams,
targetFiles: List[AbsolutePath],
targetFiles: Iterator[AbsolutePath],
token: CancelToken,
): Future[List[ReferencesResult]] = {
withPCAndAdjustLsp(params) { (pc, pos, adjust) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ final class ReferenceProvider(
): Set[String] = {
val dialect = scalaVersionSelector.getDialect(path)
val identifiers = Set.newBuilder[String]
new LegacyScanner(Input.String(text), dialect).foreach {
case ident if ident.token == IDENTIFIER => identifiers += ident.name
case _ =>

try {
new LegacyScanner(Input.String(text), dialect).foreach {
case ident if ident.token == IDENTIFIER => identifiers += ident.name
case _ =>
}
} catch {
case NonFatal(_) =>
}

identifiers.result()
}

Expand Down Expand Up @@ -214,7 +220,12 @@ final class ReferenceProvider(
}
}
val pcResult =
pcReferences(source, params, path => !index.contains(path.toNIO))
pcReferences(
source,
params,
forceIncludeLocalSearch = false,
path => !index.contains(path.toNIO),
)

Future
.sequence(List(semanticdbResult, pcResult))
Expand All @@ -228,7 +239,7 @@ final class ReferenceProvider(
)
case None =>
scribe.debug(s"No semanticdb for $source")
pcReferences(source, params)
pcReferences(source, params, forceIncludeLocalSearch = true)
}
}

Expand Down Expand Up @@ -323,13 +334,16 @@ final class ReferenceProvider(
private def pcReferences(
path: AbsolutePath,
params: ReferenceParams,
forceIncludeLocalSearch: Boolean,
filterTargetFiles: AbsolutePath => Boolean = _ => true,
): Future[List[ReferencesResult]] = {
val result = for {
name <- nameAtPosition(path, params.getPosition())
buildTarget <- buildTargets.inverseSources(path)
targetFiles = (path :: pathsForName(buildTarget, name).toList).distinct
.filter(filterTargetFiles)
targetFiles = {
val localPath = Option.when(forceIncludeLocalSearch)(path)
pathsForName(buildTarget, localPath, name).filter(filterTargetFiles)
}
if targetFiles.nonEmpty
} yield compilers
.references(params, targetFiles, EmptyCancelToken)
Expand All @@ -354,10 +368,12 @@ final class ReferenceProvider(

private def pathsForName(
buildTarget: BuildTargetIdentifier,
localPath: Option[AbsolutePath],
name: String,
): Iterator[AbsolutePath] = {
val allowedBuildTargets = buildTargets.allInverseDependencies(buildTarget)
val visited = scala.collection.mutable.Set.empty[AbsolutePath]
localPath.foreach(visited.add)
val result = for {
(path, entry) <- tokenIndex.iterator
if allowedBuildTargets.contains(entry.id) &&
Expand All @@ -368,7 +384,7 @@ final class ReferenceProvider(
if sourcePath.exists
} yield sourcePath

result
result ++ localPath
}

/**
Expand Down Expand Up @@ -470,7 +486,7 @@ final class ReferenceProvider(
val isLocal = occ.symbol.isLocal
if (isLocal)
compilers
.references(params, List(source), EmptyCancelToken)
.references(params, Iterator(source), EmptyCancelToken)
.map(_.flatMap(_.locations))
else {
/* search local in the following cases:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PcReferencesLspSuite
}
}

def refFiles = files.keysIterator.map(server.toPath(_)).toList
def refFiles = files.keysIterator.map(server.toPath(_))

val layout = input.replaceAll("<<|>>|@@", "")

Expand Down

0 comments on commit 405ac4a

Please sign in to comment.