Fixed one more case of no-auto-insertion after "as"
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.plugin.completion;
|
package org.jetbrains.jet.plugin.completion;
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.*;
|
import com.intellij.codeInsight.completion.*;
|
||||||
|
import com.intellij.openapi.editor.Document;
|
||||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||||
import com.intellij.patterns.PlatformPatterns;
|
import com.intellij.patterns.PlatformPatterns;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -122,7 +123,9 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
// this code will make replacement offset "modified" and prevents altering it by the code in CompletionProgressIndicator
|
// this code will make replacement offset "modified" and prevents altering it by the code in CompletionProgressIndicator
|
||||||
context.setReplacementOffset(context.getReplacementOffset());
|
context.setReplacementOffset(context.getReplacementOffset());
|
||||||
|
|
||||||
if (context.getCompletionType() == CompletionType.SMART) {
|
if (context.getCompletionType() == CompletionType.SMART
|
||||||
|
&& !isAtEndOfLine(offset, context.getEditor().getDocument()) /* do not use parent expression if we are at the end of line - it's probably parsed incorrectly */) {
|
||||||
|
|
||||||
PsiElement tokenAt = context.getFile().findElementAt(Math.max(0, offset));
|
PsiElement tokenAt = context.getFile().findElementAt(Math.max(0, offset));
|
||||||
if (tokenAt != null) {
|
if (tokenAt != null) {
|
||||||
PsiElement parent = tokenAt.getParent();
|
PsiElement parent = tokenAt.getParent();
|
||||||
@@ -136,11 +139,6 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int expressionEnd = expression.getTextRange().getEndOffset();
|
int expressionEnd = expression.getTextRange().getEndOffset();
|
||||||
String text = context.getFile().getText();
|
|
||||||
while (expressionEnd > 0 && Character.isWhitespace(text.charAt(expressionEnd - 1))) {
|
|
||||||
expressionEnd--;
|
|
||||||
}
|
|
||||||
|
|
||||||
int suggestedReplacementOffset;
|
int suggestedReplacementOffset;
|
||||||
if (expression instanceof JetCallExpression) {
|
if (expression instanceof JetCallExpression) {
|
||||||
JetExpression calleeExpression = ((JetCallExpression) expression).getCalleeExpression();
|
JetExpression calleeExpression = ((JetCallExpression) expression).getCalleeExpression();
|
||||||
@@ -159,4 +157,16 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAtEndOfLine(int offset, Document document) {
|
||||||
|
int i = offset;
|
||||||
|
CharSequence chars = document.getCharsSequence();
|
||||||
|
while (i < chars.length()) {
|
||||||
|
char c = chars.charAt(i);
|
||||||
|
if (c == '\n' || c == 'r') return true;
|
||||||
|
if (!Character.isWhitespace(c)) return false;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun bar(o: Any): String {
|
||||||
|
val v: String = o as <caret>
|
||||||
|
return ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun bar(o: Any): String {
|
||||||
|
val v: String = o as String<caret>
|
||||||
|
return ""
|
||||||
|
}
|
||||||
+5
@@ -86,6 +86,11 @@ public class SmartCompletionHandlerTestGenerated extends AbstractSmartCompletion
|
|||||||
doTest("idea/testData/completion/handlers/smart/AutoCompleteAfterAs2.kt");
|
doTest("idea/testData/completion/handlers/smart/AutoCompleteAfterAs2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("AutoCompleteAfterAs3.kt")
|
||||||
|
public void testAutoCompleteAfterAs3() throws Exception {
|
||||||
|
doTest("idea/testData/completion/handlers/smart/AutoCompleteAfterAs3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ClassObjectMethod1.kt")
|
@TestMetadata("ClassObjectMethod1.kt")
|
||||||
public void testClassObjectMethod1() throws Exception {
|
public void testClassObjectMethod1() throws Exception {
|
||||||
doTest("idea/testData/completion/handlers/smart/ClassObjectMethod1.kt");
|
doTest("idea/testData/completion/handlers/smart/ClassObjectMethod1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user