@@ -14,7 +14,7 @@ import dotty.tools.dotc.core.Symbols.{defn, NoSymbol, Symbol}
1414import dotty .tools .dotc .core .Scopes
1515import dotty .tools .dotc .core .StdNames .{nme , tpnme }
1616import dotty .tools .dotc .core .TypeError
17- import dotty .tools .dotc .core .Types .{NamedType , Type , takeAllFilter }
17+ import dotty .tools .dotc .core .Types .{NameFilter , NamedType , Type , NoType }
1818import dotty .tools .dotc .printing .Texts ._
1919import dotty .tools .dotc .util .{NoSourcePosition , SourcePosition }
2020
@@ -220,7 +220,10 @@ object Completion {
220220 * inclusion filter, then add it to the completions.
221221 */
222222 private def add (sym : Symbol , nameInScope : Name )(implicit ctx : Context ) =
223- if (sym.exists && ! completions.lookup(nameInScope).exists && include(sym, nameInScope)) {
223+ if (sym.exists &&
224+ completionsFilter(NoType , nameInScope) &&
225+ ! completions.lookup(nameInScope).exists &&
226+ include(sym, nameInScope)) {
224227 completions.enter(sym, nameInScope)
225228 }
226229
@@ -232,20 +235,16 @@ object Completion {
232235
233236 /** Include in completion sets only symbols that
234237 * 1. start with given name prefix, and
235- * 2. do not contain '$' except in prefix where it is explicitly written by user, and
238+ * 2. is not absent (info is not NoType)
236239 * 3. are not a primary constructor,
237240 * 4. have an existing source symbol,
238241 * 5. are the module class in case of packages,
239242 * 6. are mutable accessors, to exclude setters for `var`,
240243 * 7. have same term/type kind as name prefix given so far
241- *
242- * The reason for (2) is that we do not want to present compiler-synthesized identifiers
243- * as completion results. However, if a user explicitly writes all '$' characters in an
244- * identifier, we should complete the rest.
245244 */
246245 private def include (sym : Symbol , nameInScope : Name )(implicit ctx : Context ): Boolean =
247246 nameInScope.startsWith(prefix) &&
248- ! nameInScope.toString.drop(prefix.length).contains( '$' ) &&
247+ ! sym.isAbsent &&
249248 ! sym.isPrimaryConstructor &&
250249 sym.sourceSymbol.exists &&
251250 (! sym.is(Package ) || ! sym.moduleClass.exists) &&
@@ -263,12 +262,13 @@ object Completion {
263262 */
264263 private def accessibleMembers (site : Type )(implicit ctx : Context ): Seq [Symbol ] = site match {
265264 case site : NamedType if site.symbol.is(Package ) =>
266- site.decls.toList.filter(sym => include(sym, sym.name)) // Don't look inside package members -- it's too expensive.
265+ // Don't look inside package members -- it's too expensive.
266+ site.decls.toList.filter(sym => sym.isAccessibleFrom(site, superAccess = false ))
267267 case _ =>
268268 def appendMemberSyms (name : Name , buf : mutable.Buffer [SingleDenotation ]): Unit =
269269 try buf ++= site.member(name).alternatives
270270 catch { case ex : TypeError => }
271- site.memberDenots(takeAllFilter , appendMemberSyms).collect {
271+ site.memberDenots(completionsFilter , appendMemberSyms).collect {
272272 case mbr if include(mbr.symbol, mbr.symbol.name) => mbr.accessibleFrom(site, superAccess = true ).symbol
273273 case _ => NoSymbol
274274 }.filter(_.exists)
@@ -315,6 +315,12 @@ object Completion {
315315 targets
316316 }
317317
318+ /** Filter for names that should appear when looking for completions. */
319+ private [this ] object completionsFilter extends NameFilter {
320+ def apply (pre : Type , name : Name )(implicit ctx : Context ): Boolean =
321+ ! name.isConstructorName && name.toTermName.info.kind == SimpleNameKind
322+ }
323+
318324 }
319325
320326 /**
0 commit comments