Search in sources :

Example 11 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project android by JetBrains.

the class AndroidJavaDocWithGradleTest method checkJavadoc.

private void checkJavadoc(@NotNull String targetPath, @Nullable String expectedDoc) {
    VirtualFile f = findFile(targetPath);
    myFixture.configureFromExistingVirtualFile(f);
    PsiElement originalElement = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
    assert originalElement != null;
    final PsiElement docTargetElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
    assert docTargetElement != null;
    DocumentationProvider provider = DocumentationManager.getProviderFromElement(docTargetElement);
    assertEquals(expectedDoc, provider.generateDoc(docTargetElement, originalElement));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiElement(com.intellij.psi.PsiElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 12 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-community by JetBrains.

the class JsonBySchemaDocumentationBaseTest method assertDocumentation.

protected void assertDocumentation(@NotNull PsiElement docElement, @NotNull PsiElement context, boolean shouldHaveDoc) {
    DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(context);
    String inlineDoc = documentationProvider.generateDoc(docElement, context);
    if (shouldHaveDoc) {
        assertNotNull("inline help is null", inlineDoc);
    } else {
        assertNull("inline help is not null", inlineDoc);
    }
    if (shouldHaveDoc) {
        assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + ".html", inlineDoc);
    }
}
Also used : JsonSchemaDocumentationProvider(com.jetbrains.jsonSchema.ide.JsonSchemaDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 13 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-community by JetBrains.

the class ExternalJavaDocAction method update.

@Override
public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    DataContext dataContext = event.getDataContext();
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    PsiElement element = getElement(dataContext, editor);
    final PsiElement originalElement = getOriginalElement(CommonDataKeys.PSI_FILE.getData(dataContext), editor);
    DocumentationManager.storeOriginalElement(CommonDataKeys.PROJECT.getData(dataContext), 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);
    }
}
Also used : ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 14 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-community by JetBrains.

the class ExternalJavaDocAction method showExternalJavadoc.

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 = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        List<String> urls;
        if (StringUtil.isEmptyOrSpaces(docUrl)) {
            urls = ReadAction.compute(() -> provider.getUrlFor(element, originalElement));
        } 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);
    });
}
Also used : Project(com.intellij.openapi.project.Project) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) ExternalDocumentationHandler(com.intellij.lang.documentation.ExternalDocumentationHandler) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 15 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider in project intellij-community by JetBrains.

the class ExtensionPointDocumentationProviderTest method testExtensionPointDocumentation.

public void testExtensionPointDocumentation() {
    myFixture.configureByFiles("extensionPointDocumentation.xml", "bar/MyExtensionPoint.java");
    final PsiElement docElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile());
    DocumentationProvider provider = DocumentationManager.getProviderFromElement(docElement);
    String epDefinition = "[" + myModule.getName() + "] foo<br/>" + "<b>bar</b> (extensionPointDocumentation.xml)<br/>" + "<a href=\"psi_element://bar.MyExtensionPoint\"><code>MyExtensionPoint</code></a>";
    assertEquals(epDefinition, provider.getQuickNavigateInfo(docElement, null));
    assertEquals("<em>EP Definition</em><br/>" + epDefinition + "<br/><br/>" + "<em>EP Implementation</em>" + "<html><head>    <style type=\"text/css\">        #error {            background-color: #eeeeee;            margin-bottom: 10px;        }        p {            margin: 5px 0;        }    </style></head>" + "<body><small><b>bar</b></small><PRE>public interface <b>MyExtensionPoint</b></PRE>\n" + "   MyExtensionPoint JavaDoc.</body></html>", provider.generateDoc(docElement, null));
}
Also used : PsiElement(com.intellij.psi.PsiElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Aggregations

DocumentationProvider (com.intellij.lang.documentation.DocumentationProvider)24 PsiElement (com.intellij.psi.PsiElement)15 FlexDocumentationProvider (com.intellij.javascript.flex.FlexDocumentationProvider)3 ExternalDocumentationProvider (com.intellij.lang.documentation.ExternalDocumentationProvider)3 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)3 JSDocumentationProvider (com.intellij.lang.javascript.documentation.JSDocumentationProvider)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiFile (com.intellij.psi.PsiFile)3 CssDocumentationProvider (com.intellij.psi.css.impl.util.CssDocumentationProvider)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 DocCommentFixer (com.intellij.codeInsight.documentation.DocCommentFixer)1 LookupEx (com.intellij.codeInsight.lookup.LookupEx)1 CodeDocumentationProvider (com.intellij.lang.documentation.CodeDocumentationProvider)1 CompositeDocumentationProvider (com.intellij.lang.documentation.CompositeDocumentationProvider)1 ExternalDocumentationHandler (com.intellij.lang.documentation.ExternalDocumentationHandler)1 ModuleUtilCore.findModuleForPsiElement (com.intellij.openapi.module.ModuleUtilCore.findModuleForPsiElement)1 Project (com.intellij.openapi.project.Project)1 PopupStep (com.intellij.openapi.ui.popup.PopupStep)1