com.intellij.codeInsight.completion.CompletionProgressIndicator Java Examples
The following examples show how to use
com.intellij.codeInsight.completion.CompletionProgressIndicator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeditorRequestHandler.java From neovim-intellij-complete with MIT License | 6 votes |
public LookupElement[] getCompletionVariants(String path, String fileContent, int line, int column) { LOG.debug(String.format("getCompletionVariants(%s:%d:%d)", path, line, column)); final Collection<LookupElement> completionVariants = ContainerUtil.newLinkedList(); EmbeditorUtil.performCompletion(path, fileContent, line, column, new EmbeditorUtil.CompletionCallback() { @Override public void completionFinished(@NotNull CompletionParameters parameters, @NotNull CompletionProgressIndicator indicator, @NotNull Document document) { for (LookupElement item : indicator.getLookup().getItems()) { //completionVariants.add(item.getUserData(key).toString().replace("\u0000###", "").replace("###", "")); completionVariants.add(item); } } }); return completionVariants.toArray(new LookupElement[completionVariants.size()]); }
Example #2
Source File: AutoPopupControllerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void scheduleAutoPopup(@Nonnull Editor editor, @Nonnull CompletionType completionType, @Nullable final Condition<? super PsiFile> condition) { //if (ApplicationManager.getApplication().isUnitTestMode() && !TestModeFlags.is(CompletionAutoPopupHandler.ourTestingAutopopup)) { // return; //} boolean alwaysAutoPopup = Boolean.TRUE.equals(editor.getUserData(ALWAYS_AUTO_POPUP)); if (!CodeInsightSettings.getInstance().AUTO_POPUP_COMPLETION_LOOKUP && !alwaysAutoPopup) { return; } if (PowerSaveMode.isEnabled()) { return; } if (!CompletionServiceImpl.isPhase(CompletionPhase.CommittingDocuments.class, CompletionPhase.NoCompletion.getClass())) { return; } final CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCurrentCompletionProgressIndicator(); if (currentCompletion != null) { currentCompletion.closeAndFinish(true); } CompletionPhase.CommittingDocuments.scheduleAsyncCompletion(editor, completionType, condition, myProject, null); }
Example #3
Source File: AnnotationLightCodeInsightFixtureTestCase.java From idea-php-generics-plugin with MIT License | 5 votes |
@Override public void run() { CommandProcessor.getInstance().executeCommand(getProject(), () -> { final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.BASIC) { @Override protected void completionFinished(final CompletionProgressIndicator indicator, boolean hasModifiers) { // find our lookup element final LookupElement lookupElement = ContainerUtil.find(indicator.getLookup().getItems(), insert::match); if(lookupElement == null) { fail("No matching lookup element found"); } // overwrite behavior and force completion + insertHandler CommandProcessor.getInstance().executeCommand(indicator.getProject(), new Runnable() { @Override public void run() { //indicator.setMergeCommand(); Currently method has package level access indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, lookupElement); } }, "Autocompletion", null); } }; Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(getEditor(), getFile()); handler.invokeCompletion(getProject(), editor); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }, null, null); }
Example #4
Source File: EmbeditorRequestHandler.java From neovim-intellij-complete with MIT License | 5 votes |
public int getCompletionStartOffsetInLine(String path, String fileContent, int line, int column) { LOG.debug(String.format("getCompletionStartOffsetInLine(%s:%d:%d)", path, line, column)); final Ref<Integer> integerRef = Ref.create(0); EmbeditorUtil.performCompletion(path, fileContent, line, column, new EmbeditorUtil.CompletionCallback() { @Override public void completionFinished(@NotNull CompletionParameters parameters, @NotNull CompletionProgressIndicator indicator, @NotNull Document document) { integerRef.set(EmbeditorUtil.getOffsetFromLineStart(parameters, document)); } }); return integerRef.get(); }
Example #5
Source File: AnnotationLightCodeInsightFixtureTestCase.java From idea-php-annotation-plugin with MIT License | 5 votes |
@Override public void run() { CommandProcessor.getInstance().executeCommand(getProject(), () -> { final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.BASIC) { @Override protected void completionFinished(final CompletionProgressIndicator indicator, boolean hasModifiers) { // find our lookup element final LookupElement lookupElement = ContainerUtil.find(indicator.getLookup().getItems(), insert::match); if(lookupElement == null) { fail("No matching lookup element found"); } // overwrite behavior and force completion + insertHandler CommandProcessor.getInstance().executeCommand(indicator.getProject(), new Runnable() { @Override public void run() { //indicator.setMergeCommand(); Currently method has package level access indicator.getLookup().finishLookup(Lookup.AUTO_INSERT_SELECT_CHAR, lookupElement); } }, "Autocompletion", null); } }; Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(getEditor(), getFile()); handler.invokeCompletion(getProject(), editor); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); }, null, null); }
Example #6
Source File: CodeInsightTestFixtureImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public LookupElement[] complete(final CompletionType type, final int invocationCount) { assertInitialized(); myEmptyLookup = false; UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { final CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(type) { @Override protected void completionFinished(CompletionProgressIndicator indicator, boolean hasModifiers) { myEmptyLookup = indicator.getLookup().getItems().isEmpty(); super.completionFinished(indicator, hasModifiers); } }; Editor editor = getCompletionEditor(); handler.invokeCompletion(getProject(), editor, invocationCount); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); // to compare with file text } }, null, null); } }); return getLookupElements(); }
Example #7
Source File: BackspaceHandler.java From consulo with Apache License 2.0 | 5 votes |
static void truncatePrefix(final DataContext dataContext, LookupImpl lookup, final EditorActionHandler handler, final int hideOffset, final Caret caret) { final Editor editor = lookup.getEditor(); if (!lookup.performGuardedChange(() -> handler.execute(editor, caret, dataContext))) { return; } final CompletionProgressIndicator process = CompletionServiceImpl.getCurrentCompletionProgressIndicator(); lookup.truncatePrefix(process == null || !process.isAutopopupCompletion(), hideOffset); }
Example #8
Source File: LightPlatformTestCase.java From consulo with Apache License 2.0 | 4 votes |
public static void doTearDown(@Nonnull final Project project, ApplicationStarter application, boolean checkForEditors) throws Exception { DocumentCommitThread.getInstance().clearQueue(); CodeStyleSettingsManager.getInstance(project).dropTemporarySettings(); checkAllTimersAreDisposed(); UsefulTestCase.doPostponedFormatting(project); LookupManager lookupManager = LookupManager.getInstance(project); if (lookupManager != null) { lookupManager.hideActiveLookup(); } ((StartupManagerImpl)StartupManager.getInstance(project)).prepareForNextTest(); InspectionProfileManager.getInstance().deleteProfile(PROFILE); assertNotNull("Application components damaged", ProjectManager.getInstance()); new WriteCommandAction.Simple(project) { @Override @RequiredWriteAction protected void run() throws Throwable { if (ourSourceRoot != null) { try { final VirtualFile[] children = ourSourceRoot.getChildren(); for (VirtualFile child : children) { child.delete(this); } } catch (IOException e) { //noinspection CallToPrintStackTrace e.printStackTrace(); } } EncodingManager encodingManager = EncodingManager.getInstance(); if (encodingManager instanceof EncodingManagerImpl) ((EncodingManagerImpl)encodingManager).clearDocumentQueue(); FileDocumentManager manager = FileDocumentManager.getInstance(); ApplicationManager.getApplication().runWriteAction(EmptyRunnable.getInstance()); // Flush postponed formatting if any. manager.saveAllDocuments(); if (manager instanceof FileDocumentManagerImpl) { ((FileDocumentManagerImpl)manager).dropAllUnsavedDocuments(); } } }.execute().throwException(); assertFalse(PsiManager.getInstance(project).isDisposed()); PsiDocumentManagerImpl documentManager = clearUncommittedDocuments(project); ((HintManagerImpl)HintManager.getInstance()).cleanup(); DocumentCommitThread.getInstance().clearQueue(); UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { ((UndoManagerImpl)UndoManager.getGlobalInstance()).dropHistoryInTests(); ((UndoManagerImpl)UndoManager.getInstance(project)).dropHistoryInTests(); UIUtil.dispatchAllInvocationEvents(); } }); TemplateDataLanguageMappings.getInstance(project).cleanupForNextTest(); ProjectManagerEx.getInstanceEx().closeTestProject(project); //application.setDataProvider(null); ourTestCase = null; ((PsiManagerImpl)PsiManager.getInstance(project)).cleanupForNextTest(); CompletionProgressIndicator.cleanupForNextTest(); if (checkForEditors) { checkEditorsReleased(); } if (isLight(project)) { // mark temporarily as disposed so that rogue component trying to access it will fail ((ProjectImpl)project).setTemporarilyDisposed(true); documentManager.clearUncommittedDocuments(); } }
Example #9
Source File: LookupActionHandler.java From consulo with Apache License 2.0 | 4 votes |
@Override protected void executeInLookup(LookupImpl lookup, DataContext context, final Caret caret) { final Editor editor = lookup.getEditor(); final int offset = editor.getCaretModel().getOffset(); final CharSequence seq = editor.getDocument().getCharsSequence(); if (seq.length() <= offset || !lookup.isCompletion()) { myOriginalHandler.execute(editor, caret, context); return; } char c = seq.charAt(offset); CharFilter.Result lookupAction = LookupTypedHandler.getLookupAction(c, lookup); if (lookupAction != CharFilter.Result.ADD_TO_PREFIX || Character.isWhitespace(c)) { myOriginalHandler.execute(editor, caret, context); return; } if (!lookup.performGuardedChange(() -> { CaretAction action = lookupCaret -> { lookupCaret.removeSelection(); int caretOffset = lookupCaret.getOffset(); if (caretOffset < seq.length()) { lookupCaret.moveToOffset(caretOffset + 1); } }; if (caret == null) { editor.getCaretModel().runForEachCaret(action); } else { action.perform(caret); } })) { return; } lookup.fireBeforeAppendPrefix(c); lookup.appendPrefix(c); final CompletionProgressIndicator completion = CompletionServiceImpl.getCurrentCompletionProgressIndicator(); if (completion != null) { completion.prefixUpdated(); } }