LineMarkerProvider not working?!
Answered
I want to develop a plugin, with that one can attach a marker to the current line via the context menu in the editor.For that I have created a new class that implements the LineMarkerInfo interface.
package de.vag.intellij.marker
import com.intellij.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.LineMarkerProvider
import com.intellij.psi.PsiElement
import com.intellij.openapi.editor.markup.GutterIconRenderer
import com.intellij.openapi.util.IconLoader
class MyMarkerProvider() : LineMarkerProvider {
override fun getLineMarkerInfo(element: PsiElement): LineMarkerInfo<*>? {
val icon = IconLoader.getIcon("/META-INF/logo.svg")
return LineMarkerInfo(element, element.textRange, icon, null,null, GutterIconRenderer.Alignment.LEFT)
}
}
Then I Have registered this new class in the Plugin.xml (for Java).
<extensions defaultExtensionNs="com.intellij">
<codeInsight.lineMarkerProvider
language="JAVA"
implementationClass="de.vag.intellij.marker.MyMarkerProvider"/>
</extensions>
I call the getLineMarkerInfo() in the action listener of the menu option:
package de.vag.intellij
import de.vag.intellij.marker.MyMarkerProvider
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.LangDataKeys
import com.intellij.psi.PsiElement
class MarkerAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val editor = e.getRequiredData(CommonDataKeys.EDITOR)
val psiElement: PsiElement = e.getData(LangDataKeys.PSI_FILE)!!
MyMarkerProvider().getLineMarkerInfo(psiElement)
}
}
The method gets called but nothing happens and no error occurs. So what am I missing?
Please sign in to leave a comment.
LineMarkerProvider API is not supposed to work like this, please see https://plugins.jetbrains.com/docs/intellij/line-marker-provider.html
Your custom implementation of LineMarkerProvider can use any data (e.g. from "highlight current line" as context action) stored somewhere to then render such additional higlights.