@@ -86,26 +86,21 @@ object Completion:
86
86
*
87
87
* Otherwise, provide no completion suggestion.
88
88
*/
89
- def completionMode (path : List [untpd.Tree ], pos : SourcePosition ): Mode =
90
-
91
- val completionSymbolKind : Mode =
92
- path match
93
- case GenericImportSelector (sel) =>
94
- if sel.imported.span.contains(pos.span) then Mode .ImportOrExport // import scala.@@
95
- else if sel.isGiven && sel.bound.span.contains(pos.span) then Mode .ImportOrExport
96
- else Mode .None // import scala.{util => u@@}
97
- case GenericImportOrExport (_) => Mode .ImportOrExport | Mode .Scope // import TrieMa@@
98
- case untpd.Literal (Constants .Constant (_ : String )) :: _ => Mode .Term | Mode .Scope // literal completions
99
- case (ref : untpd.RefTree ) :: _ =>
100
- val maybeSelectMembers = if ref.isInstanceOf [untpd.Select ] then Mode .Member else Mode .Scope
101
-
102
- if (ref.name.isTermName) Mode .Term | maybeSelectMembers
103
- else if (ref.name.isTypeName) Mode .Type | maybeSelectMembers
104
- else Mode .None
105
-
106
- case _ => Mode .None
107
-
108
- completionSymbolKind
89
+ def completionMode (path : List [untpd.Tree ], pos : SourcePosition ): Mode = path match
90
+ case GenericImportSelector (sel) =>
91
+ if sel.imported.span.contains(pos.span) then Mode .ImportOrExport // import scala.@@
92
+ else if sel.isGiven && sel.bound.span.contains(pos.span) then Mode .ImportOrExport
93
+ else Mode .None // import scala.{util => u@@}
94
+ case GenericImportOrExport (_) => Mode .ImportOrExport | Mode .Scope // import TrieMa@@
95
+ case untpd.Literal (Constants .Constant (_ : String )) :: _ => Mode .Term | Mode .Scope // literal completions
96
+ case (ref : untpd.RefTree ) :: _ =>
97
+ val maybeSelectMembers = if ref.isInstanceOf [untpd.Select ] then Mode .Member else Mode .Scope
98
+
99
+ if (ref.name.isTermName) Mode .Term | maybeSelectMembers
100
+ else if (ref.name.isTypeName) Mode .Type | maybeSelectMembers
101
+ else Mode .None
102
+
103
+ case _ => Mode .None
109
104
110
105
/** When dealing with <errors> in varios palces we check to see if they are
111
106
* due to incomplete backticks. If so, we ensure we get the full prefix
@@ -130,7 +125,7 @@ object Completion:
130
125
def completionPrefix (path : List [untpd.Tree ], pos : SourcePosition )(using Context ): String =
131
126
def fallback : Int =
132
127
var i = pos.point - 1
133
- while i >= 0 && Chars .isIdentifierPart (pos.source.content()(i)) do i -= 1
128
+ while i >= 0 && Character .isUnicodeIdentifierPart (pos.source.content()(i)) do i -= 1
134
129
i + 1
135
130
136
131
path match
@@ -278,6 +273,32 @@ object Completion:
278
273
if denot.isType then denot.symbol.showFullName
279
274
else denot.info.widenTermRefExpr.show
280
275
276
+ /** Include in completion sets only symbols that
277
+ * 1. is not absent (info is not NoType)
278
+ * 2. are not a primary constructor,
279
+ * 3. have an existing source symbol,
280
+ * 4. are the module class in case of packages,
281
+ * 5. are mutable accessors, to exclude setters for `var`,
282
+ * 6. symbol is not a package object
283
+ * 7. symbol is not an artifact of the compiler
284
+ * 8. symbol is not a constructor proxy module when in type completion mode
285
+ * 9. have same term/type kind as name prefix given so far
286
+ */
287
+ def isValidCompletionSymbol (sym : Symbol , completionMode : Mode )(using Context ): Boolean =
288
+ sym.exists &&
289
+ ! sym.isAbsent() &&
290
+ ! sym.isPrimaryConstructor &&
291
+ sym.sourceSymbol.exists &&
292
+ (! sym.is(Package ) || sym.is(ModuleClass )) &&
293
+ ! sym.isAllOf(Mutable | Accessor ) &&
294
+ ! sym.isPackageObject &&
295
+ ! sym.is(Artifact ) &&
296
+ ! (completionMode.is(Mode .Type ) && sym.isAllOf(ConstructorProxyModule )) &&
297
+ (
298
+ (completionMode.is(Mode .Term ) && (sym.isTerm || sym.is(ModuleClass ))
299
+ || (completionMode.is(Mode .Type ) && (sym.isType || sym.isStableMember)))
300
+ )
301
+
281
302
given ScopeOrdering (using Context ): Ordering [Seq [SingleDenotation ]] with
282
303
val order =
283
304
List (defn.ScalaPredefModuleClass , defn.ScalaPackageClass , defn.JavaLangPackageClass )
@@ -531,34 +552,13 @@ object Completion:
531
552
extMethodsWithAppliedReceiver.groupByName
532
553
533
554
/** Include in completion sets only symbols that
534
- * 1. start with given name prefix, and
535
- * 2. is not absent (info is not NoType)
536
- * 3. are not a primary constructor,
537
- * 4. have an existing source symbol,
538
- * 5. are the module class in case of packages,
539
- * 6. are mutable accessors, to exclude setters for `var`,
540
- * 7. symbol is not a package object
541
- * 8. symbol is not an artifact of the compiler
542
- * 9. have same term/type kind as name prefix given so far
555
+ * 1. match the filter method,
556
+ * 2. satisfy [[Completion.isValidCompletionSymbol ]]
543
557
*/
544
558
private def include (denot : SingleDenotation , nameInScope : Name )(using Context ): Boolean =
545
- val sym = denot.symbol
546
-
547
-
548
559
nameInScope.startsWith(prefix) &&
549
- sym.exists &&
550
560
completionsFilter(NoType , nameInScope) &&
551
- ! sym.isAbsent() &&
552
- ! sym.isPrimaryConstructor &&
553
- sym.sourceSymbol.exists &&
554
- (! sym.is(Package ) || sym.is(ModuleClass )) &&
555
- ! sym.isAllOf(Mutable | Accessor ) &&
556
- ! sym.isPackageObject &&
557
- ! sym.is(Artifact ) &&
558
- (
559
- (mode.is(Mode .Term ) && (sym.isTerm || sym.is(ModuleClass ))
560
- || (mode.is(Mode .Type ) && (sym.isType || sym.isStableMember)))
561
- )
561
+ isValidCompletionSymbol(denot.symbol, mode)
562
562
563
563
private def extractRefinements (site : Type )(using Context ): Seq [SingleDenotation ] =
564
564
site match
0 commit comments