-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: use pc for finding references of local symbols and when …
…semanticdb is missing (#5940) * improvement: use pc for finding references of local symbols * delete unused `referencedPackages` * use pc for references as fallback when missing semanticdb * move collecting identifiers to mtags * fixes * small review changes * add back `compileAndLookForNewReferences` * benchmarks * get file content on demand * small fix * scalafix * fixes after rebase * add test for rename with un-compiled build target * post rebase fixes * refactor: drop using buffers in pc * review fixes * filter if empty locations * post rebase fixes
- Loading branch information
1 parent
df933f2
commit d12e21e
Showing
50 changed files
with
2,109 additions
and
1,093 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
metals/src/main/scala/scala/meta/internal/metals/IdentifierIndex.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package scala.meta.internal.metals | ||
|
||
import java.nio.charset.StandardCharsets | ||
import java.nio.file.Path | ||
|
||
import scala.collection.concurrent.TrieMap | ||
import scala.util.control.NonFatal | ||
|
||
import scala.meta.Dialect | ||
import scala.meta.inputs.Input | ||
import scala.meta.internal.tokenizers.LegacyScanner | ||
import scala.meta.internal.tokenizers.LegacyToken._ | ||
import scala.meta.io.AbsolutePath | ||
|
||
import ch.epfl.scala.bsp4j.BuildTargetIdentifier | ||
import com.google.common.hash.BloomFilter | ||
import com.google.common.hash.Funnels | ||
|
||
class IdentifierIndex { | ||
val index: TrieMap[Path, IdentifierIndex.IndexEntry] = TrieMap.empty | ||
|
||
def addIdentifiers( | ||
file: AbsolutePath, | ||
id: BuildTargetIdentifier, | ||
set: Iterable[String], | ||
): Unit = { | ||
val bloom = BloomFilter.create( | ||
Funnels.stringFunnel(StandardCharsets.UTF_8), | ||
Integer.valueOf(set.size * 2), | ||
0.01, | ||
) | ||
|
||
val entry = IdentifierIndex.IndexEntry(id, bloom) | ||
index(file.toNIO) = entry | ||
set.foreach(bloom.put) | ||
} | ||
|
||
def collectIdentifiers( | ||
text: String, | ||
dialect: Dialect, | ||
): Iterable[String] = { | ||
val identifiers = Set.newBuilder[String] | ||
|
||
try { | ||
new LegacyScanner(Input.String(text), dialect).foreach { | ||
case ident if ident.token == IDENTIFIER => identifiers += ident.name | ||
case _ => | ||
} | ||
} catch { | ||
case NonFatal(_) => | ||
} | ||
|
||
identifiers.result() | ||
} | ||
} | ||
|
||
object IdentifierIndex { | ||
case class IndexEntry( | ||
id: BuildTargetIdentifier, | ||
bloom: BloomFilter[CharSequence], | ||
) | ||
} |
Oops, something went wrong.