Fix AssertionError on completing after template in string literal
#KT-16402 Fixed
This commit is contained in:
committed by
Simon Ogorodnik
parent
0560ba7929
commit
27e7f13335
+10
-3
@@ -333,9 +333,7 @@ class KotlinCompletionContributor : CompletionContributor() {
|
|||||||
val psiDocumentManager = PsiDocumentManager.getInstance(context.project)
|
val psiDocumentManager = PsiDocumentManager.getInstance(context.project)
|
||||||
psiDocumentManager.commitAllDocuments()
|
psiDocumentManager.commitAllDocuments()
|
||||||
|
|
||||||
assert(startOffset > 1 && document.charsSequence[startOffset - 1] == '.')
|
val token = getToken(context.file, document.charsSequence, startOffset)
|
||||||
val token = context.file.findElementAt(startOffset - 2)!!
|
|
||||||
assert(token.node.elementType == KtTokens.IDENTIFIER || token.node.elementType == KtTokens.THIS_KEYWORD)
|
|
||||||
val nameRef = token.parent as KtNameReferenceExpression
|
val nameRef = token.parent as KtNameReferenceExpression
|
||||||
|
|
||||||
document.insertString(nameRef.startOffset, "{")
|
document.insertString(nameRef.startOffset, "{")
|
||||||
@@ -346,6 +344,15 @@ class KotlinCompletionContributor : CompletionContributor() {
|
|||||||
|
|
||||||
super.handleInsert(context)
|
super.handleInsert(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getToken(file: PsiFile, charsSequence: CharSequence, startOffset: Int): PsiElement {
|
||||||
|
assert(startOffset > 1 && charsSequence[startOffset - 1] == '.')
|
||||||
|
val token = file.findElementAt(startOffset - 2)!!
|
||||||
|
return if (token.node.elementType == KtTokens.IDENTIFIER || token.node.elementType == KtTokens.THIS_KEYWORD)
|
||||||
|
token
|
||||||
|
else
|
||||||
|
getToken(file, charsSequence, token.startOffset + 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
class Foo(val bar: Bar)
|
||||||
|
class Bar(val baz: String)
|
||||||
|
|
||||||
|
fun foo(foo: Foo) {
|
||||||
|
val s = "$foo.bar.<caret>"
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: baz
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
class Foo(val bar: Bar)
|
||||||
|
class Bar(val baz: String)
|
||||||
|
|
||||||
|
fun foo(foo: Foo) {
|
||||||
|
val s = "$foo.bar.<caret>"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: baz
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
class Foo(val bar: Bar)
|
||||||
|
class Bar(val baz: String)
|
||||||
|
|
||||||
|
fun foo(foo: Foo) {
|
||||||
|
val s = "${foo.bar.baz}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ELEMENT: baz
|
||||||
+6
@@ -1825,6 +1825,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("StringTemplateDot2.kt")
|
||||||
|
public void testStringTemplateDot2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/inStringLiterals/StringTemplateDot2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("StringTemplateDotSomething.kt")
|
@TestMetadata("StringTemplateDotSomething.kt")
|
||||||
public void testStringTemplateDotSomething() throws Exception {
|
public void testStringTemplateDotSomething() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/inStringLiterals/StringTemplateDotSomething.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/inStringLiterals/StringTemplateDotSomething.kt");
|
||||||
|
|||||||
+6
@@ -1825,6 +1825,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("StringTemplateDot2.kt")
|
||||||
|
public void testStringTemplateDot2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/inStringLiterals/StringTemplateDot2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("StringTemplateDotSomething.kt")
|
@TestMetadata("StringTemplateDotSomething.kt")
|
||||||
public void testStringTemplateDotSomething() throws Exception {
|
public void testStringTemplateDotSomething() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/inStringLiterals/StringTemplateDotSomething.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/common/inStringLiterals/StringTemplateDotSomething.kt");
|
||||||
|
|||||||
+6
@@ -835,6 +835,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AfterDot4.kt")
|
||||||
|
public void testAfterDot4() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/stringTemplate/AfterDot4.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("AfterThisDot.kt")
|
@TestMetadata("AfterThisDot.kt")
|
||||||
public void testAfterThisDot() throws Exception {
|
public void testAfterThisDot() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/stringTemplate/AfterThisDot.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user