@@ -75,7 +75,7 @@ object Completion:
75
75
customMatcher : Option [Name => Boolean ] = None
76
76
)(using Context ): CompletionMap =
77
77
val adjustedPath = typeCheckExtensionConstructPath(untpdPath, tpdPath, pos)
78
- computeCompletions(pos, mode, rawPrefix, adjustedPath, customMatcher)
78
+ computeCompletions(pos, mode, rawPrefix, adjustedPath, untpdPath, customMatcher)
79
79
80
80
/**
81
81
* Inspect `path` to determine what kinds of symbols should be considered.
@@ -199,12 +199,16 @@ object Completion:
199
199
.flatten.getOrElse(tpdPath)
200
200
201
201
private def computeCompletions (
202
- pos : SourcePosition , mode : Mode , rawPrefix : String , adjustedPath : List [tpd.Tree ], matches : Option [Name => Boolean ]
202
+ pos : SourcePosition ,
203
+ mode : Mode , rawPrefix : String ,
204
+ adjustedPath : List [tpd.Tree ],
205
+ untpdPath : List [untpd.Tree ],
206
+ matches : Option [Name => Boolean ]
203
207
)(using Context ): CompletionMap =
204
208
val hasBackTick = rawPrefix.headOption.contains('`' )
205
209
val prefix = if hasBackTick then rawPrefix.drop(1 ) else rawPrefix
206
210
val matches0 = matches.getOrElse(_.startsWith(prefix))
207
- val completer = new Completer (mode, pos, matches0)
211
+ val completer = new Completer (mode, pos, untpdPath, matches0)
208
212
209
213
val result = adjustedPath match
210
214
// Ignore synthetic select from `This` because in code it was `Ident`
@@ -279,6 +283,12 @@ object Completion:
279
283
if denot.isType then denot.symbol.showFullName
280
284
else denot.info.widenTermRefExpr.show
281
285
286
+
287
+ def isInNewContext (untpdPath : List [untpd.Tree ]): Boolean =
288
+ untpdPath match
289
+ case _ :: untpd.New (selectOrIdent : (untpd.Select | untpd.Ident )) :: _ => true
290
+ case _ => false
291
+
282
292
/** Include in completion sets only symbols that
283
293
* 1. is not absent (info is not NoType)
284
294
* 2. are not a primary constructor,
@@ -290,7 +300,11 @@ object Completion:
290
300
* 8. symbol is not a constructor proxy module when in type completion mode
291
301
* 9. have same term/type kind as name prefix given so far
292
302
*/
293
- def isValidCompletionSymbol (sym : Symbol , completionMode : Mode )(using Context ): Boolean =
303
+ def isValidCompletionSymbol (sym : Symbol , completionMode : Mode , isNew : Boolean )(using Context ): Boolean =
304
+
305
+ lazy val isEnum = sym.is(Enum ) ||
306
+ (sym.companionClass.exists && sym.companionClass.is(Enum ))
307
+
294
308
sym.exists &&
295
309
! sym.isAbsent() &&
296
310
! sym.isPrimaryConstructor &&
@@ -300,6 +314,7 @@ object Completion:
300
314
! sym.isPackageObject &&
301
315
! sym.is(Artifact ) &&
302
316
! (completionMode.is(Mode .Type ) && sym.isAllOf(ConstructorProxyModule )) &&
317
+ ! (isNew && isEnum) &&
303
318
(
304
319
(completionMode.is(Mode .Term ) && (sym.isTerm || sym.is(ModuleClass ))
305
320
|| (completionMode.is(Mode .Type ) && (sym.isType || sym.isStableMember)))
@@ -323,7 +338,7 @@ object Completion:
323
338
* For the results of all `xyzCompletions` methods term names and type names are always treated as different keys in the same map
324
339
* and they never conflict with each other.
325
340
*/
326
- class Completer (val mode : Mode , pos : SourcePosition , matches : Name => Boolean ):
341
+ class Completer (val mode : Mode , pos : SourcePosition , untpdPath : List [untpd. Tree ], matches : Name => Boolean ):
327
342
/** Completions for terms and types that are currently in scope:
328
343
* the members of the current class, local definitions and the symbols that have been imported,
329
344
* recursively adding completions from outer scopes.
@@ -530,7 +545,7 @@ object Completion:
530
545
// There are four possible ways for an extension method to be applicable
531
546
532
547
// 1. The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference.
533
- val termCompleter = new Completer (Mode .Term , pos, matches)
548
+ val termCompleter = new Completer (Mode .Term , pos, untpdPath, matches)
534
549
val extMethodsInScope = termCompleter.scopeCompletions.toList.flatMap:
535
550
case (name, denots) => denots.collect:
536
551
case d : SymDenotation if d.isTerm && d.termRef.symbol.is(Extension ) => (d.termRef, name.asTermName)
@@ -557,14 +572,16 @@ object Completion:
557
572
}
558
573
extMethodsWithAppliedReceiver.groupByName
559
574
575
+ lazy val isNew : Boolean = isInNewContext(untpdPath)
576
+
560
577
/** Include in completion sets only symbols that
561
578
* 1. match the filter method,
562
579
* 2. satisfy [[Completion.isValidCompletionSymbol ]]
563
580
*/
564
581
private def include (denot : SingleDenotation , nameInScope : Name )(using Context ): Boolean =
565
582
matches(nameInScope) &&
566
583
completionsFilter(NoType , nameInScope) &&
567
- isValidCompletionSymbol(denot.symbol, mode)
584
+ isValidCompletionSymbol(denot.symbol, mode, isNew )
568
585
569
586
private def extractRefinements (site : Type )(using Context ): Seq [SingleDenotation ] =
570
587
site match
0 commit comments