Search in sources :

Example 21 with DocumentationProvider

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

the class FlexCssPropertyDescriptor method getDocumentationString.

@Nullable
public String getDocumentationString(@Nullable PsiElement context) {
    if (context == null)
        return null;
    PsiElement[] declarations = getDeclarations(context);
    List<DocumentationElement> docElements = new ArrayList<>();
    for (PsiElement declaration : declarations) {
        PsiFile file = declaration.getContainingFile();
        if (file != null) {
            DocumentationProvider provider = DocumentationManager.getProviderFromElement(declaration);
            String docForDeclaration = provider.generateDoc(declaration, declaration);
            if (docForDeclaration != null) {
                JSClass jsClass = PsiTreeUtil.getParentOfType(declaration, JSClass.class);
                String header = jsClass != null ? jsClass.getQualifiedName() : file.getName();
                docElements.add(new DocumentationElement(header, docForDeclaration));
            }
        }
    }
    Collections.sort(docElements, (e1, e2) -> Comparing.compare(e1.header, e2.header));
    StringBuilder builder = new StringBuilder();
    for (int i = 0, n = docElements.size(); i < n; i++) {
        DocumentationElement docElement = docElements.get(i);
        builder.append("<b>").append(docElement.header).append("</b>").append("<br>\n");
        builder.append(docElement.documentation);
        if (i != n - 1) {
            builder.append("<br><br>\n\n");
        }
    }
    return builder.toString();
}
Also used : PsiFile(com.intellij.psi.PsiFile) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with DocumentationProvider

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

the class AndroidDomTestCase method doTestExternalDoc.

protected final void doTestExternalDoc(String expectedPart) {
    PsiElement originalElement = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
    PsiElement docTargetElement = DocumentationManager.getInstance(getProject()).findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
    DocumentationProvider provider = DocumentationManager.getProviderFromElement(docTargetElement);
    List<String> urls = provider.getUrlFor(docTargetElement, originalElement);
    String doc = ((ExternalDocumentationProvider) provider).fetchExternalDocumentation(myFixture.getProject(), docTargetElement, urls);
    assertNotNull(doc);
    assertTrue("Can't find " + expectedPart + " in " + doc, doc.contains(expectedPart));
}
Also used : ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) PsiElement(com.intellij.psi.PsiElement) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 23 with DocumentationProvider

use of com.intellij.lang.documentation.DocumentationProvider 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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LookupEx(com.intellij.codeInsight.lookup.LookupEx) LookupElement(com.intellij.codeInsight.lookup.LookupElement) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider)

Example 24 with DocumentationProvider

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

the class FlexDocumentationTest method testFlexCssSelector.

@JSTestOptions({ JSTestOption.WithCssSupportLoader, JSTestOption.WithFlexFacet })
public void testFlexCssSelector() throws Exception {
    DocumentationProvider cssDocumentationProvider = new CssDocumentationProvider();
    PsiElement docElement = getDocElementForLookupItem(cssDocumentationProvider, getTestName(false) + ".css");
    assertInstanceOf(docElement, JSClass.class);
}
Also used : PsiElement(com.intellij.psi.PsiElement) CssDocumentationProvider(com.intellij.psi.css.impl.util.CssDocumentationProvider) FlexDocumentationProvider(com.intellij.javascript.flex.FlexDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) JSDocumentationProvider(com.intellij.lang.javascript.documentation.JSDocumentationProvider) CssDocumentationProvider(com.intellij.psi.css.impl.util.CssDocumentationProvider) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

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