Skip to content

Commit 67c5fac

Browse files
committed
chore: Improve completions when a lot of exports are present
It seems .sourceSymbol would end up traversing a lot of trees in that case, which is highly inefficient I also added a try for cases such as scalameta/metals#7573 [Cherry-picked b148260]
1 parent dbef9dc commit 67c5fac

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ object Completion:
321321
* 8. symbol is not a constructor proxy module when in type completion mode
322322
* 9. have same term/type kind as name prefix given so far
323323
*/
324-
def isValidCompletionSymbol(sym: Symbol, completionMode: Mode, isNew: Boolean)(using Context): Boolean =
325-
324+
def isValidCompletionSymbol(sym: Symbol, completionMode: Mode, isNew: Boolean)(using Context): Boolean = try
326325
lazy val isEnum = sym.is(Enum) ||
327326
(sym.companionClass.exists && sym.companionClass.is(Enum))
328327

329328
sym.exists &&
330329
!sym.isAbsent(canForce = false) &&
331330
!sym.isPrimaryConstructor &&
332-
sym.sourceSymbol.exists &&
331+
// running sourceSymbol on ExportedTerm will force a lot of computation from collectSubTrees
332+
(sym.is(ExportedTerm) || sym.sourceSymbol.exists) &&
333333
(!sym.is(Package) || sym.is(ModuleClass)) &&
334334
!sym.isAllOf(Mutable | Accessor) &&
335335
!sym.isPackageObject &&
@@ -340,6 +340,9 @@ object Completion:
340340
(completionMode.is(Mode.Term) && (sym.isTerm || sym.is(ModuleClass))
341341
|| (completionMode.is(Mode.Type) && (sym.isType || sym.isStableMember)))
342342
)
343+
catch
344+
case NonFatal(ex) =>
345+
false
343346
end isValidCompletionSymbol
344347

345348
given ScopeOrdering(using Context): Ordering[Seq[SingleDenotation]] with

0 commit comments

Comments
 (0)