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 6, 2024
1 parent be9ad2e commit e21a048
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 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 @@ -1276,8 +1276,8 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite {
"""|package a
|
|trait Base:
| def foo(x: Int): Int
| def bar(x: String): String
| def foo(x: Int): Int
|
|case class <<Concrete>>() extends Base:
| def aaa = "aaa"
Expand All @@ -1286,8 +1286,8 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite {
"""|package a
|
|trait Base:
| def foo(x: Int): Int
| def bar(x: String): String
| def foo(x: Int): Int
|
|case class Concrete() extends Base:
|
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 e21a048

Please sign in to comment.