use of com.intellij.codeInsight.lookup.LookupEx in project intellij-community by JetBrains.
the class PyTestCase method completeCaretWithMultipleVariants.
/**
* When you have more than one completion variant, you may use this method providing variant to choose.
* It only works for one caret (multiple carets not supported) and since it puts tab after completion, be sure to limit
* line somehow (i.e. with comment).
* <br/>
* Example: "user.n[caret]." There are "name" and "nose" fields.
* By calling this function with "nose" you will end with "user.nose ".
*/
protected final void completeCaretWithMultipleVariants(@NotNull final String... desiredVariants) {
final LookupElement[] lookupElements = myFixture.completeBasic();
final LookupEx lookup = myFixture.getLookup();
if (lookupElements != null && lookupElements.length > 1) {
// More than one element returned, check directly because completion can't work in this case
for (final LookupElement element : lookupElements) {
final String suggestedString = element.getLookupString();
if (Arrays.asList(desiredVariants).contains(suggestedString)) {
myFixture.getLookup().setCurrentItem(element);
lookup.setCurrentItem(element);
myFixture.completeBasicAllCarets('\t');
return;
}
}
}
}
use of com.intellij.codeInsight.lookup.LookupEx in project intellij-community by JetBrains.
the class ShowIntentionActionsHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
}
final LookupEx lookup = LookupManager.getActiveLookup(editor);
if (lookup != null) {
lookup.showElementActions();
return;
}
final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(project);
letAutoImportComplete(editor, file, codeAnalyzer);
ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
IntentionHintComponent hintComponent = codeAnalyzer.getLastIntentionHint();
if (hintComponent != null) {
IntentionHintComponent.PopupUpdateResult result = hintComponent.isForEditor(editor) ? hintComponent.updateActions(intentions) : IntentionHintComponent.PopupUpdateResult.HIDE_AND_RECREATE;
if (result == IntentionHintComponent.PopupUpdateResult.HIDE_AND_RECREATE) {
hintComponent.hide();
}
}
if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction())
return;
//intentions check isWritable before modification: if (!file.isWritable()) return;
TemplateState state = TemplateManagerImpl.getTemplateState(editor);
if (state != null && !state.isFinished()) {
return;
}
if (!intentions.isEmpty()) {
IntentionHintComponent.showIntentionHint(project, file, editor, intentions, true);
}
}
use of com.intellij.codeInsight.lookup.LookupEx in project intellij-community by JetBrains.
the class DocumentationManager method showJavaDocInfo.
public void showJavaDocInfo(final Editor editor, @Nullable final PsiFile file, boolean requestFocus, @Nullable final Runnable closeCallback) {
myEditor = editor;
final Project project = getProject(file);
PsiDocumentManager.getInstance(project).commitAllDocuments();
final PsiElement list = ParameterInfoController.findArgumentList(file, editor.getCaretModel().getOffset(), -1);
PsiElement expressionList = null;
if (list != null) {
LookupEx lookup = LookupManager.getInstance(myProject).getActiveLookup();
if (lookup != null) {
// take completion variants for documentation then
expressionList = null;
} else {
expressionList = list;
}
}
final PsiElement originalElement = getContextElement(editor, file);
PsiElement element = assertSameProject(findTargetElement(editor, file));
if (element == null && expressionList != null) {
element = expressionList;
}
//file == null for text field editor
if (element == null && file == null)
return;
if (element == null) {
// look if we are within a javadoc comment
element = assertSameProject(originalElement);
if (element == null)
return;
PsiComment comment = PsiTreeUtil.getParentOfType(element, PsiComment.class);
if (comment == null)
return;
element = comment instanceof PsiDocCommentBase ? ((PsiDocCommentBase) comment).getOwner() : comment.getParent();
if (element == null)
return;
//if (!(element instanceof PsiDocCommentOwner)) return null;
}
final PopupUpdateProcessor updateProcessor = new PopupUpdateProcessor(project) {
@Override
public void updatePopup(Object lookupIteObject) {
if (lookupIteObject == null) {
return;
}
if (lookupIteObject instanceof PsiElement) {
doShowJavaDocInfo((PsiElement) lookupIteObject, false, this, originalElement, closeCallback);
return;
}
DocumentationProvider documentationProvider = getProviderFromElement(file);
PsiElement element = documentationProvider.getDocumentationElementForLookupItem(PsiManager.getInstance(myProject), lookupIteObject, originalElement);
if (element == null)
return;
if (myEditor != null) {
final PsiFile file = element.getContainingFile();
if (file != null) {
Editor editor = myEditor;
showJavaDocInfo(myEditor, file, false);
myEditor = editor;
}
} else {
doShowJavaDocInfo(element, false, this, originalElement, closeCallback);
}
}
};
doShowJavaDocInfo(element, requestFocus, updateProcessor, originalElement, closeCallback);
}
use of com.intellij.codeInsight.lookup.LookupEx in project Perl5-IDEA by Camelcade.
the class PerlCompletionPopupTest method doCheckAutopopupResult.
private void doCheckAutopopupResult(@NotNull String type, boolean result) {
myTester.typeWithPauses(type);
LookupEx activeLookup = LookupManager.getActiveLookup(getEditor());
if (result) {
assertNotNull(activeLookup);
} else {
assertNull(activeLookup);
}
}
use of com.intellij.codeInsight.lookup.LookupEx in project android by JetBrains.
the class AndroidLayoutDomTest method testDimenUnitsCompletion1.
public void testDimenUnitsCompletion1() throws Exception {
VirtualFile file = copyFileToProject(getTestName(true) + ".xml");
myFixture.configureFromExistingVirtualFile(file);
myFixture.complete(CompletionType.BASIC);
UsefulTestCase.assertSameElements(myFixture.getLookupElementStrings(), "3dp", "3px", "3sp", "3pt", "3mm", "3in");
PsiElement originalElement = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
LookupEx lookup = myFixture.getLookup();
LookupElement dpElement = null;
LookupElement pxElement = null;
for (LookupElement element : lookup.getItems()) {
if (element.getLookupString().endsWith("dp")) {
dpElement = element;
} else if (element.getLookupString().endsWith("px")) {
pxElement = element;
}
}
DocumentationProvider provider;
PsiElement docTargetElement;
lookup.setCurrentItem(dpElement);
docTargetElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
provider = DocumentationManager.getProviderFromElement(docTargetElement);
assertEquals("<html><body><b>Density-independent Pixels</b> - an abstract unit that is based on the physical " + "density of the screen.</body></html>", provider.generateDoc(docTargetElement, originalElement));
lookup.setCurrentItem(pxElement);
docTargetElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
provider = DocumentationManager.getProviderFromElement(docTargetElement);
assertEquals("<html><body><b>Pixels</b> - corresponds to actual pixels on the screen. Not recommended.</body></html>", provider.generateDoc(docTargetElement, originalElement));
}
Aggregations