mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
one more fix for caret position when choosing a class suggestion by dot
This commit is contained in:
+2
-1
@@ -58,10 +58,11 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
final int plEnd = context.getOffset(PARAM_LIST_END);
|
||||
if (plStart >= 0 && plEnd >= 0) {
|
||||
context.getDocument().deleteString(plStart, plEnd);
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||
}
|
||||
}
|
||||
|
||||
context.commitDocument();
|
||||
|
||||
OffsetKey insideRef = context.trackOffset(context.getTailOffset(), false);
|
||||
|
||||
final PsiElement position = SmartCompletionDecorator.getPosition(context, delegate);
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.StaticImportMethodFix;
|
||||
import com.intellij.codeInsight.guess.GuessManager;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -699,7 +700,8 @@ public class JavaCompletionUtil {
|
||||
|
||||
public static int insertClassReference(PsiClass psiClass, PsiFile file, int startOffset, int endOffset) {
|
||||
final Project project = file.getProject();
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
documentManager.commitAllDocuments();
|
||||
|
||||
final PsiManager manager = file.getManager();
|
||||
|
||||
@@ -725,7 +727,7 @@ public class JavaCompletionUtil {
|
||||
|
||||
final RangeMarker toDelete = insertTemporary(startOffset + name.length(), document, " ");
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
documentManager.commitAllDocuments();
|
||||
|
||||
int newEndOffset = endOffset;
|
||||
PsiElement element = file.findElementAt(startOffset);
|
||||
@@ -740,23 +742,28 @@ public class JavaCompletionUtil {
|
||||
? ((PsiImportStaticReferenceElement)ref).bindToTargetClass(psiClass)
|
||||
: ref.bindToElement(psiClass);
|
||||
|
||||
newElement = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(newElement);
|
||||
final RangeMarker rangeMarker = document.createRangeMarker(newElement.getTextRange());
|
||||
documentManager.doPostponedOperationsAndUnblockDocument(document);
|
||||
documentManager.commitDocument(document);
|
||||
|
||||
newElement = CodeInsightUtilBase.findElementInRange(file, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(),
|
||||
PsiJavaCodeReferenceElement.class,
|
||||
JavaLanguage.INSTANCE);
|
||||
rangeMarker.dispose();
|
||||
if (newElement != null) {
|
||||
newEndOffset = newElement.getTextRange().getEndOffset();
|
||||
if (newElement instanceof PsiJavaCodeReferenceElement && !(newElement instanceof PsiReferenceExpression)) {
|
||||
if (!(newElement instanceof PsiReferenceExpression)) {
|
||||
PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)newElement).getParameterList();
|
||||
if (parameterList != null) {
|
||||
newEndOffset = parameterList.getTextRange().getStartOffset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!staticImport &&
|
||||
newElement instanceof PsiJavaCodeReferenceElement &&
|
||||
!psiClass.getManager().areElementsEquivalent(psiClass, resolveReference((PsiReference)newElement))) {
|
||||
final String qName = psiClass.getQualifiedName();
|
||||
if (qName != null) {
|
||||
document.replaceString(newElement.getTextRange().getStartOffset(), newEndOffset, qName);
|
||||
if (!staticImport && !psiClass.getManager().areElementsEquivalent(psiClass, resolveReference((PsiReference)newElement))) {
|
||||
final String qName = psiClass.getQualifiedName();
|
||||
if (qName != null) {
|
||||
document.replaceString(newElement.getTextRange().getStartOffset(), newEndOffset, qName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Foo {
|
||||
{
|
||||
verify(runP4WithClient("integ", "main/...", "rel/..."));
|
||||
FInpSt.<caret>
|
||||
verify(runP4WithClient("resolve", "-at"));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.io.FileInputStream;
|
||||
|
||||
public class Foo {
|
||||
{
|
||||
verify(runP4WithClient("integ", "main/...", "rel/..."));
|
||||
FileInputStream.<caret>
|
||||
verify(runP4WithClient("resolve", "-at"));
|
||||
}
|
||||
}
|
||||
+12
@@ -1266,4 +1266,16 @@ public class ListUtils {
|
||||
|
||||
public void testClassNameDot() { doTest('.') }
|
||||
|
||||
public void testClassNameDotBeforeCall() {
|
||||
myFixture.addClass("package foo; public class FileInputStreamSmth {}")
|
||||
myFixture.configureByFile(getTestName(false) + ".java")
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
type '\b'
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments()
|
||||
myFixture.completeBasic()
|
||||
assert lookup
|
||||
type '.'
|
||||
checkResult()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class CodeInsightUtilBase {
|
||||
public static <T extends PsiElement> T forcePsiPostprocessAndRestoreElement(final T element) {
|
||||
final PsiFile psiFile = element.getContainingFile();
|
||||
final Document document = psiFile.getViewProvider().getDocument();
|
||||
if (document == null) return element;
|
||||
//if (document == null) return element;
|
||||
final Language language = PsiUtilBase.getDialect(element);
|
||||
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(psiFile.getProject());
|
||||
final RangeMarker rangeMarker = document.createRangeMarker(element.getTextRange());
|
||||
|
||||
Reference in New Issue
Block a user