Skip to content

Commit 6d817fb

Browse files
committed
improvement: Improve efficiency of completions (scala#23355)
There are two improvements here: - isAbsent(force = false) which is already used in the codebase when we care about performance - we don't search for extension or implicit methods on empty query, as we would have inverseSemanticdb invoked on every possible extension method and it's quite inefficient [Cherry-picked 99543c5]
1 parent d77facb commit 6d817fb

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ object Completion:
332332
(sym.companionClass.exists && sym.companionClass.is(Enum))
333333

334334
sym.exists &&
335-
!sym.isAbsent() &&
335+
!sym.isAbsent(canForce = false) &&
336336
!sym.isPrimaryConstructor &&
337337
sym.sourceSymbol.exists &&
338338
(!sym.is(Package) || sym.is(ModuleClass)) &&

presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class Completions(
590590
else false,
591591
)
592592
Some(search.search(query, buildTargetIdentifier, visitor).nn)
593-
else if completionMode.is(Mode.Member) then
593+
else if completionMode.is(Mode.Member) && query.nonEmpty then
594594
val visitor = new CompilerSearchVisitor(sym =>
595595
def isExtensionMethod = sym.is(ExtensionMethod) &&
596596
qualType.widenDealias <:< sym.extensionParam.info.widenDealias

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionExtensionSuite.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
228228
|""".stripMargin
229229
)
230230

231+
/**
232+
* For optimization, we don't show any completions here as it would bring
233+
* every extension method into the completion list.
234+
*/
231235
@Test def `simple-empty` =
232236
check(
233237
"""|package example
@@ -238,11 +242,13 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
238242
|
239243
|def main = 100.@@
240244
|""".stripMargin,
241-
"""|incr: Int (extension)
242-
|""".stripMargin,
245+
"",
243246
filter = _.contains("(extension)")
244247
)
245248

249+
/**
250+
* Some as above, but for implicit completions.
251+
*/
246252
@Test def `simple-empty-old` =
247253
check(
248254
"""|package example
@@ -253,8 +259,7 @@ class CompletionExtensionSuite extends BaseCompletionSuite:
253259
|
254260
|def main = 100.@@
255261
|""".stripMargin,
256-
"""|testOps(b: Int): String (implicit)
257-
|""".stripMargin,
262+
"",
258263
filter = _.contains("(implicit)")
259264
)
260265

0 commit comments

Comments
 (0)