@@ -220,28 +220,19 @@ object Interactive {
220
220
* 1. start with given name prefix, and
221
221
* 2. do not contain '$' except in prefix where it is explicitly written by user, and
222
222
* 3. are not a primary constructor,
223
- * 4. have an existing source symbol,
224
- * 5. are the module class in case of packages,
225
- * 6. are not Java module classes when completing imports (to avoid duplicate results).
226
- * 7. are mutable accessors, to exclude setters for `var`,
227
- * 8. have same term/type kind as name prefix given so far
223
+ * 4. are the module class in case of packages,
224
+ * 5. are mutable accessors, to exclude setters for `var`,
225
+ * 6. have same term/type kind as name prefix given so far
228
226
*
229
227
* The reason for (2) is that we do not want to present compiler-synthesized identifiers
230
228
* as completion results. However, if a user explicitly writes all '$' characters in an
231
229
* identifier, we should complete the rest.
232
- *
233
- * The reason for (4) is that we want to filter, for instance, non-existnet `Module`
234
- * symbols that accompany class symbols. We can't simply return only the source symbols,
235
- * because this would discard some synthetic symbols such as the copy method of case
236
- * classes.
237
230
*/
238
231
def include (sym : Symbol ) =
239
232
sym.name.startsWith(info.prefix) &&
240
233
! sym.name.toString.drop(info.prefix.length).contains('$' ) &&
241
234
! sym.isPrimaryConstructor &&
242
- sym.sourceSymbol.exists &&
243
235
(! sym.is(Package ) || ! sym.moduleClass.exists) &&
244
- (! info.inImport || ! sym.is(allOf(JavaDefined , Module ), butNot = Package )) &&
245
236
! sym.is(allOf(Mutable , Accessor )) &&
246
237
(! info.termOnly || sym.isTerm) &&
247
238
(! info.typeOnly || sym.isType)
@@ -336,7 +327,16 @@ object Interactive {
336
327
case _ => getScopeCompletions(ctx)
337
328
}
338
329
339
- val completionList = completions.toList
330
+ val completionList =
331
+ if (! info.inImport) completions.toList
332
+ else {
333
+ // In imports, show only the type symbols when there are multiple options with the same name
334
+ completions.toList.groupBy(_.name.stripModuleClassSuffix.toSimpleName).mapValues {
335
+ case sym :: Nil => sym :: Nil
336
+ case syms => syms.filter(_.isType)
337
+ }.values.flatten.toList
338
+ }
339
+
340
340
interactiv.println(i " completion with pos = $pos, prefix = $info.prefix, termOnly = $info.termOnly, typeOnly = $info.typeOnly = $completionList%, % " )
341
341
(info.position, completionList)
342
342
}
0 commit comments