@@ -14,7 +14,7 @@ import dotty.tools.dotc.core.Symbols.{defn, NoSymbol, Symbol}
14
14
import dotty .tools .dotc .core .Scopes
15
15
import dotty .tools .dotc .core .StdNames .{nme , tpnme }
16
16
import 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 }
18
18
import dotty .tools .dotc .printing .Texts ._
19
19
import dotty .tools .dotc .util .{NoSourcePosition , SourcePosition }
20
20
@@ -220,7 +220,10 @@ object Completion {
220
220
* inclusion filter, then add it to the completions.
221
221
*/
222
222
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)) {
224
227
completions.enter(sym, nameInScope)
225
228
}
226
229
@@ -232,20 +235,16 @@ object Completion {
232
235
233
236
/** Include in completion sets only symbols that
234
237
* 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)
236
239
* 3. are not a primary constructor,
237
240
* 4. have an existing source symbol,
238
241
* 5. are the module class in case of packages,
239
242
* 6. are mutable accessors, to exclude setters for `var`,
240
243
* 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.
245
244
*/
246
245
private def include (sym : Symbol , nameInScope : Name )(implicit ctx : Context ): Boolean =
247
246
nameInScope.startsWith(prefix) &&
248
- ! nameInScope.toString.drop(prefix.length).contains( '$' ) &&
247
+ ! sym.isAbsent &&
249
248
! sym.isPrimaryConstructor &&
250
249
sym.sourceSymbol.exists &&
251
250
(! sym.is(Package ) || ! sym.moduleClass.exists) &&
@@ -263,12 +262,13 @@ object Completion {
263
262
*/
264
263
private def accessibleMembers (site : Type )(implicit ctx : Context ): Seq [Symbol ] = site match {
265
264
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 ))
267
267
case _ =>
268
268
def appendMemberSyms (name : Name , buf : mutable.Buffer [SingleDenotation ]): Unit =
269
269
try buf ++= site.member(name).alternatives
270
270
catch { case ex : TypeError => }
271
- site.memberDenots(takeAllFilter , appendMemberSyms).collect {
271
+ site.memberDenots(completionsFilter , appendMemberSyms).collect {
272
272
case mbr if include(mbr.symbol, mbr.symbol.name) => mbr.accessibleFrom(site, superAccess = true ).symbol
273
273
case _ => NoSymbol
274
274
}.filter(_.exists)
@@ -315,6 +315,12 @@ object Completion {
315
315
targets
316
316
}
317
317
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
+
318
324
}
319
325
320
326
/**
0 commit comments