Search in sources :

Example 11 with GutterIconRenderer

use of com.intellij.openapi.editor.markup.GutterIconRenderer in project intellij-community by JetBrains.

the class LineMarkersPass method queryLineMarkersForInjected.

private static void queryLineMarkersForInjected(@NotNull PsiElement element, @NotNull final PsiFile containingFile, @NotNull Set<PsiFile> visitedInjectedFiles, @NotNull final PairConsumer<PsiElement, LineMarkerInfo> consumer) {
    if (containingFile.getViewProvider() instanceof InjectedFileViewProvider)
        return;
    final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(containingFile.getProject());
    InjectedLanguageUtil.enumerate(element, containingFile, false, (injectedPsi, places) -> {
        // there may be several concatenated literals making the one injected file
        if (!visitedInjectedFiles.add(injectedPsi))
            return;
        final Project project = injectedPsi.getProject();
        Document document = PsiDocumentManager.getInstance(project).getCachedDocument(injectedPsi);
        if (!(document instanceof DocumentWindow))
            return;
        List<PsiElement> injElements = CollectHighlightsUtil.getElementsInRange(injectedPsi, 0, injectedPsi.getTextLength());
        final List<LineMarkerProvider> providers = getMarkerProviders(injectedPsi.getLanguage(), project);
        queryProviders(injElements, injectedPsi, providers, (injectedElement, injectedMarker) -> {
            GutterIconRenderer gutterRenderer = injectedMarker.createGutterRenderer();
            TextRange injectedRange = new TextRange(injectedMarker.startOffset, injectedMarker.endOffset);
            List<TextRange> editables = manager.intersectWithAllEditableFragments(injectedPsi, injectedRange);
            for (TextRange editable : editables) {
                TextRange hostRange = manager.injectedToHost(injectedPsi, editable);
                Icon icon = gutterRenderer == null ? null : gutterRenderer.getIcon();
                GutterIconNavigationHandler<PsiElement> navigationHandler = injectedMarker.getNavigationHandler();
                LineMarkerInfo<PsiElement> converted = new LineMarkerInfo<>(injectedElement, hostRange, icon, injectedMarker.updatePass, e -> injectedMarker.getLineMarkerTooltip(), navigationHandler, GutterIconRenderer.Alignment.RIGHT);
                consumer.consume(injectedElement, converted);
            }
        });
    });
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) DocumentWindow(com.intellij.injected.editor.DocumentWindow) InjectedFileViewProvider(com.intellij.psi.impl.source.tree.injected.InjectedFileViewProvider) Project(com.intellij.openapi.project.Project) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) PsiElement(com.intellij.psi.PsiElement)

Aggregations

GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)11 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)3 AnAction (com.intellij.openapi.actionSystem.AnAction)3 PsiElement (com.intellij.psi.PsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 Pass (com.intellij.codeHighlighting.Pass)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 AllIcons (com.intellij.icons.AllIcons)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 Document (com.intellij.openapi.editor.Document)2 Editor (com.intellij.openapi.editor.Editor)2 PsiFile (com.intellij.psi.PsiFile)2 ColorIcon (com.intellij.util.ui.ColorIcon)2 ArrayList (java.util.ArrayList)2 javax.swing (javax.swing)2 Nullable (org.jetbrains.annotations.Nullable)2 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)1 LineMarkerProviderDescriptor (com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor)1