From 7c76ded6b1e02a986d68ea8b3138a257afc5baba Mon Sep 17 00:00:00 2001 From: Vadim Chelyshov Date: Fri, 7 Jun 2024 15:21:50 +0300 Subject: [PATCH] completions: do not complete package There is an issue with completions for package in Metals. ```scala // code package one@@ // compeltions oneCURSOR ``` It seems there is no need in completions for Package at all. --- .../dotty/tools/dotc/interactive/Completion.scala | 2 ++ .../pc/tests/completion/CompletionSuite.scala | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 8a1cc10373db..e59a8e0b882d 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -90,6 +90,8 @@ object Completion: * Otherwise, provide no completion suggestion. */ def completionMode(path: List[untpd.Tree], pos: SourcePosition): Mode = path match + // Ignore `package foo@@` and `package foo.bar@@` + case ((_: tpd.Select) | (_: tpd.Ident)):: (_ : tpd.PackageDef) :: _ => Mode.None case GenericImportSelector(sel) => if sel.imported.span.contains(pos.span) then Mode.ImportOrExport // import scala.@@ else if sel.isGiven && sel.bound.span.contains(pos.span) then Mode.ImportOrExport diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala index 2c216b4c40f7..f3fc03b3fb33 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala @@ -2223,3 +2223,17 @@ class CompletionSuite extends BaseCompletionSuite: |""".stripMargin, topLines = Some(3) ) + + @Test def `packageIssueIdent` = + check( + """package one@@ + |""".stripMargin, + "" + ) + + @Test def `packageIssueSelect` = + check( + """package one.two@@ + |""".stripMargin, + "" + )