Skip to content

Change completions filtering to now include package module classes #14756

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

Merged
merged 1 commit into from
Mar 23, 2022
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ object Completion {
// 1. The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference.
val termCompleter = new Completer(Mode.Term, prefix, pos)
val extMethodsInScope = termCompleter.scopeCompletions.toList.flatMap {
case (name, denots) => denots.collect { case d: SymDenotation => (d.termRef, name.asTermName) }
case (name, denots) => denots.collect { case d: SymDenotation if d.isTerm => (d.termRef, name.asTermName) }
}

// 2. The extension method is a member of some given instance that is visible at the point of the reference.
Expand Down Expand Up @@ -467,8 +467,8 @@ object Completion {
!sym.isPackageObject &&
!sym.is(Artifact) &&
(
(mode.is(Mode.Term) && sym.isTerm)
|| (mode.is(Mode.Type) && (sym.isType || sym.isStableMember))
(mode.is(Mode.Term) && (sym.isTerm || sym.is(ModuleClass))
|| (mode.is(Mode.Type) && (sym.isType || sym.isStableMember)))
)

/** @param site The type to inspect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,4 +1224,25 @@ class CompletionTest {
|def foo(x: Bar[M]) = x.bar.ma${m1}"""
.withSource.completion(m1, expected)
}

@Test def packageCompletionsOutsideImport: Unit = {
val expected = Set(
("java", Module, "java"),
("javax", Module, "javax"),
)
code"""object Foo { ja${m1}"""
.withSource.completion(m1, expected)
}

@Test def topLevelPackagesCompletionsOutsideImport: Unit = {
val expected = Set(
("example", Module, "example"),
)
code"""package example:
| def foo = ""
|
|def main = exa${m1}"""
.withSource.completion(m1, expected)
}

}