Smart completion to ignore context after the caret
This commit is contained in:
Generated
+7
@@ -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) {
|
public void beforeCompletion(@NotNull CompletionInitializationContext context) {
|
||||||
if (context.getFile() instanceof JetFile) {
|
if (context.getFile() instanceof JetFile) {
|
||||||
int offset = context.getStartOffset();
|
int offset = context.getStartOffset();
|
||||||
|
PsiElement tokenBefore = context.getFile().findElementAt(Math.max(0, offset - 1));
|
||||||
PsiElement position = 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
|
||||||
if (JetPackagesContributor.ACTIVATION_PATTERN.accepts(position)) {
|
|
||||||
context.setDummyIdentifier(JetPackagesContributor.DUMMY_IDENTIFIER);
|
|
||||||
}
|
}
|
||||||
else if (JetExtensionReceiverTypeContributor.ACTIVATION_PATTERN.accepts(position)) {
|
else {
|
||||||
context.setDummyIdentifier(JetExtensionReceiverTypeContributor.DUMMY_IDENTIFIER);
|
if (JetPackagesContributor.ACTIVATION_PATTERN.accepts(tokenBefore)) {
|
||||||
}
|
context.setDummyIdentifier(JetPackagesContributor.DUMMY_IDENTIFIER);
|
||||||
else{
|
}
|
||||||
context.setDummyIdentifier(CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED);
|
else if (JetExtensionReceiverTypeContributor.ACTIVATION_PATTERN.accepts(tokenBefore)) {
|
||||||
|
context.setDummyIdentifier(JetExtensionReceiverTypeContributor.DUMMY_IDENTIFIER);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
context.setDummyIdentifier(CompletionUtilCore.DUMMY_IDENTIFIER_TRIMMED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.getEditor().getSelectionModel().hasSelection()) {
|
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");
|
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")
|
@TestMetadata("ChainedCall.kt")
|
||||||
public void testChainedCall() throws Exception {
|
public void testChainedCall() throws Exception {
|
||||||
doTest("idea/testData/completion/smart/ChainedCall.kt");
|
doTest("idea/testData/completion/smart/ChainedCall.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user