Fixed KT-5142 Code completion of parameter type inserts FQ-name
#KT-5142 Fixed
This commit is contained in:
@@ -43,23 +43,22 @@ public class JetClassInsertHandler implements InsertHandler<LookupElement> {
|
|||||||
int startOffset = context.getStartOffset();
|
int startOffset = context.getStartOffset();
|
||||||
Document document = context.getDocument();
|
Document document = context.getDocument();
|
||||||
if (!isAfterDot(document, startOffset)) {
|
if (!isAfterDot(document, startOffset)) {
|
||||||
String text = DescriptorUtils.getFqName(descriptor).asString();
|
String fqName = DescriptorUtils.getFqName(descriptor).asString();
|
||||||
// insert dot after because otherwise parser can sometimes produce no suitable reference here
|
// insert dot after because otherwise parser can sometimes produce no suitable reference here
|
||||||
document.replaceString(startOffset, context.getTailOffset(), text + ".");
|
String tempSuffix = ".xxx"; // we add "xxx" after dot because of some bugs in resolve (see KT-5145)
|
||||||
|
document.replaceString(startOffset, context.getTailOffset(), fqName + tempSuffix);
|
||||||
|
int classNameEnd = startOffset + fqName.length();
|
||||||
|
|
||||||
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(context.getProject());
|
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(context.getProject());
|
||||||
psiDocumentManager.commitAllDocuments();
|
psiDocumentManager.commitAllDocuments();
|
||||||
RangeMarker rangeMarker = document.createRangeMarker(startOffset, startOffset + text.length());
|
RangeMarker rangeMarker = document.createRangeMarker(classNameEnd, classNameEnd + tempSuffix.length());
|
||||||
|
|
||||||
ShortenReferences.instance$.process((JetFile) context.getFile(), startOffset, startOffset + text.length());
|
ShortenReferences.instance$.process((JetFile) context.getFile(), startOffset, classNameEnd);
|
||||||
psiDocumentManager.commitAllDocuments();
|
psiDocumentManager.commitAllDocuments();
|
||||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
|
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
|
||||||
|
|
||||||
if (rangeMarker.isValid()) {
|
if (rangeMarker.isValid()) {
|
||||||
int endOffset = rangeMarker.getEndOffset();
|
document.deleteString(rangeMarker.getStartOffset(), rangeMarker.getEndOffset());
|
||||||
if (endOffset < document.getTextLength() && document.getCharsSequence().charAt(endOffset) == '.') {
|
|
||||||
document.deleteString(endOffset, endOffset + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun foo(p: StringB<caret>) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun foo(p: StringBuilder<caret>) {
|
||||||
|
}
|
||||||
@@ -137,4 +137,6 @@ public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){
|
|||||||
fun testEnumMember() = doTest(1, "A", null, '\n')
|
fun testEnumMember() = doTest(1, "A", null, '\n')
|
||||||
fun testEnumMember1() = doTest(1, "A", null, '\n')
|
fun testEnumMember1() = doTest(1, "A", null, '\n')
|
||||||
fun testClassFromClassObject() = doTest(1, "Some", null, '\n')
|
fun testClassFromClassObject() = doTest(1, "Some", null, '\n')
|
||||||
|
|
||||||
|
fun testParameterType() = doTest(1, "StringBuilder", " (java.lang)", '\n')
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user