com.intellij.codeInsight.documentation.DocumentationManager Java Examples
The following examples show how to use
com.intellij.codeInsight.documentation.DocumentationManager.
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: ShowQuickDocInfoAction.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override protected CodeInsightActionHandler getHandler() { return new CodeInsightActionHandler() { @RequiredUIAccess @Override public void invoke(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file) { DocumentationManager.getInstance(project).showJavaDocInfo(editor, file, LookupManager.getActiveLookup(editor) == null); } @Override public boolean startInWriteAction() { return false; } }; }
Example #2
Source File: ShowQuickDocInfoAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final Editor editor = e.getData(CommonDataKeys.EDITOR); final PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT); if (project != null && editor != null) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_FEATURE); final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(project).getActiveLookup(); if (lookup != null) { //dumpLookupElementWeights(lookup); FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE); } actionPerformedImpl(project, editor); } else if (project != null && element != null) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_CTRLN_FEATURE); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { DocumentationManager.getInstance(project).showJavaDocInfo(element, null); } }, getCommandName(), null); } }
Example #3
Source File: LookupManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
private void showJavadoc(LookupImpl lookup) { if (myActiveLookup != lookup) return; DocumentationManager docManager = DocumentationManager.getInstance(myProject); if (docManager.getDocInfoHint() != null) return; // will auto-update LookupElement currentItem = lookup.getCurrentItem(); CompletionProcess completion = CompletionService.getCompletionService().getCurrentCompletion(); if (currentItem != null && currentItem.isValid() && isAutoPopupJavadocSupportedBy(currentItem) && completion != null) { try { boolean hideLookupWithDoc = completion.isAutopopupCompletion() || CodeInsightSettings.getInstance().JAVADOC_INFO_DELAY == 0; docManager.showJavaDocInfo(lookup.getEditor(), lookup.getPsiFile(), false, () -> { if (hideLookupWithDoc && completion == CompletionService.getCompletionService().getCurrentCompletion()) { hideActiveLookup(); } }); } catch (IndexNotReadyException ignored) { } } }
Example #4
Source File: CtrlMouseHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override public void hyperlinkUpdate(@Nonnull HyperlinkEvent e) { if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { return; } String description = e.getDescription(); if (StringUtil.isEmpty(description) || !description.startsWith(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL)) { return; } String elementName = e.getDescription().substring(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL.length()); DumbService.getInstance(myProject).withAlternativeResolveEnabled(() -> { PsiElement targetElement = myProvider.getDocumentationElementForLink(PsiManager.getInstance(myProject), elementName, myContext); if (targetElement != null) { LightweightHint hint = myHint; if (hint != null) { hint.hide(true); } DocumentationManager.getInstance(myProject).showJavaDocInfo(targetElement, myContext, null); } }); }
Example #5
Source File: CtrlMouseHandler.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static DocInfo generateInfo(PsiElement element, PsiElement atPointer, boolean fallbackToBasicInfo) { final DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(element, atPointer); String result = documentationProvider.getQuickNavigateInfo(element, atPointer); if (result == null && fallbackToBasicInfo) { result = doGenerateInfo(element); } return result == null ? DocInfo.EMPTY : new DocInfo(result, documentationProvider); }
Example #6
Source File: ExternalJavaDocAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Editor editor = dataContext.getData(CommonDataKeys.EDITOR); PsiElement element = getElement(dataContext, editor); final PsiElement originalElement = getOriginalElement(dataContext.getData(CommonDataKeys.PSI_FILE), editor); DocumentationManager.storeOriginalElement(dataContext.getData(CommonDataKeys.PROJECT), originalElement, element); final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element); boolean enabled; if (provider instanceof ExternalDocumentationProvider) { final ExternalDocumentationProvider edProvider = (ExternalDocumentationProvider)provider; enabled = edProvider.hasDocumentationFor(element, originalElement) || edProvider.canPromptToConfigureDocumentation(element); } else { final List<String> urls = provider.getUrlFor(element, originalElement); enabled = urls != null && !urls.isEmpty(); } if (editor != null) { presentation.setEnabled(enabled); if (ActionPlaces.isMainMenuOrActionSearch(event.getPlace())) { presentation.setVisible(true); } else { presentation.setVisible(enabled); } } else{ presentation.setEnabled(enabled); presentation.setVisible(true); } }
Example #7
Source File: ExternalJavaDocAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null) { return; } Editor editor = dataContext.getData(CommonDataKeys.EDITOR); PsiElement element = getElement(dataContext, editor); if (element == null) { Messages.showMessageDialog( project, IdeBundle.message("message.please.select.element.for.javadoc"), IdeBundle.message("title.no.element.selected"), Messages.getErrorIcon() ); return; } PsiFile context = dataContext.getData(CommonDataKeys.PSI_FILE); PsiElement originalElement = getOriginalElement(context, editor); DocumentationManager.storeOriginalElement(project, originalElement, element); showExternalJavadoc(element, originalElement, null, dataContext); }
Example #8
Source File: PopupUpdateProcessor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void beforeShown(final LightweightWindowEvent windowEvent) { final Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup(); if (activeLookup != null) { activeLookup.addLookupListener(new LookupAdapter() { @Override public void currentItemChanged(LookupEvent event) { if (windowEvent.asPopup().isVisible()) { //was not canceled yet final LookupElement item = event.getItem(); if (item != null) { PsiElement targetElement = CompletionUtil.getTargetElement(item); if (targetElement == null) { targetElement = DocumentationManager.getInstance(myProject).getElementFromLookup(activeLookup.getEditor(), activeLookup.getPsiFile()); } updatePopup(targetElement); //open next } } else { activeLookup.removeLookupListener(this); } } }); } else { final Component focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject); boolean fromQuickSearch = focusedComponent != null && focusedComponent.getParent() instanceof ChooseByNameBase.JPanelProvider; if (fromQuickSearch) { ChooseByNameBase.JPanelProvider panelProvider = (ChooseByNameBase.JPanelProvider)focusedComponent.getParent(); panelProvider.registerHint(windowEvent.asPopup()); } else if (focusedComponent instanceof JComponent) { HintUpdateSupply supply = HintUpdateSupply.getSupply((JComponent)focusedComponent); if (supply != null) supply.registerHint(windowEvent.asPopup()); } } }
Example #9
Source File: EditorMouseHoverPopupManager.java From consulo with Apache License 2.0 | 5 votes |
private static PsiElement extractOriginalElement(PsiElement element) { if (element == null) { return null; } SmartPsiElementPointer<?> originalElementPointer = element.getUserData(DocumentationManager.ORIGINAL_ELEMENT_KEY); return originalElementPointer == null ? null : originalElementPointer.getElement(); }
Example #10
Source File: DaemonListeners.java From consulo with Apache License 2.0 | 5 votes |
@Override public void mouseMoved(@Nonnull EditorMouseEvent e) { if (Registry.is("ide.disable.editor.tooltips") || Registry.is("editor.new.mouse.hover.popups")) { return; } Editor editor = e.getEditor(); if (myProject != editor.getProject()) return; if (EditorMouseHoverPopupControl.arePopupsDisabled(editor)) return; boolean shown = false; try { if (e.getArea() == EditorMouseEventArea.EDITING_AREA && !UIUtil.isControlKeyDown(e.getMouseEvent()) && DocumentationManager.getInstance(myProject).getDocInfoHint() == null && EditorUtil.isPointOverText(editor, e.getMouseEvent().getPoint())) { LogicalPosition logical = editor.xyToLogicalPosition(e.getMouseEvent().getPoint()); int offset = editor.logicalPositionToOffset(logical); HighlightInfo info = myDaemonCodeAnalyzer.findHighlightByOffset(editor.getDocument(), offset, false); if (info == null || info.getDescription() == null || info.getHighlighter() != null && FoldingUtil.isHighlighterFolded(editor, info.getHighlighter())) { IdeTooltipManager.getInstance().hideCurrent(e.getMouseEvent()); return; } DaemonTooltipUtil.showInfoTooltip(info, editor, offset); shown = true; } } finally { if (!shown && !TooltipController.getInstance().shouldSurvive(e.getMouseEvent())) { DaemonTooltipUtil.cancelTooltips(); } } }
Example #11
Source File: ShowQuickDocAtPinnedWindowFromTooltipAction.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void doActionPerformed(@Nonnull DataContext context, @Nonnull PsiElement docAnchor, @Nonnull PsiElement originalElement) { Project project = context.getData(CommonDataKeys.PROJECT); if (project == null) { return; } DocumentationManager docManager = DocumentationManager.getInstance(project); docManager.setAllowContentUpdateFromContext(false); docManager.showJavaDocInfoAtToolWindow(docAnchor, originalElement); }
Example #12
Source File: CopyQuickDocAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(AnActionEvent e) { String selected = e.getData(DocumentationManager.SELECTED_QUICK_DOC_TEXT); if (selected == null || selected.isEmpty()) { return; } CopyPasteManager.getInstance().setContents(new StringSelection(selected)); }
Example #13
Source File: ShowImplementationsAction.java From consulo with Apache License 2.0 | 5 votes |
protected static PsiElement getElement(@Nonnull Project project, PsiFile file, Editor editor, PsiElement element) { if (element == null && editor != null) { element = TargetElementUtil.findTargetElement(editor, TargetElementUtil.getAllAccepted()); final PsiElement adjustedElement = TargetElementUtil.adjustElement(editor, TargetElementUtil.getAllAccepted(), element, null); if (adjustedElement != null) { element = adjustedElement; } else if (file != null) { element = DocumentationManager.getInstance(project).getElementFromLookup(editor, file); } } return element; }
Example #14
Source File: BaseDocumentationTest.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
public String verify() { Editor editor = myFixture.getEditor(); PsiFile file = myFixture.getFile(); PsiElement originalElement = file.findElementAt(editor.getCaretModel().getOffset()); PsiElement element = DocumentationManager.getInstance(getProject()).findTargetElement(editor, file); assertThat(originalElement).isNotNull(); assertThat(element).isNotNull(); DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(originalElement); return documentationProvider.generateDoc(element, originalElement); }
Example #15
Source File: CtrlMouseHandler.java From consulo with Apache License 2.0 | 4 votes |
private void addHighlighterAndShowHint(@Nonnull Info info, @Nonnull DocInfo docInfo, @Nonnull EditorEx editor) { if (myDisposed || editor.isDisposed()) return; if (myHighlighter != null) { if (!info.isSimilarTo(myHighlighter.getStoredInfo())) { disposeHighlighter(); } else { // highlighter already set if (info.isNavigatable()) { editor.setCustomCursor(CtrlMouseHandler.class, Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } return; } } if (!info.isValid(editor.getDocument()) || !info.isNavigatable() && docInfo.text == null) { return; } boolean highlighterOnly = EditorSettingsExternalizable.getInstance().isShowQuickDocOnMouseOverElement() && DocumentationManager.getInstance(myProject).getDocInfoHint() != null; myHighlighter = installHighlighterSet(info, editor, highlighterOnly); if (highlighterOnly || docInfo.text == null) return; HyperlinkListener hyperlinkListener = docInfo.docProvider == null ? null : new QuickDocHyperlinkListener(docInfo.docProvider, info.myElementAtPointer); Ref<Consumer<? super String>> newTextConsumerRef = new Ref<>(); JComponent component = HintUtil.createInformationLabel(docInfo.text, hyperlinkListener, null, newTextConsumerRef); component.setBorder(JBUI.Borders.empty(6, 6, 5, 6)); final LightweightHint hint = new LightweightHint(wrapInScrollPaneIfNeeded(component, editor)); myHint = hint; hint.addHintListener(__ -> myHint = null); showHint(hint, editor); Consumer<? super String> newTextConsumer = newTextConsumerRef.get(); if (newTextConsumer != null) { updateOnPsiChanges(hint, info, newTextConsumer, docInfo.text, editor); } }
Example #16
Source File: SpringConfigurationMetadataGroup.java From intellij-spring-assistant with MIT License | 4 votes |
public String getDocumentation(String nodeNavigationPathDotDelimited) { // Format for the documentation is as follows /* * <p><b>a.b.c</b> ({@link com.acme.Generic}<{@link com.acme.Class1}, {@link com.acme.Class2}>)</p> * <p>Long description</p> * or of this type * <p><b>Type</b> {@link com.acme.Array}[]</p> * <p><b>Declared at</b>{@link com.acme.GenericRemovedClass#method}></p> <-- only for groups with method info */ StringBuilder builder = new StringBuilder().append("<b>").append(nodeNavigationPathDotDelimited).append("</b>"); if (className != null) { builder.append(" ("); updateClassNameAsJavadocHtml(builder, className); builder.append(")"); } if (description != null) { builder.append("<p>").append(description).append("</p>"); } if (sourceType != null) { String sourceTypeInJavadocFormat = removeGenerics(sourceType); if (sourceMethod != null) { sourceTypeInJavadocFormat += ("." + sourceMethod); } // lets show declaration point only if does not match the type if (!sourceTypeInJavadocFormat.equals(removeGenerics(className))) { StringBuilder buffer = new StringBuilder(); DocumentationManager .createHyperlink(buffer, methodForDocumentationNavigation(sourceTypeInJavadocFormat), sourceTypeInJavadocFormat, false); sourceTypeInJavadocFormat = buffer.toString(); builder.append("<p>Declared at ").append(sourceTypeInJavadocFormat).append("</p>"); } } return builder.toString(); }
Example #17
Source File: CopyQuickDocAction.java From consulo with Apache License 2.0 | 4 votes |
@Override public void update(AnActionEvent e) { String selected = e.getData(DocumentationManager.SELECTED_QUICK_DOC_TEXT); e.getPresentation().setEnabled(selected != null && !selected.isEmpty()); }
Example #18
Source File: ExternalJavaDocAction.java From consulo with Apache License 2.0 | 4 votes |
public static void showExternalJavadoc(PsiElement element, PsiElement originalElement, String docUrl, DataContext dataContext) { DocumentationProvider provider = DocumentationManager.getProviderFromElement(element); if (provider instanceof ExternalDocumentationHandler && ((ExternalDocumentationHandler)provider).handleExternal(element, originalElement)) { return; } Project project = dataContext.getData(CommonDataKeys.PROJECT); final Component contextComponent = dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT); ApplicationManager.getApplication().executeOnPooledThread(() -> { List<String> urls; if (StringUtil.isEmptyOrSpaces(docUrl)) { ThrowableComputable<List<String>,RuntimeException> action = () -> provider.getUrlFor(element, originalElement); urls = AccessRule.read(action); } else { urls = Collections.singletonList(docUrl); } if (provider instanceof ExternalDocumentationProvider && urls != null && urls.size() > 1) { for (String url : urls) { List<String> thisUrlList = Collections.singletonList(url); String doc = ((ExternalDocumentationProvider)provider).fetchExternalDocumentation(project, element, thisUrlList); if (doc != null) { urls = thisUrlList; break; } } } final List<String> finalUrls = urls; ApplicationManager.getApplication().invokeLater(() -> { if (ContainerUtil.isEmpty(finalUrls)) { if (element != null && provider instanceof ExternalDocumentationProvider) { ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider)provider; if (externalDocumentationProvider.canPromptToConfigureDocumentation(element)) { externalDocumentationProvider.promptToConfigureDocumentation(element); } } } else if (finalUrls.size() == 1) { BrowserUtil.browse(finalUrls.get(0)); } else { JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Choose external documentation root", ArrayUtil.toStringArray(finalUrls)) { @Override public PopupStep onChosen(final String selectedValue, final boolean finalChoice) { BrowserUtil.browse(selectedValue); return FINAL_CHOICE; } }).showInBestPositionFor(DataManager.getInstance().getDataContext(contextComponent)); } }, ModalityState.NON_MODAL); }); }
Example #19
Source File: DocumentationTest.java From intellij-swagger with MIT License | 4 votes |
protected void testQuickDocumentation(final String fileName, final String expectedDocumentation) { final PsiFile psiFile = myFixture.configureByFile(filesPath + fileName); final PsiElement originalElement = psiFile.findElementAt(myFixture.getEditor().getCaretModel().getOffset()).getParent(); final PsiElement targetElement = originalElement.getReferences()[0].resolve(); final DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(targetElement); final String quickNavigateInfo = documentationProvider.getQuickNavigateInfo(targetElement, originalElement); assertEquals(expectedDocumentation, quickNavigateInfo); }