Do not insert redundant space
This commit is contained in:
+12
-5
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.builtins.extractParameterNameFromFunctionTypeArgumen
|
||||
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.isCharAt
|
||||
import org.jetbrains.kotlin.idea.core.ExpectedInfos
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.core.fuzzyType
|
||||
@@ -62,8 +63,17 @@ object LambdaSignatureTemplates {
|
||||
context.project.executeWriteCommand(commandName, groupId = commandGroupId) {
|
||||
try {
|
||||
if (rangeMarker.isValid) {
|
||||
context.document.deleteString(rangeMarker.startOffset, rangeMarker.endOffset)
|
||||
context.editor.caretModel.moveToOffset(rangeMarker.startOffset)
|
||||
val startOffset = rangeMarker.startOffset
|
||||
context.document.deleteString(startOffset, rangeMarker.endOffset)
|
||||
|
||||
if (signatureOnly) {
|
||||
val spaceAhead = context.document.charsSequence.isCharAt(startOffset, ' ')
|
||||
if (!spaceAhead) {
|
||||
context.document.insertString(startOffset, " ")
|
||||
}
|
||||
}
|
||||
|
||||
context.editor.caretModel.moveToOffset(startOffset)
|
||||
val template = buildTemplate(lambdaType, signatureOnly, explicitParameterTypes, context.project)
|
||||
TemplateManager.getInstance(context.project).startTemplate(context.editor, template)
|
||||
}
|
||||
@@ -181,9 +191,6 @@ object LambdaSignatureTemplates {
|
||||
if (!signatureOnly) {
|
||||
template.addTextSegment(" }")
|
||||
}
|
||||
else {
|
||||
template.addTextSegment(" ") //TODO: no additional space if space ahead
|
||||
}
|
||||
|
||||
return template
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun foo(p: (x: Char, String) -> Unit){}
|
||||
|
||||
fun bar() {
|
||||
foo { <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: "x, s ->"
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun foo(p: (x: Char, String) -> Unit){}
|
||||
|
||||
fun bar() {
|
||||
foo { x, s -> <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: "x, s ->"
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(p: (x: Char, String) -> Unit){}
|
||||
|
||||
fun bar() {
|
||||
foo { <caret>}
|
||||
}
|
||||
|
||||
// ELEMENT: "x, s ->"
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(p: (x: Char, String) -> Unit){}
|
||||
|
||||
fun bar() {
|
||||
foo { x, s -> <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: "x, s ->"
|
||||
+21
@@ -926,4 +926,25 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/idea-completion/testData/handlers/smart/lambdaSignature")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class LambdaSignature extends AbstractSmartCompletionHandlerTest {
|
||||
public void testAllFilesPresentInLambdaSignature() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/handlers/smart/lambdaSignature"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("NoAdditionalSpace.kt")
|
||||
public void testNoAdditionalSpace() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/lambdaSignature/NoAdditionalSpace.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/smart/lambdaSignature/Simple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user