Smart completion to ignore context after the caret

This commit is contained in:
Valentin Kipyatkov
2013-12-19 15:58:38 +04:00
parent dd6940be41
commit d28705a5ec
6 changed files with 61 additions and 10 deletions
+7
View File
@@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="valentin">
<words>
<w>pparent</w>
</words>
</dictionary>
</component>
@@ -101,17 +101,20 @@ public class JetCompletionContributor extends CompletionContributor {
public void beforeCompletion(@NotNull CompletionInitializationContext context) {
if (context.getFile() instanceof JetFile) {
int offset = context.getStartOffset();
PsiElement position = context.getFile().findElementAt(Math.max(0, offset - 1));
if (JetPackagesContributor.ACTIVATION_PATTERN.accepts(position)) {
context.setDummyIdentifier(JetPackagesContributor.DUMMY_IDENTIFIER);
PsiElement tokenBefore = context.getFile().findElementAt(Math.max(0, offset - 1));
if (context.getCompletionType() == CompletionType.SMART) {
context.setDummyIdentifier(CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED + "$"); // add '$' to ignore context after the caret
}
else if (JetExtensionReceiverTypeContributor.ACTIVATION_PATTERN.accepts(position)) {
context.setDummyIdentifier(JetExtensionReceiverTypeContributor.DUMMY_IDENTIFIER);
}
else{
context.setDummyIdentifier(CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED);
else {
if (JetPackagesContributor.ACTIVATION_PATTERN.accepts(tokenBefore)) {
context.setDummyIdentifier(JetPackagesContributor.DUMMY_IDENTIFIER);
}
else if (JetExtensionReceiverTypeContributor.ACTIVATION_PATTERN.accepts(tokenBefore)) {
context.setDummyIdentifier(JetExtensionReceiverTypeContributor.DUMMY_IDENTIFIER);
}
else{
context.setDummyIdentifier(CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED);
}
}
if (!context.getEditor().getSelectionModel().hasSelection()) {
@@ -0,0 +1,8 @@
fun foo(s: String){ }
fun bar(p1: String, p2: Int) {
foo(<caret>1 + 2)
}
// EXIST: p1
// ABSENT: p2
@@ -0,0 +1,10 @@
val v1: Int = 10
val v2: String = ""
fun foo(i: Int){}
var call: A = foo(<caret>3 + 2)
set(value) { }
// EXIST: v1
// ABSENT: v2
@@ -0,0 +1,8 @@
fun foo(s: String){ }
fun bar(p1: String, p2: Int) {
foo(<caret>x + 2)
}
// EXIST: p1
// ABSENT: p2
@@ -56,6 +56,21 @@ public class JetSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest("idea/testData/completion/smart/AutoNotNullTypeWithQualifier.kt");
}
@TestMetadata("BeforeArgumentWithBinaryOperation.kt")
public void testBeforeArgumentWithBinaryOperation() throws Exception {
doTest("idea/testData/completion/smart/BeforeArgumentWithBinaryOperation.kt");
}
@TestMetadata("BeforeArgumentWithBinaryOperation2.kt")
public void testBeforeArgumentWithBinaryOperation2() throws Exception {
doTest("idea/testData/completion/smart/BeforeArgumentWithBinaryOperation2.kt");
}
@TestMetadata("BeforeArgumentWithBinaryOperation3.kt")
public void testBeforeArgumentWithBinaryOperation3() throws Exception {
doTest("idea/testData/completion/smart/BeforeArgumentWithBinaryOperation3.kt");
}
@TestMetadata("ChainedCall.kt")
public void testChainedCall() throws Exception {
doTest("idea/testData/completion/smart/ChainedCall.kt");