use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class CodeInsightTestUtil method doLiveTemplateTest.
public static void doLiveTemplateTest(@NotNull final CodeInsightTestFixture fixture, @NotNull final String before, @NotNull final String after) {
fixture.configureByFile(before);
new ListTemplatesAction().actionPerformedImpl(fixture.getProject(), fixture.getEditor());
final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(fixture.getEditor());
assert lookup != null;
lookup.finishLookup(Lookup.NORMAL_SELECT_CHAR);
fixture.checkResultByFile(after, false);
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class BaseRefactoringAction method actionPerformed.
@Override
public final void actionPerformed(@NotNull AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Project project = e.getProject();
if (project == null)
return;
PsiDocumentManager.getInstance(project).commitAllDocuments();
final Editor editor = e.getData(CommonDataKeys.EDITOR);
final PsiElement[] elements = getPsiElementArray(dataContext);
int eventCount = IdeEventQueue.getInstance().getEventCount();
RefactoringActionHandler handler;
try {
handler = getHandler(dataContext);
} catch (ProcessCanceledException ignored) {
return;
}
if (handler == null) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol.to.refactor"));
CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.getCannotRefactorMessage(null), null);
return;
}
InplaceRefactoring activeInplaceRenamer = InplaceRefactoring.getActiveInplaceRenamer(editor);
if (!InplaceRefactoring.canStartAnotherRefactoring(editor, project, handler, elements) && activeInplaceRenamer != null) {
InplaceRefactoring.unableToStartWarning(project, editor);
return;
}
if (activeInplaceRenamer == null) {
final LookupEx lookup = LookupManager.getActiveLookup(editor);
if (lookup instanceof LookupImpl) {
Runnable command = () -> ((LookupImpl) lookup).finishLookup(Lookup.NORMAL_SELECT_CHAR);
Document doc = editor.getDocument();
DocCommandGroupId group = DocCommandGroupId.noneGroupId(doc);
CommandProcessor.getInstance().executeCommand(editor.getProject(), command, "Completion", group, UndoConfirmationPolicy.DEFAULT, doc);
}
}
IdeEventQueue.getInstance().setEventCount(eventCount);
if (editor != null) {
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null)
return;
DaemonCodeAnalyzer.getInstance(project).autoImportReferenceAtCursor(editor, file);
handler.invoke(project, editor, file, dataContext);
} else {
handler.invoke(project, elements, dataContext);
}
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class CodeCompletionHandlerBase method doComplete.
private void doComplete(CompletionInitializationContext initContext, boolean hasModifiers, int invocationCount, OffsetTranslator translator, OffsetsInFile hostOffsets, OffsetsInFile hostCopyOffsets) {
final Editor editor = initContext.getEditor();
CompletionAssertions.checkEditorValid(editor);
CompletionContext context = createCompletionContext(initContext.getFile(), hostCopyOffsets);
LookupImpl lookup = obtainLookup(editor, initContext.getProject());
CompletionParameters parameters = createCompletionParameters(invocationCount, context, editor);
CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
if (phase instanceof CompletionPhase.CommittingDocuments) {
if (phase.indicator != null) {
phase.indicator.closeAndFinish(false);
}
((CompletionPhase.CommittingDocuments) phase).replaced = true;
} else {
CompletionServiceImpl.assertPhase(CompletionPhase.NoCompletion.getClass());
}
final CompletionProgressIndicator indicator = new CompletionProgressIndicator(editor, initContext.getCaret(), parameters, this, initContext.getOffsetMap(), hostOffsets, hasModifiers, lookup);
Disposer.register(indicator, hostCopyOffsets.getOffsets());
Disposer.register(indicator, context.getOffsetMap());
Disposer.register(indicator, translator);
CompletionServiceImpl.setCompletionPhase(synchronous ? new CompletionPhase.Synchronous(indicator) : new CompletionPhase.BgCalculation(indicator));
indicator.startCompletion(initContext);
if (!synchronous) {
return;
}
if (indicator.blockingWaitForFinish(ourAutoInsertItemTimeout)) {
try {
indicator.getLookup().refreshUi(true, false);
} catch (Exception e) {
CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
LOG.error(e);
return;
}
completionFinished(indicator, hasModifiers);
return;
}
CompletionServiceImpl.setCompletionPhase(new CompletionPhase.BgCalculation(indicator));
indicator.showLookup();
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class CompletionLookupArranger method arrangeItems.
@Override
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup, boolean onExplicitAction) {
List<LookupElement> items = getMatchingItems();
MultiMap<CompletionSorterImpl, LookupElement> itemsBySorter = groupItemsBySorter(items);
LookupElement relevantSelection = findMostRelevantItem(itemsBySorter);
LookupImpl lookupImpl = (LookupImpl) lookup;
List<LookupElement> listModel = isAlphaSorted() ? sortByPresentation(items) : fillModelByRelevance(lookupImpl, ContainerUtil.newIdentityTroveSet(items), itemsBySorter, relevantSelection);
int toSelect = getItemToSelect(lookupImpl, listModel, onExplicitAction, relevantSelection);
LOG.assertTrue(toSelect >= 0);
addDummyItems(items.size() - listModel.size(), listModel);
return new Pair<>(listModel, toSelect);
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class TemplatesCompletionTest method testAutopopupWithEnabledLiveTemplatesInCompletion.
public void testAutopopupWithEnabledLiveTemplatesInCompletion() {
LiveTemplateCompletionContributor.setShowTemplatesInTests(false, myFixture.getTestRootDisposable());
configureByFile();
type("instanceof");
LookupImpl lookup = getLookup();
assertNotNull(lookup);
assertEquals(1, lookup.getItems().size());
LookupElement item = lookup.getCurrentItem();
assertNotNull(item);
assertInstanceOf(item, PostfixTemplateLookupElement.class);
assertInstanceOf(((PostfixTemplateLookupElement) item).getPostfixTemplate(), InstanceofExpressionPostfixTemplate.class);
}
Aggregations