Commit 55914a27 authored by peter's avatar peter
Browse files

support completion at the end of file with no dummy identifier (IDEA-188584)

parent c91edc8e
Showing with 7 additions and 9 deletions
+7 -9
......@@ -249,14 +249,12 @@ public class CodeCompletionHandlerBase {
if (indicator.blockingWaitForFinish(ourAutoInsertItemTimeout)) {
try {
indicator.getLookup().refreshUi(true, false);
completionFinished(indicator, hasModifiers);
}
catch (Exception e) {
catch (Throwable e) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
LOG.error(e);
return;
}
completionFinished(indicator, hasModifiers);
return;
}
......
......@@ -120,7 +120,7 @@ class CompletionAssertions {
static void assertHostInfo(PsiFile hostCopy, OffsetMap hostMap) {
PsiUtilCore.ensureValid(hostCopy);
if (hostMap.getOffset(CompletionInitializationContext.START_OFFSET) >= hostCopy.getTextLength()) {
if (hostMap.getOffset(CompletionInitializationContext.START_OFFSET) > hostCopy.getTextLength()) {
throw new AssertionError("startOffset outside the host file: " + hostMap.getOffset(CompletionInitializationContext.START_OFFSET) + "; " + hostCopy);
}
}
......@@ -140,10 +140,6 @@ class CompletionAssertions {
createAstAttachment(fileCopy, originalFile));
}
if (fileCopy.findElementAt(offset) != insertedElement) {
throw new AssertionError("wrong offset");
}
final TextRange range = insertedElement.getTextRange();
CharSequence fileCopyText = fileCopy.getViewProvider().getContents();
if ((range.getEndOffset() > fileCopyText.length()) ||
......
......@@ -21,6 +21,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.PsiFileEx;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.reference.SoftReference;
import org.jetbrains.annotations.NotNull;
......@@ -156,6 +157,9 @@ public class CompletionInitializationUtil {
@NotNull
private static PsiElement findCompletionPositionLeaf(OffsetsInFile offsets, int offset, PsiFile originalFile) {
PsiElement insertedElement = offsets.getFile().findElementAt(offset);
if (insertedElement == null && offsets.getFile().getTextLength() == 0) {
insertedElement = PsiTreeUtil.getDeepestLast(offsets.getFile());
}
CompletionAssertions.assertCompletionPositionPsiConsistent(offsets, offset, originalFile, insertedElement);
return insertedElement;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment