Fix the end of the replaced identifier for completion with tab char
Stop removing (, ), {, }, + and so on.
This commit is contained in:
@@ -21,9 +21,11 @@ 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;
|
||||||
import com.intellij.psi.PsiReference;
|
import com.intellij.psi.PsiReference;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.util.ProcessingContext;
|
import com.intellij.util.ProcessingContext;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
||||||
|
|
||||||
@@ -93,8 +95,10 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeCompletion(@NotNull CompletionInitializationContext context) {
|
public void beforeCompletion(@NotNull CompletionInitializationContext context) {
|
||||||
if (context.getCompletionType() == CompletionType.BASIC && context.getFile() instanceof JetFile) {
|
if (context.getFile() instanceof JetFile) {
|
||||||
PsiElement position = context.getFile().findElementAt(Math.max(0, context.getStartOffset() - 1));
|
int offset = context.getStartOffset();
|
||||||
|
|
||||||
|
PsiElement position = context.getFile().findElementAt(Math.max(0, offset - 1));
|
||||||
|
|
||||||
if (JetPackagesContributor.ACTIVATION_PATTERN.accepts(position)) {
|
if (JetPackagesContributor.ACTIVATION_PATTERN.accepts(position)) {
|
||||||
context.setDummyIdentifier(JetPackagesContributor.DUMMY_IDENTIFIER);
|
context.setDummyIdentifier(JetPackagesContributor.DUMMY_IDENTIFIER);
|
||||||
@@ -102,6 +106,21 @@ public class JetCompletionContributor extends CompletionContributor {
|
|||||||
else if (JetExtensionReceiverTypeContributor.ACTIVATION_PATTERN.accepts(position)) {
|
else if (JetExtensionReceiverTypeContributor.ACTIVATION_PATTERN.accepts(position)) {
|
||||||
context.setDummyIdentifier(JetExtensionReceiverTypeContributor.DUMMY_IDENTIFIER);
|
context.setDummyIdentifier(JetExtensionReceiverTypeContributor.DUMMY_IDENTIFIER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!context.getEditor().getSelectionModel().hasSelection()) {
|
||||||
|
PsiReference reference = context.getFile().findReferenceAt(offset);
|
||||||
|
if (reference != null) {
|
||||||
|
PsiElement atElement = context.getFile().findElementAt(offset);
|
||||||
|
assert atElement != null : String.format("Element is not expected to be null: %d in file %s",
|
||||||
|
offset, context.getFile().getText());
|
||||||
|
|
||||||
|
IElementType parentElementType = atElement.getParent().getNode().getElementType();
|
||||||
|
|
||||||
|
if (!(reference instanceof JetSimpleNameReference) || parentElementType == JetNodeTypes.OPERATION_REFERENCE) {
|
||||||
|
context.setReplacementOffset(offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val vvvvv = 112
|
||||||
|
val a = vv<caret>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val vvvvv = 112
|
||||||
|
val a = vvvvv<caret>
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vv<caret>{}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vvvvv<caret>{}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vv<caret>[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vvvvv<caret>[]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vv<caret>+12
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vvvvv<caret>+12
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vv<caret>()
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vvvvv<caret>()
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vvv<caret>me
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
vvvvv<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun foo(f: (Int) -> Unit) = 12
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
foo {vv<caret>}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun foo(f: (Int) -> Unit) = 12
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
foo {vvvvv<caret>}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
val foo = array(1, 2, 3)
|
||||||
|
foo[vv<caret>]
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
val foo = array(1, 2, 3)
|
||||||
|
foo[vvvvv<caret>]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
foo(<caret>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
foo(vvvvv<caret>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
foo(vv<caret>)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val vvvvv = 12
|
||||||
|
foo(vvvvv<caret>)
|
||||||
|
}
|
||||||
@@ -70,6 +70,26 @@ public class CompletionHandlerTest() : JetLightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
fun testForceParenthesisForTabChar() = doTest(CompletionType.BASIC, 0, "some", null, '\t')
|
fun testForceParenthesisForTabChar() = doTest(CompletionType.BASIC, 0, "some", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertAtTheFileEnd() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertBeforeBraces() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertBeforeBrackets() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertBeforeOperator() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertBeforeParentheses() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertInsideBraces() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertInsideBrackets() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertInsideEmptyParentheses() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertInsideParentheses() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
|
fun testTabInsertInSimpleName() = doTest(CompletionType.BASIC, 0, "vvvvv", null, '\t')
|
||||||
|
|
||||||
var fixture by Delegates.notNull<JavaCodeInsightTestFixture>()
|
var fixture by Delegates.notNull<JavaCodeInsightTestFixture>()
|
||||||
|
|
||||||
protected override fun setUp() {
|
protected override fun setUp() {
|
||||||
|
|||||||
Reference in New Issue
Block a user