Skip to content

Commit bfae5dd

Browse files
committed
Fix extension member completions on packages
1 parent 66d15b2 commit bfae5dd

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ object Completion:
370370
* For the results of all `xyzCompletions` methods term names and type names are always treated as different keys in the same map
371371
* and they never conflict with each other.
372372
*/
373-
class Completer(val mode: Mode, pos: SourcePosition, untpdPath: List[untpd.Tree], matches: Name => Boolean):
373+
class Completer(val mode: Mode, pos: SourcePosition, untpdPath: List[untpd.Tree], matches: Name => Boolean)(using Context):
374374
/** Completions for terms and types that are currently in scope:
375375
* the members of the current class, local definitions and the symbols that have been imported,
376376
* recursively adding completions from outer scopes.
@@ -384,7 +384,7 @@ object Completion:
384384
* (even if the import follows it syntactically)
385385
* - a more deeply nested import shadowing a member or a local definition causes an ambiguity
386386
*/
387-
def scopeCompletions(using context: Context): CompletionResult =
387+
lazy val scopeCompletions: CompletionResult =
388388

389389
/** Temporary data structure representing denotations with the same name introduced in a given scope
390390
* as a member of a type, by a local definition or by an import clause
@@ -619,8 +619,7 @@ object Completion:
619619
// There are four possible ways for an extension method to be applicable
620620

621621
// 1. The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference.
622-
val termCompleter = new Completer(Mode.Term, pos, untpdPath, matches)
623-
val extMethodsInScope = termCompleter.scopeCompletions.names.toList.flatMap:
622+
val extMethodsInScope = scopeCompletions.names.toList.flatMap:
624623
case (name, denots) => denots.collect:
625624
case d: SymDenotation if d.isTerm && d.termRef.symbol.is(Extension) => (d.termRef, name.asTermName)
626625

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,3 +2250,10 @@ class CompletionSuite extends BaseCompletionSuite:
22502250
|""".stripMargin,
22512251
""
22522252
)
2253+
2254+
@Test def `no-completions-on-package-selection` =
2255+
check(
2256+
"""package one.@@
2257+
|""".stripMargin,
2258+
""
2259+
)

0 commit comments

Comments
 (0)