Fixed KT-5101 Partly qualified name is inserted by code completion
#KT-5101 Fixed
This commit is contained in:
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.InsertHandler;
|
||||
import com.intellij.codeInsight.completion.InsertionContext;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
@@ -43,10 +44,23 @@ public class JetClassInsertHandler implements InsertHandler<LookupElement> {
|
||||
Document document = context.getDocument();
|
||||
if (!isAfterDot(document, startOffset)) {
|
||||
String text = DescriptorUtils.getFqName(descriptor).asString();
|
||||
document.replaceString(startOffset, context.getTailOffset(), text);
|
||||
// insert dot after because otherwise parser can sometimes produce no suitable reference here
|
||||
document.replaceString(startOffset, context.getTailOffset(), text + ".");
|
||||
|
||||
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(context.getProject());
|
||||
psiDocumentManager.commitAllDocuments();
|
||||
RangeMarker rangeMarker = document.createRangeMarker(startOffset, startOffset + text.length());
|
||||
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||
ShortenReferences.instance$.process((JetFile) context.getFile(), startOffset, startOffset + text.length());
|
||||
psiDocumentManager.commitAllDocuments();
|
||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
|
||||
|
||||
if (rangeMarker.isValid()) {
|
||||
int endOffset = rangeMarker.getEndOffset();
|
||||
if (endOffset < document.getTextLength() && document.getCharsSequence().charAt(endOffset) == '.') {
|
||||
document.deleteString(endOffset, endOffset + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
fun Str<caret>foo() {
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fun StringBuilder<caret>foo() {
|
||||
}
|
||||
@@ -32,6 +32,8 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){
|
||||
|
||||
fun testClassCompletionInLambda() = doTest(1, "String", " (kotlin)", '\n')
|
||||
|
||||
fun testClassCompletionBeforeName() = doTest(1, "StringBuilder", " (java.lang)", '\n')
|
||||
|
||||
fun testDoNotInsertImportForAlreadyImported() = doTest()
|
||||
|
||||
fun testDoNotInsertDefaultJsImports() = doTest()
|
||||
|
||||
Reference in New Issue
Block a user