mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-83475 Disable autopopup in unfinished String literals
This commit is contained in:
@@ -1240,4 +1240,16 @@ class Foo {{
|
||||
assert myFixture.lookupElementStrings.containsAll(['too', 'command.toString'])
|
||||
}
|
||||
|
||||
public void testUnfinishedString() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
// Date
|
||||
class Foo {
|
||||
String s = "<caret>
|
||||
String s2 = s;
|
||||
}
|
||||
'''
|
||||
type 'D'
|
||||
assert !lookup
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-3
@@ -17,10 +17,11 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.lang.LanguageParserDefinitions;
|
||||
import com.intellij.lang.ParserDefinition;
|
||||
import com.intellij.patterns.ElementPattern;
|
||||
import com.intellij.patterns.PlatformPatterns;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.util.ThreeState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -42,13 +43,26 @@ public class SkipAutopopupInStrings extends CompletionConfidence {
|
||||
if (contextElement != null) {
|
||||
ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(PsiUtilBase.getLanguageAtOffset(psiFile, offset));
|
||||
if (definition != null) {
|
||||
ElementPattern<PsiElement> pattern = PlatformPatterns.psiElement().withElementType(definition.getStringLiteralElements());
|
||||
if (pattern.accepts(contextElement) || pattern.accepts(contextElement.getParent())) {
|
||||
if (isStringLiteral(contextElement, definition) || isStringLiteral(contextElement.getParent(), definition)) {
|
||||
return ThreeState.YES;
|
||||
}
|
||||
if (offset > 0) {
|
||||
PsiElement prev = psiFile.findElementAt(offset - 1);
|
||||
if (prev != null && (isStringLiteralWithError(prev, definition) || isStringLiteralWithError(prev.getParent(), definition))) {
|
||||
return ThreeState.YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ThreeState.UNSURE;
|
||||
}
|
||||
|
||||
private static boolean isStringLiteral(PsiElement element, ParserDefinition definition) {
|
||||
return PlatformPatterns.psiElement().withElementType(definition.getStringLiteralElements()).accepts(element);
|
||||
}
|
||||
|
||||
private static boolean isStringLiteralWithError(PsiElement element, ParserDefinition definition) {
|
||||
return isStringLiteral(element, definition) && PsiTreeUtil.nextLeaf(element) instanceof PsiErrorElement;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user