KT-5012 Autocompletion is completing to FQN and not the value
#KT-5012 Fixed #KT-5006 Fixed
This commit is contained in:
@@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.completion.handlers;
|
|||||||
import com.intellij.codeInsight.completion.InsertHandler;
|
import com.intellij.codeInsight.completion.InsertHandler;
|
||||||
import com.intellij.codeInsight.completion.InsertionContext;
|
import com.intellij.codeInsight.completion.InsertionContext;
|
||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
import com.intellij.codeInsight.lookup.LookupElement;
|
||||||
|
import com.intellij.openapi.editor.Document;
|
||||||
import com.intellij.psi.PsiDocumentManager;
|
import com.intellij.psi.PsiDocumentManager;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
@@ -38,14 +39,29 @@ public class JetClassInsertHandler implements InsertHandler<LookupElement> {
|
|||||||
JetLookupObject lookupObject = (JetLookupObject)item.getObject();
|
JetLookupObject lookupObject = (JetLookupObject)item.getObject();
|
||||||
DeclarationDescriptor descriptor = lookupObject.getDescriptor();
|
DeclarationDescriptor descriptor = lookupObject.getDescriptor();
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
String text = DescriptorUtils.getFqName(descriptor).asString();
|
|
||||||
int startOffset = context.getStartOffset();
|
int startOffset = context.getStartOffset();
|
||||||
context.getDocument().replaceString(startOffset, context.getTailOffset(), text);
|
Document document = context.getDocument();
|
||||||
|
if (!isAfterDot(document, startOffset)) {
|
||||||
|
String text = DescriptorUtils.getFqName(descriptor).asString();
|
||||||
|
document.replaceString(startOffset, context.getTailOffset(), text);
|
||||||
|
|
||||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||||
ShortenReferences.instance$.process((JetFile) context.getFile(), startOffset, startOffset + text.length());
|
ShortenReferences.instance$.process((JetFile) context.getFile(), startOffset, startOffset + text.length());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAfterDot(Document document, int offset) {
|
||||||
|
CharSequence chars = document.getCharsSequence();
|
||||||
|
while(offset > 0) {
|
||||||
|
offset--;
|
||||||
|
char c = chars.charAt(offset);
|
||||||
|
if (!Character.isWhitespace(c)) {
|
||||||
|
return c == '.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
enum class E {
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val e = E.<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
enum class E {
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val e = E.A<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
enum class E {
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val e = E. <caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
enum class E {
|
||||||
|
A
|
||||||
|
B
|
||||||
|
C
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val e = E. A<caret>
|
||||||
|
}
|
||||||
@@ -125,4 +125,7 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testObject() = doTest()
|
fun testObject() = doTest()
|
||||||
|
|
||||||
|
fun testEnumMember() = doTest(1, "A", null, '\n')
|
||||||
|
fun testEnumMember1() = doTest(1, "A", null, '\n')
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user