From f6228da0e881e961efac557372ba2ff68d94cdc8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 15 Jan 2019 15:40:16 +0100 Subject: [PATCH 1/5] Fix #5237: Do not list in scala packege completions --- compiler/src/dotty/tools/dotc/interactive/Completion.scala | 7 +++++-- compiler/test/dotty/tools/repl/TabcompleteTests.scala | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index d740d4098e3e..0a037ec3fb08 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -140,7 +140,7 @@ object Completion { private[this] val completions = new RenameAwareScope /** - * Return the list of symbols that shoudl be included in completion results. + * Return the list of symbols that should be included in completion results. * * If several symbols share the same name, the type symbols appear before term symbols inside * the same `Completion`. @@ -252,7 +252,10 @@ object Completion { ( (mode.is(Mode.Term) && sym.isTerm) || (mode.is(Mode.Type) && (sym.isType || sym.isStable)) - ) + ) && + (sym ne defn.RepeatedParamClass) && + (sym ne defn.ByNameParamClass2x) && + (sym ne defn.EqualsPatternClass) /** * Find all the members of `site` that are accessible and which should be included in `info`. diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index 20b3552cdaef..4fe62d2c0982 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -90,4 +90,10 @@ class TabcompleteTests extends ReplTest { val expected = List("Renamed") assertEquals(expected, tabComplete("val foo: Rena")) } + + @Test def importScala = fromInitialState { implicit s => + val comp = tabComplete("import scala.") + // check that there are no special symbols leaked: , , ... + assertEquals(comp.find(_.startsWith("<")), None) + } } From 3aebfaba164cc5b27b914d5234de63ac49fcb09b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 15 Jan 2019 15:46:02 +0100 Subject: [PATCH 2/5] Do not complete `package` as a member of some package --- compiler/src/dotty/tools/dotc/interactive/Completion.scala | 1 + compiler/test/dotty/tools/repl/TabcompleteTests.scala | 1 + 2 files changed, 2 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 0a037ec3fb08..f756b9ad6f5b 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -253,6 +253,7 @@ object Completion { (mode.is(Mode.Term) && sym.isTerm) || (mode.is(Mode.Type) && (sym.isType || sym.isStable)) ) && + !sym.isPackageObject && (sym ne defn.RepeatedParamClass) && (sym ne defn.ByNameParamClass2x) && (sym ne defn.EqualsPatternClass) diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index 4fe62d2c0982..7dc82fbb9988 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -95,5 +95,6 @@ class TabcompleteTests extends ReplTest { val comp = tabComplete("import scala.") // check that there are no special symbols leaked: , , ... assertEquals(comp.find(_.startsWith("<")), None) + assert(!comp.contains("package")) } } From de16b016733772392bbbf51a76cc2376b94386c8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 15 Jan 2019 16:40:42 +0100 Subject: [PATCH 3/5] Add Artifact to SpecialPolyClass constructor and use in Completion --- compiler/src/dotty/tools/dotc/core/Definitions.scala | 2 +- compiler/src/dotty/tools/dotc/interactive/Completion.scala | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index a3f4191b7af1..24c7f5910f59 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -80,7 +80,7 @@ class Definitions { denot.info = ClassInfo(ScalaPackageClass.thisType, cls, parents, paramDecls) } } - newClassSymbol(ScalaPackageClass, name, EmptyFlags, completer).entered + newClassSymbol(ScalaPackageClass, name, Artifact, completer).entered } /** The trait FunctionN, ImplicitFunctionN, ErasedFunctionN or ErasedImplicitFunction, for some N diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index f756b9ad6f5b..9d7bda65ca1a 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -254,9 +254,7 @@ object Completion { || (mode.is(Mode.Type) && (sym.isType || sym.isStable)) ) && !sym.isPackageObject && - (sym ne defn.RepeatedParamClass) && - (sym ne defn.ByNameParamClass2x) && - (sym ne defn.EqualsPatternClass) + !sym.is(Artifact) /** * Find all the members of `site` that are accessible and which should be included in `info`. From 2a5d062ebe6adda2dd37a1e431439f19c07816f5 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 15 Jan 2019 17:24:20 +0100 Subject: [PATCH 4/5] Move conditions and update doc --- .../src/dotty/tools/dotc/interactive/Completion.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 9d7bda65ca1a..bc6408e996bb 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -240,7 +240,9 @@ object Completion { * 4. have an existing source symbol, * 5. are the module class in case of packages, * 6. are mutable accessors, to exclude setters for `var`, - * 7. have same term/type kind as name prefix given so far + * 7. symbol is not a package object + * 8. symbol is not an atifact of the compiler + * 9. have same term/type kind as name prefix given so far */ private def include(sym: Symbol, nameInScope: Name)(implicit ctx: Context): Boolean = nameInScope.startsWith(prefix) && @@ -249,12 +251,12 @@ object Completion { sym.sourceSymbol.exists && (!sym.is(Package) || !sym.moduleClass.exists) && !sym.is(allOf(Mutable, Accessor)) && + !sym.isPackageObject && + !sym.is(Artifact) && ( (mode.is(Mode.Term) && sym.isTerm) || (mode.is(Mode.Type) && (sym.isType || sym.isStable)) - ) && - !sym.isPackageObject && - !sym.is(Artifact) + ) /** * Find all the members of `site` that are accessible and which should be included in `info`. From 438c74df3073e4bc16969a5e29265e38dc5273b6 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Tue, 15 Jan 2019 18:03:41 +0100 Subject: [PATCH 5/5] Update compiler/src/dotty/tools/dotc/interactive/Completion.scala Co-Authored-By: nicolasstucki --- compiler/src/dotty/tools/dotc/interactive/Completion.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index bc6408e996bb..5060aae3d2fb 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -241,7 +241,7 @@ object Completion { * 5. are the module class in case of packages, * 6. are mutable accessors, to exclude setters for `var`, * 7. symbol is not a package object - * 8. symbol is not an atifact of the compiler + * 8. symbol is not an artifact of the compiler * 9. have same term/type kind as name prefix given so far */ private def include(sym: Symbol, nameInScope: Name)(implicit ctx: Context): Boolean =