Handle Error in an IntelliJ plugin using IntelliJ Platform plugin SDK

Answered

I'm currently working on an IntelliJ plugin using the IntelliJ Platform plugin SDK. I wanted to update the content of a pane each time an error is detected by the IDE.

I have currently put in place a custom ToolWindowFactory which create a ToolWindowContent with my pane.

class MyWindowTools : ToolWindowFactory {

    private var imageLabel = JLabel()
    private var panel = JPanel()

    override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
        // Set up the panel
        panel.add(imageLabel)
        toolWindow.contentManager.addContent(toolWindow.contentManager.factory.createContent(panel, "", false))

        ...
    }
}

From what I could see, it would be possible to use an PsiTreeChangeListener to detect once a PsiErrorElement is added/updated to the PsiTree. But that seems a bit abstract to me at the moment and I don't see how to proceed.

Otherwise another solution could be to retrieve the content of the IntelliJ Problems tab. But I didn't see anything related to that in the provided documentation.

What is the appropriate way to handle error ? And how can I proceed ?

3
4 comments

There is no one who can help me ?

0

What is your use case, why duplicate existing functionality from Problems toolwindow?

0

Hi Yann,

I just want to build a fun plugin that displays a pane of an animated bird that I drew. I want this bird to react to written code. For example, the bird may make a funny face if an error has occurred in the file I am currently working on.

That's why I didn't want to duplicate anythings, just get the result of this toolWindow.

2

The Problems View Tab does not expose in any its information. It seems the only way would be to replicate/reimplement the functionality in your code, see com.intellij.analysis.problemsView.toolWindow.HighlightingWatcher and related code.

0

Please sign in to leave a comment.