Correct keyword completion after try in assignment
This commit is contained in:
@@ -188,13 +188,16 @@ object KeywordCompletion {
|
|||||||
is KtBlockExpression -> {
|
is KtBlockExpression -> {
|
||||||
var prefixText = "fun foo() { "
|
var prefixText = "fun foo() { "
|
||||||
if (prevParent is KtExpression) {
|
if (prevParent is KtExpression) {
|
||||||
val tryExpression = prevParent.prevSiblingOfSameType() as? KtTryExpression
|
// check that we are right after a try-expression without finally-block
|
||||||
if (tryExpression != null && tryExpression.finallyBlock == null) {
|
val prevLeaf = prevParent.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment && it !is PsiErrorElement }
|
||||||
prefixText += when {
|
if (prevLeaf?.node?.elementType == KtTokens.RBRACE) {
|
||||||
tryExpression.catchClauses.isEmpty() -> "try {}\n"
|
val blockParent = (prevLeaf?.parent as? KtBlockExpression)?.parent
|
||||||
else -> "try {} catch (e: E) {}\n"
|
when (blockParent) {
|
||||||
|
is KtTryExpression -> prefixText += "try {}\n"
|
||||||
|
is KtCatchClause -> prefixText += "try {} catch (e: E) {}\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildFilterWithContext(prefixText, prevParent, position)
|
return buildFilterWithContext(prefixText, prevParent, position)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fun foo() {
|
||||||
|
val v = try {
|
||||||
|
bar()
|
||||||
|
}
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: catch
|
||||||
|
// EXIST: finally
|
||||||
|
// EXIST: false
|
||||||
|
// EXIST: null
|
||||||
|
// EXIST: true
|
||||||
|
// NOTHING_ELSE
|
||||||
+6
@@ -85,6 +85,12 @@ public class KeywordCompletionTestGenerated extends AbstractKeywordCompletionTes
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AfterTryInAssignment.kt")
|
||||||
|
public void testAfterTryInAssignment() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/keywords/AfterTryInAssignment.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInKeywords() throws Exception {
|
public void testAllFilesPresentInKeywords() throws Exception {
|
||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/keywords"), Pattern.compile("^(.+)\\.kt$"), false);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/keywords"), Pattern.compile("^(.+)\\.kt$"), false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user