Skip to content

Commit

Permalink
Add a NavigationGutterIconBuilder.setTargetRenderer compatibility API.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhdunn committed Nov 21, 2024
1 parent bcbf9ca commit f2f9d94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (C) 2024 Reece H. Dunn. SPDX-License-Identifier: Apache-2.0
package com.intellij.compat.codeInsight.navigation.impl

import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
import com.intellij.ide.util.PsiElementListCellRenderer
import com.intellij.openapi.util.Computable
import com.intellij.openapi.util.NlsSafe
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.Nls
Expand All @@ -18,3 +20,7 @@ abstract class PsiTargetPresentationRenderer<T : PsiElement> : PsiElementListCel

abstract override fun getIcon(element: PsiElement): Icon?
}

fun <T : PsiElement> NavigationGutterIconBuilder<T>.setTargetRenderer(
renderer: Computable<PsiTargetPresentationRenderer<*>>
): NavigationGutterIconBuilder<T> = setCellRenderer { renderer.compute() }
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package uk.co.reecedunn.intellij.plugin.marklogic.rewriter.navigation
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProvider
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
import com.intellij.compat.codeInsight.navigation.impl.*
import com.intellij.psi.PsiElement
import com.intellij.psi.impl.source.tree.LeafElement
import uk.co.reecedunn.intellij.plugin.marklogic.resources.MarkLogicIcons
Expand All @@ -23,7 +24,7 @@ class RewriterLineMarkerProvider : LineMarkerProvider {
return NavigationGutterIconBuilder.create(MarkLogicIcons.Markers.Endpoint)
.setTargets(endpoints.map { it.endpoint })
.setTooltipText(PluginApiBundle.message("line-marker.rewriter-endpoint.tooltip-text"))
.setTargetRenderer { RewriterListCellRenderer(endpoints) }
.setTargetRenderer { RewriterListCellRenderer(endpoints) as PsiTargetPresentationRenderer<PsiElement> }
.createLineMarkerInfo(element)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package uk.co.reecedunn.intellij.plugin.marklogic.search.options.navigation
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProvider
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
import com.intellij.compat.codeInsight.navigation.impl.*
import com.intellij.psi.PsiElement
import uk.co.reecedunn.intellij.plugin.marklogic.search.options.SearchOptions
import uk.co.reecedunn.intellij.plugin.marklogic.search.options.reference.CustomConstraintFunctionReference
Expand All @@ -26,7 +27,7 @@ class CustomConstraintLineMarkerProvider : LineMarkerProvider {
return NavigationGutterIconBuilder.create(CustomConstraintFunctionReference.getIcon(facets[0].referenceType))
.setTargets(facets.map { it.element })
.setTooltipText(PluginApiBundle.message("line-marker.search-constraint.tooltip-text"))
.setTargetRenderer { CustomConstraintListCellRenderer(facets) }
.setTargetRenderer { CustomConstraintListCellRenderer(facets) as PsiTargetPresentationRenderer<PsiElement> }
.createLineMarkerInfo(element)
}
}

0 comments on commit f2f9d94

Please sign in to comment.