Converting VSCode extension to Intellij plugin questions

Viewed 115

I've just written my first extension for Visual Studio Code (https://marketplace.visualstudio.com/items?itemName=kshetline.ligatures-limited). That's working well, and now I'm trying to create a similar plug-in for Intellij IDEA.

NOTHING is going smoothly, or working much like any of the examples I've found.

Perhaps I'm trying to learn too many new things at once: I don't know much about Gradle, IDEA's extension API, or Kotlin (I do at least know Java well).

What I'm stuck on now is the basics of getting events or notifications from IDEA which at least roughly correspond to these VSCode extension callbacks:

workspace.onDidOpenTextDocument
workspace.onDidCloseTextDocument
window.onDidChangeVisibleTextEditors
window.onDidChangeTextEditorSelection
workspace.onDidChangeTextDocument
workspace.onDidChangeConfiguration

Basically I need to know:

  • Which documents/editors are currently open at the start of opening a project
  • When documents/editors are opened and closed after that
  • When the current cursor position or text selection changes in any open editors
  • When text is modified in any of the open editors
  • When the configuration of the plugin is modified

Here's what little I have of a plugin.xml file now:

<idea-plugin>
  <id>com.shetline.ligatures-limited</id>
  <name>Ligatures Limited</name>
  <vendor email="kerry@shetline.com" url="http://github.com/kshetline/ligatures-limited-idea">Kerry Shetline</vendor>

  <description><![CDATA[
    Code ligatures <i>only where you want them</i>, not where you don't
    ]]></description>

  <depends>com.intellij.modules.platform</depends>

  <applicationListeners>
    <listener class="com.shetline.lligatures.LigaturesLimited" topic="com.intellij.ide.AppLifecycleListener"/>
  </applicationListeners>

  <extensions defaultExtensionNs="com.intellij">
    <applicationService serviceImplementation="com.shetline.lligatures.LigaturesLimited"/>
  </extensions>

  <actions>
  </actions>
</idea-plugin>

The ONE event I've managed to capture is when the application starts up:

package com.shetline.lligatures

import com.intellij.ide.AppLifecycleListener

class LigaturesLimited : AppLifecycleListener {
  override fun appFrameCreated(commandLineArgs: MutableList<String>) {
    println("*** appFrameCreated")
  }
}

I can understand from sample code I've seen how I might, for example, attach an action to a document, and then as soon as a user triggered that action, learn about the associated document and editor... but I don't want to have to wait for something like that. I need to be immediately aware of the fact that an editor is open and looking at a document as soon as that happens.

I've tried looking at the source for Rainbow Brackets, because I'd have thought there'd be a fair amount of overlap between what that extension does and what I'm trying to do -- which is basically apply contextual formatting to the code the user is editing. But I'm afraid I follow very little about how Rainbow Brackets manages to do what it does.

0 Answers
Related