From 3ffc1737dc73eb69e996821956dc74cc6242b053 Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Fri, 30 Jan 2026 14:11:41 +0100 Subject: [PATCH] [command-completion] IDEA-385364 Generation doesn't work on a new line with tabs GitOrigin-RevId: 36a9526f790baae02f68afdc7e7bbfe5bde75217 --- ... => JavaCommandsCompletionGenerateTest.kt} | 29 ++++++++++++++++++- .../command/CommandCompletionProvider.kt | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) rename java/java-tests/testSrc/com/intellij/java/codeInsight/completion/commands/{JavaCommandsCompletionGenerateConstructorsTest.kt => JavaCommandsCompletionGenerateTest.kt} (90%) diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/commands/JavaCommandsCompletionGenerateConstructorsTest.kt b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/commands/JavaCommandsCompletionGenerateTest.kt similarity index 90% rename from java/java-tests/testSrc/com/intellij/java/codeInsight/completion/commands/JavaCommandsCompletionGenerateConstructorsTest.kt rename to java/java-tests/testSrc/com/intellij/java/codeInsight/completion/commands/JavaCommandsCompletionGenerateTest.kt index b19eebbcc00a..fc4f9e825186 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/commands/JavaCommandsCompletionGenerateConstructorsTest.kt +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/commands/JavaCommandsCompletionGenerateTest.kt @@ -8,7 +8,7 @@ import com.intellij.openapi.util.registry.Registry import com.intellij.testFramework.NeedsIndex @NeedsIndex.SmartMode(reason = "it requires highlighting") -class JavaCommandsCompletionGenerateConstructorsTest : LightFixtureCompletionTestCase() { +class JavaCommandsCompletionGenerateTest : LightFixtureCompletionTestCase() { override fun setUp() { super.setUp() @@ -16,6 +16,33 @@ class JavaCommandsCompletionGenerateConstructorsTest : LightFixtureCompletionTes Registry.get("ide.completion.command.force.enabled").setValue(true, getTestRootDisposable()) } + fun testGenerateWithTabs() { + //don't move, there are tabs instead of spaces + val text = """ +package org.test; + +public class Test { + private Integer num; + + + ge +}""".trimIndent() + myFixture.configureByText(JavaFileType.INSTANCE, text) + val elements = myFixture.completeBasic() + selectItem(elements.first { element -> element.lookupString.contains("Generate 'No-Args Constructor'", ignoreCase = true) }) + NonBlockingReadActionImpl.waitForAsyncTaskCompletion() + myFixture.checkResult(""" +package org.test; + +public class Test { + private Integer num; + + + public Test() { + } +}""".trimIndent()) + } + fun testGenerateNoArgsConstructor() { myFixture.configureByText(JavaFileType.INSTANCE, """ class A { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionProvider.kt b/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionProvider.kt index 84d547e12522..34b2f40bab22 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionProvider.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/command/CommandCompletionProvider.kt @@ -614,6 +614,7 @@ internal fun findActualIndex(suffix: String, text: CharSequence, offset: Int): I var currentIndex = 1 while (text.getOrNull(offset - currentIndex)?.isLetter() == true || text.getOrNull(offset - currentIndex) == ' ' || + text.getOrNull(offset - currentIndex) == '\t' || text.getOrNull(offset - currentIndex) == '\'' ) { currentIndex++