Custom run/debug config
Hello all,
I am looking to add my own run/debug configuration type and associated configuration to the "Run/Debug Configurations" dialog. Can someone point me to some documentation on how to do this or to some example plugin(s) to look at?
Thanks,
Teemu
Please sign in to leave a comment.
Well, can't find any documents on this. And all the code I find is nicely with zero comments.
I have been looking at the JUnit and TestNG plugins in the IntelliJ Common Edition sources as potential examples. Mostly TestNG.
There seems to be something called "configurationType" in the plugin.xml that looks a bit like what I am looking for. I then created my own class that implements ConfigurationType and use that to provide a ConfigurationFactory. This factory then returns an instance of RuntimeConfiguration that I created. The RuntimeConfiguration implementation extends ModuleBasedConfiguration<JavaRunConfigurationModule> which is what I copied from the TestNG plugin (the TestNGConfiguration.java file).
The TestNG version of RuntimeConfiguration also implements CommonJavaRunConfigurationParameters and RefactoringListenerProvider but I left those out as I have no idea what they are used for or what they should return. Of course, I have no idea about the rest of the code either as it is just guesswork with copy-pasteing everything..
So, finally I got my run type listed in the Run/Debug configuration dialog. Clicking on it does not work as the IDE hangs for a while and leaves the previous type dialog visible. It seems to throw this exception: java.lang.IllegalArgumentException: Argument 1 for @NotNull parameter of com/intellij/openapi/util/Disposer.register must not be null at com.intellij.openapi.util.Disposer.register(Disposer.java)
There are also a bunch of stuff in the plugin.xml that seems it might be relevant. Definitions such as "configurationProducer", "errorHandler", "deadCode", "psi.referenceContributor", etc. No idea what these are. Are they documented somewhere?
Anyway, there must be some magic trick to figuring all this out. How else would everyone have written their plugins? Anyone care to share that trick?
Thanks,
Teemu
You implement an exetnsion point so that the platform knows about you.
Here are 3 you should look at:
<configurationType id="Lua" implementation="com.sylvanaar.idea.Lua.run.LuaConfigurationType"/>
<configurationProducer id="Lua" implementation="com.sylvanaar.idea.Lua.run.LuaRunConfigurationProducer"/>
<programRunner implementation="com.sylvanaar.idea.Lua.run.LuaRunner"/>
They register a "Type" of configuration, create instances of it, and then run those instances.
Here are my Lua run configurations. I borrowed code where I could and just worked through the rest myself.
https://bitbucket.org/sylvanaar2/lua-for-idea/src/e3fa28b0b04a2da6816b019464340a10aa7b24ff/src/run?at=idea12
There most of the code.
Thanks. These look very helpful. Should help me quite a bit with implementing the missing pieces..
Hi
Do you have any more insights of how to do it? I am thinking of developing a plugin with a custom config myself and any information would be welcome...
Thanks in advance,
Victor
Hi,
Not many useful tips unfortunately. I got the dialog to show after some debugging, and managed to get it to save the configurations and correctly load them. For this, I found it most useful to look into the workspace.xml file as this is where the configurations are stored and where they get loaded. Helps a lot in debugging if something actually got saved or not. You copy the user settings from your dialog in your editor component in the resetEditorFrom and applyEditorTo methods. This goes into the configuration objects, which have their own readExternal and writeExternal methods to store them to the workspace.xml file. Many of the IntelliJ plugins actually use the older, deprecated version of their storage API. I think I went looking into the Maven plugin and found an example of the newer one, which involves just using XmlSerializer.serialize and XmlSerializer.deserialize calls and was quite simple.
So I finally got the configuration editor working, although it still bugs in some ways for the class selectors as I have complained in some other thread. After this you would still need to implement something to get the whole thing actually running. That is, when the created configuration is selected and the user presses the green arrow for running it.. There is something in the configuration object to create a RunProfileState that probably has something to do with this. For example, you can create one extending "JavaCommandLineState" which is what I used. played around with it some time and I think I got it to the point where some of my code was executed. But to properly run the stuff, you need to be able to fork a new VM, attach to that, get it to execute your stuff, etc. etc.
In the end, I got tired of all with the non-existing documents and headaches, and just create a simple separate menu where I just show the same dialog I was going to use for the run/debug configuration, and from this configuration I create the code for a main method the user can dump in their own Main class. This is mostly pointless as it is no longer possible to modify or easily to select between the different previous configurations.
If you do create a plugin and go with creating all the run configurations, I would be interested to hear how it went and see any nicely documented code for it.. :)
Good luck,
Teemu