Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed May 29, 2024
1 parent 3d98986 commit 9ed940e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
11 changes: 9 additions & 2 deletions metals/src/main/scala/scala/meta/internal/metals/Compilers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ class Compilers(
searchFiles: List[AbsolutePath],
includeDefinition: Boolean,
symbol: String,
additionalAdjust: AdjustRange
additionalAdjust: AdjustRange,
): Future[List[ReferencesResult]] = {
// we filter only Scala files, since `references` for Java are not implemented
val filteredFiles = searchFiles.filter(_.isScala)
Expand All @@ -784,7 +784,14 @@ class Compilers(
compiler
.references(requestParams)
.asScala
.map(_.asScala.map(adjust.adjustReferencesResult(_, additionalAdjust, input.text)).toList)
.map(
_.asScala
.map(
adjust
.adjustReferencesResult(_, additionalAdjust, input.text)
)
.toList
)
}
}
.getOrElse(Nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ object IdentifierIndex {
bloom: BloomFilter[CharSequence],
)

case class IndexEntryWithStaleInfo(
case class MaybeStaleIndexEntry(
id: BuildTargetIdentifier,
bloom: BloomFilter[CharSequence],
isStale: Boolean,
) {
def asStale: IndexEntryWithStaleInfo =
IndexEntryWithStaleInfo(id, bloom, isStale = true)
def asStale: MaybeStaleIndexEntry =
MaybeStaleIndexEntry(id, bloom, isStale = true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class ReferenceProvider(
scalaVersionSelector: ScalaVersionSelector,
)(implicit ec: ExecutionContext)
extends SemanticdbFeatureProvider {
val index: TrieMap[Path, IdentifierIndex.IndexEntryWithStaleInfo] =
val index: TrieMap[Path, IdentifierIndex.MaybeStaleIndexEntry] =
TrieMap.empty
val identifierIndex: IdentifierIndex = new IdentifierIndex

Expand Down Expand Up @@ -88,7 +88,7 @@ final class ReferenceProvider(
)

val entry =
IdentifierIndex.IndexEntryWithStaleInfo(id, bloom, isStale = false)
IdentifierIndex.MaybeStaleIndexEntry(id, bloom, isStale = false)
index(file.toNIO) = entry
docs.documents.foreach { d =>
d.occurrences.foreach { o =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ trait MtagsEnrichments extends ScalametaCommonEnrichments {
lazy val backtickedSetter =
text(pos.start) == '`' && text.length > pos.end + 4 && text
.slice(pos.end + 1, pos.end + 4)
.mkString == "_=`"
.mkString == backtickedSetterEnding
val isOldNameBackticked = text(pos.start) == '`' &&
(text(pos.end - 1) != '`' || pos.start == (pos.end - 1)) &&
text(pos.end + 1) == '`'
Expand All @@ -259,6 +259,8 @@ trait MtagsEnrichments extends ScalametaCommonEnrichments {
}
}

private val backtickedSetterEnding = "_=`"

implicit class XtensionRangeParameters(pos: RangeParams) {
def encloses(other: Position): Boolean =
pos.offset <= other.start && pos.endOffset >= other.end
Expand Down
60 changes: 30 additions & 30 deletions tests/slow/src/test/scala/tests/feature/PcReferencesLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,36 @@ class PcReferencesLspSuite
)

check(
s"apply-test_$scalaVersion",
"""|/a/src/main/scala/Defn.scala
|package a
|class O(v: Int) { }
|object O {
| def <<app@@ly>>() = new O(1)
|}
|/a/src/main/scala/Main.scala
|package a
|object Main {
| val g = <<O>>()
|}
|""".stripMargin,
scalaVersion,
)

check(
s"constructor_$scalaVersion",
"""|/a/src/main/scala/Defn.scala
|package a
|case class Name(<<val@@ue>>: String)
|
|/a/src/main/scala/Main.scala
|package a
|object Main {
| val name2 = new Name(<<value>> = "44")
|}
|""".stripMargin,
scalaVersion,
)
s"apply-test_$scalaVersion",
"""|/a/src/main/scala/Defn.scala
|package a
|class O(v: Int) { }
|object O {
| def <<app@@ly>>() = new O(1)
|}
|/a/src/main/scala/Main.scala
|package a
|object Main {
| val g = <<O>>()
|}
|""".stripMargin,
scalaVersion,
)

check(
s"constructor_$scalaVersion",
"""|/a/src/main/scala/Defn.scala
|package a
|case class Name(<<val@@ue>>: String)
|
|/a/src/main/scala/Main.scala
|package a
|object Main {
| val name2 = new Name(<<value>> = "44")
|}
|""".stripMargin,
scalaVersion,
)
}

def check(
Expand Down

0 comments on commit 9ed940e

Please sign in to comment.