mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
don't get in the way when typing a label name in java/groovy
This commit is contained in:
@@ -105,6 +105,17 @@ public class JavaCharFilter extends CharFilter {
|
||||
}
|
||||
if (c == '.' && isWithinLiteral(lookup)) return Result.ADD_TO_PREFIX;
|
||||
|
||||
if (c == ':') {
|
||||
PsiFile file = lookup.getPsiFile();
|
||||
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
|
||||
PsiElement element = lookup.getPsiElement();
|
||||
if (PsiTreeUtil.getParentOfType(element, PsiSwitchLabelStatement.class) != null ||
|
||||
PsiTreeUtil.getParentOfType(element, PsiConditionalExpression.class) != null) {
|
||||
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
}
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
|
||||
if ((c == '[' || c == '<' || c == '.' || c == ' ' || c == '(') && isNonImportedClassEntered((LookupImpl)lookup)) {
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
|
||||
+9
-1
@@ -532,7 +532,7 @@ public interface Test {
|
||||
}
|
||||
edt { myFixture.type '\t' }
|
||||
myFixture.checkResult 'public interface Test { RuntimeException<caret>x }'
|
||||
}
|
||||
}
|
||||
|
||||
private def registerContributor(final Class contributor, LoadingOrder order = LoadingOrder.LAST) {
|
||||
def ep = Extensions.rootArea.getExtensionPoint("com.intellij.completion.contributor")
|
||||
@@ -1194,5 +1194,13 @@ class Foo {{
|
||||
assert 'io' in myFixture.lookupElementStrings
|
||||
}
|
||||
|
||||
public void testEnteringLabel() {
|
||||
myFixture.configureByText 'a.java', '''class Foo {{
|
||||
<caret>
|
||||
}}
|
||||
'''
|
||||
type 'FIS:'
|
||||
assert myFixture.file.text.contains('FIS:')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-2
@@ -20,10 +20,14 @@ import com.intellij.codeInsight.lookup.CharFilter;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseLabel;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrConditionalExpression;
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
@@ -51,6 +55,21 @@ public class GroovyReferenceCharFilter extends CharFilter {
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
|
||||
if (c == ':') {
|
||||
PsiFile file = lookup.getPsiFile();
|
||||
PsiDocumentManager.getInstance(file.getProject()).commitDocument(lookup.getEditor().getDocument());
|
||||
PsiElement element = lookup.getPsiElement();
|
||||
if (PsiTreeUtil.getParentOfType(element, GrCaseLabel.class) != null ||
|
||||
PsiTreeUtil.getParentOfType(element, GrConditionalExpression.class) != null ||
|
||||
PsiTreeUtil.getParentOfType(element, GrArgumentList.class) != null ||
|
||||
PsiTreeUtil.getParentOfType(element, GrListOrMap.class) != null
|
||||
) {
|
||||
return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
}
|
||||
return Result.HIDE_LOOKUP;
|
||||
}
|
||||
|
||||
|
||||
if (c == '[') return CharFilter.Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
if (c == '<' && item.getObject() instanceof PsiClass) return Result.SELECT_ITEM_AND_FINISH_LOOKUP;
|
||||
|
||||
|
||||
@@ -226,4 +226,10 @@ class GroovyAutoPopupTest extends CompletionAutoPopupTestCase {
|
||||
assert myFixture.lookupElementStrings == ['PrimaBalerina']
|
||||
}
|
||||
|
||||
public void testEnteringLabel() {
|
||||
myFixture.configureByText 'a.groovy', '<caret>'
|
||||
type 'FIS:'
|
||||
assert myFixture.file.text == 'FIS:'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user