mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
mad testing: check errors in host file when completion expectation fails, don't expect regex group names to be completed
GitOrigin-RevId: 051fff25bb0b39fe93e6004db48aee6492a9c389
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3b7a1dc7e2
commit
9fdc3606bc
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.paths.WebReference;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -54,10 +55,14 @@ public class CompletionPolicy {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (leafText.length() == 1 &&
|
||||
"org.intellij.lang.regexp.RegExpElementType".equals(PsiUtilCore.getElementType(leaf).getClass().getName())) {
|
||||
// regexp has a token for each character: not interesting (and no completion)
|
||||
return null;
|
||||
IElementType leafType = PsiUtilCore.getElementType(leaf);
|
||||
if ("org.intellij.lang.regexp.RegExpElementType".equals(leafType.getClass().getName())) {
|
||||
if (leafText.length() == 1) {
|
||||
return null; // regexp has a token for each character: not interesting (and no completion)
|
||||
}
|
||||
if ("NAME".equals(leafType.toString())) {
|
||||
return null; // group name, no completion expected
|
||||
}
|
||||
}
|
||||
|
||||
if (isDeclarationName(editor, file, leaf, ref)) return null;
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageEditorUtil;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
@@ -127,7 +128,7 @@ public class InvokeCompletion extends ActionOnFile {
|
||||
return;
|
||||
}
|
||||
env.logMessage("No lookup");
|
||||
if (expectedVariant == null || prefixEqualsExpected || !checkAnnotatorErrorsAtCaret(editor, file, env, expectedVariant)) {
|
||||
if (expectedVariant == null || prefixEqualsExpected || !checkAnnotatorErrorsAtCaret(editor, env, expectedVariant)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ public class InvokeCompletion extends ActionOnFile {
|
||||
LookupElement sameItem = ContainerUtil.find(items, e ->
|
||||
e.getAllLookupStrings().stream().anyMatch(
|
||||
s -> Comparing.equal(s, expectedVariant, e.isCaseSensitive())));
|
||||
if (sameItem == null && !checkAnnotatorErrorsAtCaret(editor, file, env, expectedVariant)) {
|
||||
if (sameItem == null && !checkAnnotatorErrorsAtCaret(editor, env, expectedVariant)) {
|
||||
return;
|
||||
}
|
||||
TestCase.assertNotNull("No variant '" + expectedVariant + "' among " + items + notFound, sameItem);
|
||||
@@ -161,12 +162,10 @@ public class InvokeCompletion extends ActionOnFile {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAnnotatorErrorsAtCaret(@NotNull Editor editor,
|
||||
@NotNull PsiFile file,
|
||||
Environment env,
|
||||
String expectedVariant) {
|
||||
List<HighlightInfo> infos = InvokeIntention.highlightErrors(getProject(), editor);
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
private boolean checkAnnotatorErrorsAtCaret(Editor editor, Environment env, String expectedVariant) {
|
||||
Editor hostEditor = InjectedLanguageEditorUtil.getTopLevelEditor(editor);
|
||||
List<HighlightInfo> infos = InvokeIntention.highlightErrors(getProject(), hostEditor);
|
||||
int caretOffset = hostEditor.getCaretModel().getOffset();
|
||||
boolean hasErrors = ContainerUtil.exists(infos, i -> i.getStartOffset() <= caretOffset && caretOffset <= i.getEndOffset());
|
||||
if (hasErrors) {
|
||||
env.logMessage("Found syntax errors at the completion point, skipping expected completion check for '" + expectedVariant + "'");
|
||||
|
||||
Reference in New Issue
Block a user