From a8b329df032905a1dfce6bb90c950ff5b111b4ef Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 12 Jun 2025 13:46:43 +0200 Subject: [PATCH] Waiting for named fields One would like to write ``` case tp @ ClassInfo(cls = cls) => ``` [Cherry-picked 841a676dca5494c62589c65e0a15feebb81363ee] --- .../pc/completions/CompletionProvider.scala | 7 ++++--- .../tools/pc/tests/CompilerCachingSuite.scala | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala index f1645f76cf97..3d315d5cc26e 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala @@ -176,9 +176,10 @@ class CompletionProvider( val text = params.text().nn val offset = params.offset().nn val query = Completion.naiveCompletionPrefix(text, offset) - - if offset > 0 && text.charAt(offset - 1).isUnicodeIdentifierPart - && !CompletionProvider.allKeywords.contains(query) then false -> text + def isValidLastChar = + val lastChar = text.charAt(offset - 1) + lastChar.isUnicodeIdentifierPart || lastChar == '.' + if offset > 0 && isValidLastChar && !CompletionProvider.allKeywords.contains(query) then false -> text else val isStartMultilineComment = diff --git a/presentation-compiler/test/dotty/tools/pc/tests/CompilerCachingSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/CompilerCachingSuite.scala index 1327c8dab91e..9a6f2af24efb 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/CompilerCachingSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/CompilerCachingSuite.scala @@ -83,6 +83,22 @@ class CompilerCachingSuite extends BasePCSuite: assert(contextPostCursor == contextPostSecond) checkCompilationCount(4) + @Test + def `dot-compilation-does-not-corrupt-cache`: Unit = + val contextPreCompilation = getContext() + + val fakeParams = CompilerOffsetParams(Paths.get("Test.scala").toUri(), "def hello = 1.", 14, EmptyCancelToken) + presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit) + val contextPostFirst = getContext() + assert(contextPreCompilation != contextPostFirst) + checkCompilationCount(4) + + presentationCompiler.complete(fakeParams).get(timeout.length, timeout.unit) + val contextPostSecond = getContext() + assert(contextPreCompilation != contextPostFirst) + assert(contextPostSecond == contextPostFirst) + checkCompilationCount(4) + @Test def `compilation-for-same-snippet-is-cached`: Unit = val contextPreCompilation = getContext()