Skip to content

Commit

Permalink
fix: prefer latter fully qualified name parts when building trigrams …
Browse files Browse the repository at this point in the history
…for fuzzy search
  • Loading branch information
kasiaMarek committed Jun 14, 2024
1 parent 5e40b2a commit ac36e97
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ object TrigramSubstrings {
* Iterate over all possible substrings of length 3 for the given string.
*/
def foreach(
string: String,
inString: String,
f: String => Unit,
maxResults: Int = DefaultMaxTrigrams
): Unit = {
val string = inString.reverse
val N = string.length
val arr = new Array[Char](3)
var max = maxResults
Expand All @@ -31,9 +32,9 @@ object TrigramSubstrings {
while (j < N && isNotDone) {
var k = j + 1
while (k < N && isNotDone) {
arr(0) = string.charAt(i)
arr(2) = string.charAt(i)
arr(1) = string.charAt(j)
arr(2) = string.charAt(k)
arr(0) = string.charAt(k)
f(new String(arr))
max -= 1
k += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,33 @@ class ImportMissingSymbolCrossLspSuite
scalacOptions = List("-explain"),
)

check(
"i6475",
"""|package com.scalaFakePackage.test.latestCommentByItem.domain.projection.latestCommentByItemView
|package subscriber {
| class CreateLatestCommentByItemSubscriber
|}
|package a {
| object O {
| val g: <<CreateLatestCommentByItemSubscriber>> = ???
| }
|}
|""".stripMargin,
s"""|${ImportMissingSymbol.title("CreateLatestCommentByItemSubscriber", "com.scalaFakePackage.test.latestCommentByItem.domain.projection.latestCommentByItemView.subscriber")}
|${CreateNewSymbol.title("CreateLatestCommentByItemSubscriber")}""".stripMargin,
"""|package com.scalaFakePackage.test.latestCommentByItem.domain.projection.latestCommentByItemView
|
|import com.scalaFakePackage.test.latestCommentByItem.domain.projection.latestCommentByItemView.subscriber.CreateLatestCommentByItemSubscriber
|package subscriber {
| class CreateLatestCommentByItemSubscriber
|}
|package a {
| object O {
| val g: CreateLatestCommentByItemSubscriber = ???
| }
|}
|""".stripMargin,
scalaVersion = "3.3.3",
)

}
6 changes: 3 additions & 3 deletions tests/unit/src/test/scala/tests/TrigramSubstringsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class TrigramSubstringsSuite extends BaseSuite {
check(
"abcd",
"""
|abc
|abd
|acd
|bcd
|acd
|abd
|abc
|""".stripMargin,
)

Expand Down

0 comments on commit ac36e97

Please sign in to comment.