Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly auto import when there is a renamed symbol with the same name in scope #6480

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ sealed trait IndexedContext:
// when all the conflicting symbols came from an old version of the file
case Some(symbols) if symbols.nonEmpty && symbols.forall(_.isStale) =>
Result.Missing
case Some(_) => Result.Conflict
case None => Result.Missing
case Some(symbols) if symbols.exists(rename(_).isEmpty) => Result.Conflict
case _ => Result.Missing
end lookupSym

final def hasRename(sym: Symbol, as: String): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,12 @@ class Completions(
then
indexedContext.lookupSym(sym) match
case IndexedContext.Result.InScope =>
val name =
indexedContext.rename(sym) match
case Some(rename) => rename
case None => sym.decodedName
visit(
CompletionValue.Scope(sym.decodedName, sym, findSuffix(sym))
CompletionValue.Scope(name, sym, findSuffix(sym))
)
case _ =>
completionsWithSuffix(
Expand Down
31 changes: 31 additions & 0 deletions tests/cross/src/test/scala/tests/pc/AutoImportsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,37 @@ class AutoImportsSuite extends BaseAutoImportsSuite {
)
)

checkEdit(
"i6477".tag(IgnoreScala2),
"""|package a
|import a.b.SomeClass as SC
|
|package b {
| class SomeClass
|}
|package c {
| class SomeClass
|}
|
|val bar: SC = ???
|val foo: <<SomeClass>> = ???
|""".stripMargin,
"""|package a
|import a.b.SomeClass as SC
|import a.c.SomeClass
|
|package b {
| class SomeClass
|}
|package c {
| class SomeClass
|}
|
|val bar: SC = ???
|val foo: SomeClass = ???
|""".stripMargin
)

private def ammoniteWrapper(code: String): String =
// Vaguely looks like a scala file that Ammonite generates
// from a sc file.
Expand Down
64 changes: 64 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionScala3Suite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,68 @@ class CompletionScala3Suite extends BaseCompletionSuite {
|SetOps scala.collection
|""".stripMargin
)

checkEdit(
"i6477-1",
"""|package a
|import a.b.SomeClass as SC
|
|package b {
| class SomeClass
|}
|package c {
| class SomeClass
|}
|
|val bar: SC = ???
|val foo: SomeClass@@
|""".stripMargin,
"""|package a
|import a.b.SomeClass as SC
|
|package b {
| class SomeClass
|}
|package c {
| class SomeClass
|}
|
|val bar: SC = ???
|val foo: SC
|""".stripMargin,
assertSingleItem = false
)

checkEdit(
"i6477-2",
"""|package a
|import a.b.SomeClass as SC
|
|package b {
| class SomeClass
|}
|package c {
| class SomeClass
|}
|
|val bar: SC = ???
|val foo: SomeClass@@
|""".stripMargin,
"""|package a
|import a.b.SomeClass as SC
|import a.c.SomeClass
|
|package b {
| class SomeClass
|}
|package c {
| class SomeClass
|}
|
|val bar: SC = ???
|val foo: SomeClass
|""".stripMargin,
assertSingleItem = false,
itemIndex = 1
)
}
Loading