Completion fix for reserved 'async' syntax
This commit is contained in:
committed by
Andrey Breslav
parent
afc1e24571
commit
318f0c89b2
+9
-2
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||
import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtTypeArgumentList
|
||||
@@ -73,10 +74,10 @@ sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() {
|
||||
val startOffset = context.startOffset
|
||||
val element = context.file.findElementAt(startOffset) ?: return
|
||||
|
||||
addArguments(context, element)
|
||||
addArguments(context, element, item)
|
||||
}
|
||||
|
||||
private fun addArguments(context : InsertionContext, offsetElement : PsiElement) {
|
||||
private fun addArguments(context: InsertionContext, offsetElement: PsiElement, item: LookupElement) {
|
||||
val completionChar = context.getCompletionChar()
|
||||
if (completionChar == '(') { //TODO: more correct behavior related to braces type
|
||||
context.setAddCompletionChar(false)
|
||||
@@ -122,6 +123,12 @@ sealed class KotlinFunctionInsertHandler : KotlinCallableInsertHandler() {
|
||||
offset += 2
|
||||
}
|
||||
|
||||
// insert additional brackets for reserved syntax: "async {}"
|
||||
if (insertLambda && (item.`object` as? DeclarationLookupObject)?.name?.identifier == "async") {
|
||||
document.insertString(offset, "()")
|
||||
offset += 2
|
||||
}
|
||||
|
||||
var openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)
|
||||
var closeBracketOffset = openingBracketOffset?.let { chars.indexOfSkippingSpace(closingBracket, it + 1) }
|
||||
var inBracketsShift = 0
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun async(a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
asy<caret>
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun async(a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
async() { <caret> }
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
fun async (p: Int, a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
asy<caret>
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
fun async (p: Int, a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
async(<caret>)
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun asyFoo(a: () -> Unit) {}
|
||||
|
||||
fun async(a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
asy<caret>Foo { }
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
// CHAR: '\t'
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
fun asyFoo(a: () -> Unit) {}
|
||||
|
||||
fun async(a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
async() { }
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
// CHAR: '\t'
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun asyFoo(p: Int, a: () -> Unit) {}
|
||||
|
||||
fun async(q: Int, a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
asy<caret>Foo(5) { }
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
// CHAR: '\t'
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
fun asyFoo(p: Int, a: () -> Unit) {}
|
||||
|
||||
fun async(q: Int, a: () -> Unit) {}
|
||||
|
||||
fun test() {
|
||||
async(<caret>5) { }
|
||||
}
|
||||
|
||||
// ELEMENT: async
|
||||
// CHAR: '\t'
|
||||
+33
@@ -378,6 +378,39 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/WithArgsNonEmptyLambdaAfter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/async")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Async extends AbstractBasicCompletionHandlerTest {
|
||||
public void testAllFilesPresentInAsync() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/handlers/basic/highOrderFunctions/async"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("AsyncSimple.kt")
|
||||
public void testAsyncSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/async/AsyncSimple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("AsyncWithoutLambda.kt")
|
||||
public void testAsyncWithoutLambda() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/async/AsyncWithoutLambda.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FromFooToAsync.kt")
|
||||
public void testFromFooToAsync() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/async/FromFooToAsync.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FromFooToAsync2.kt")
|
||||
public void testFromFooToAsync2() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/highOrderFunctions/async/FromFooToAsync2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/idea-completion/testData/handlers/basic/override")
|
||||
|
||||
Reference in New Issue
Block a user