Skip to content

Commit d8833c0

Browse files
committed
Complete when improting same symbol multiple times
This is related to #13623 - since it seems that Predef might be imported more than once, but this doesn't yet solve the issue.
1 parent f215817 commit d8833c0

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,22 @@ object Completion {
201201

202202
mappings.foreach { (name, denotss) =>
203203
val first = denotss.head
204+
205+
// import a.c
206+
def isSingleImport = denotss.length < 2
207+
// import a.C
208+
// locally { import b.C }
209+
def isImportedInDifferentScope = first.ctx.scope ne denotss(1).ctx.scope
210+
// import a.C
211+
// import a.C
212+
def isSameSymbolImportedDouble = denotss.forall(_.denots == first.denots)
213+
204214
denotss.find(!_.ctx.isImportContext) match {
205215
// most deeply nested member or local definition if not shadowed by an import
206216
case Some(local) if local.ctx.scope == first.ctx.scope =>
207217
resultMappings += name -> local.denots
208218

209-
// most deeply nested import if not shadowed by another import
210-
case None if denotss.length < 2 || (denotss(1).ctx.scope ne first.ctx.scope) =>
219+
case None if isSingleImport || isImportedInDifferentScope || isSameSymbolImportedDouble =>
211220
resultMappings += name -> first.denots
212221

213222
case _ =>

language-server/test/dotty/tools/languageserver/CompletionTest.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,19 @@ class CompletionTest {
404404
.completion(m1, Set())
405405
}
406406

407+
@Test def completeFromSameImportsForEqualNestingLevels: Unit = {
408+
code"""object Foo {
409+
| def xxxx(i: Int): Int = i
410+
|}
411+
|object Test {
412+
| import Foo.xxxx
413+
| import Foo.xxxx
414+
| import Foo.xxxx
415+
| val x = xx$m1
416+
|}""".withSource
417+
.completion(m1, Set(("xxxx", Method, "(i: Int): Int")))
418+
}
419+
407420
@Test def preferLocalDefinitionToImportForEqualNestingLevels: Unit = {
408421
code"""object Foo {
409422
| val xxxx = 1

0 commit comments

Comments
 (0)