Skip to content

Commit 99543c5

Browse files
authored
improvement: Improve efficiency of completions (#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
1 parent b35fa8a commit 99543c5

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
@@ -335,7 +335,7 @@ object Completion:
335335
(sym.companionClass.exists && sym.companionClass.is(Enum))
336336

337337
sym.exists &&
338-
!sym.isAbsent() &&
338+
!sym.isAbsent(canForce = false) &&
339339
!sym.isPrimaryConstructor &&
340340
sym.sourceSymbol.exists &&
341341
(!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
@@ -588,7 +588,7 @@ class Completions(
588588
else false,
589589
)
590590
Some(search.search(query, buildTargetIdentifier, visitor).nn)
591-
else if completionMode.is(Mode.Member) then
591+
else if completionMode.is(Mode.Member) && query.nonEmpty then
592592
val visitor = new CompilerSearchVisitor(sym =>
593593
def isExtensionMethod = sym.is(ExtensionMethod) &&
594594
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)