From 73dc017b5cea65569c8c501ecf8a8a7301ec40e0 Mon Sep 17 00:00:00 2001 From: ghostbuster91 Date: Tue, 26 Oct 2021 19:34:14 +0200 Subject: [PATCH 1/3] Fix missing code-completion on standalone annotations Co-authored-by: Stefan Pavikevik Co-authored-by: Tomasz Godzik Co-authored-by: Anatolii Kmetiuk --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 6 +++++- compiler/test/dotty/tools/repl/TabcompleteTests.scala | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index aff7218e662b..63b6e9f8ac51 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3472,7 +3472,11 @@ object Parsers { givenDef(start, mods, atSpan(in.skipToken()) { Mod.Given() }) case _ => syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition()) - EmptyTree + mods.annotations match { + case head :: Nil => head + case Nil => EmptyTree + case all => Block(all, errorTermTree) + } } /** ClassDef ::= id ClassConstr TemplateOpt diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index 932ab7058899..df5a159277b7 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -138,4 +138,8 @@ class TabcompleteTests extends ReplTest { tabComplete("import quoted.* ; def fooImpl(using Quotes): Expr[Int] = { import quotes.reflect.* ; TypeRepr.of[Int].s")) } + @Test def i13624 = fromInitialState { implicit s => + assertEquals(List("implicitNotFound"), tabComplete("@annotation.implicitNot")) + assertEquals(List("main"), tabComplete("@annotation.implicitNotFound @mai")) + } } From eef5d76b5f1073151a5f96d4b069fac57b3a311e Mon Sep 17 00:00:00 2001 From: ghostbuster91 Date: Mon, 1 Nov 2021 07:31:09 +0100 Subject: [PATCH 2/3] Move tests to CompletionTests file --- .../dotty/tools/repl/TabcompleteTests.scala | 5 ----- .../tools/languageserver/CompletionTest.scala | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index df5a159277b7..dd5d5391a788 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -137,9 +137,4 @@ class TabcompleteTests extends ReplTest { assertEquals(List("select", "show", "simplified", "substituteTypes"), tabComplete("import quoted.* ; def fooImpl(using Quotes): Expr[Int] = { import quotes.reflect.* ; TypeRepr.of[Int].s")) } - - @Test def i13624 = fromInitialState { implicit s => - assertEquals(List("implicitNotFound"), tabComplete("@annotation.implicitNot")) - assertEquals(List("main"), tabComplete("@annotation.implicitNotFound @mai")) - } } diff --git a/language-server/test/dotty/tools/languageserver/CompletionTest.scala b/language-server/test/dotty/tools/languageserver/CompletionTest.scala index 1dd9516de7d1..6ef219187475 100644 --- a/language-server/test/dotty/tools/languageserver/CompletionTest.scala +++ b/language-server/test/dotty/tools/languageserver/CompletionTest.scala @@ -946,4 +946,21 @@ class CompletionTest { ("MyAnnotation", Module, "Foo.MyAnnotation") ) ) + + @Test def i13624_annotation : Unit = + code"""@annotation.implicitNot${m1} + |@annotation.implicitNotFound @mai${m2}""" + .withSource + .completion(m1, + Set( + ("implicitNotFound", Class, "scala.annotation.implicitNotFound"), + ("implicitNotFound", Module, "scala.annotation.implicitNotFound") + ) + ) + .completion(m2, + Set( + ("main", Class, "scala.main"), + ("main", Module, "main") + ) + ) } From b0de71eaa707719009abe7d88178192208b22208 Mon Sep 17 00:00:00 2001 From: ghostbuster91 Date: Mon, 1 Nov 2021 07:33:37 +0100 Subject: [PATCH 3/3] Add unnecessary deleted empty line --- compiler/test/dotty/tools/repl/TabcompleteTests.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index dd5d5391a788..932ab7058899 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -137,4 +137,5 @@ class TabcompleteTests extends ReplTest { assertEquals(List("select", "show", "simplified", "substituteTypes"), tabComplete("import quoted.* ; def fooImpl(using Quotes): Expr[Int] = { import quotes.reflect.* ; TypeRepr.of[Int].s")) } + }