Getting Started

I'm trying to get started writing a plugin. Things that are killing me right off the bat are:

  • Having to stop/start IDEA every time I make a change

  • Don't know how to debug

  • Can't see System.out

  • Multiple IDEA instances?


I know that there was a doc that addressed mose of these issues, but I can't find it anymore and it might be out of date.

Can someone give me a few pointers?

18 comments
Comment actions Permalink


If you're writing against the Irida EAPs (and you probably should be), all you need to do is set up your project with a plugin module rather than a Java module. You'll need to configure an IDEA JDK (basically just a pointer to your idea directory, and a sandbox directory for storing your plugins and configuration) rather than a standard J2SE JDK. This will let you launch IDEA within itself, as just another run/debug configuration. Unfortunately, I'm pretty sure there's no documentation on this yet. Fortunately, it's pretty easy.

--Dave Griffith

0
Comment actions Permalink

Dave

I did what you mentioned.
(1) i installed eap 3177
(2) bring up 3177, settings->JDK & Global lib, Add IntelliJ IDEA SDK, point to my idea 4.5 install root, also create a sandbox dir under that root.
(3) new project->plugin module, set the project jdk to be the one i just added in step 2, create a single module, -->plugin module, set the root as the same on my project root.
(4) drop src of workspace into my project root
..set configuration...plugin...
(5) compile and test run fine at the first time
(6) after that, something wrong, i cannot even run the compile successfully---looks like it did not even import the basic java libs, what am i doing wrong?
thanks for help.

Chunbo

0
Comment actions Permalink

chunbo

>(1) i installed eap 3177

>
>(2) bring up 3177, settings->JDK & Global lib, Add IntelliJ IDEA SDK, point to my idea 4.5 install root, also create a sandbox dir under that root.

>

There is a bug in 3177, that makes in create incomplete IDEA SDK. I
would import all the IDEA stuff, but would only include 1 jar from the
Java SDK.
It's fixed in 3185 (but there are other problems... it's EAP)

Alain

0
Comment actions Permalink

thanks a lot

0
Comment actions Permalink

Dave,
That actually helped me understand what needs to be done. I need this to work with 4.5, so I can't use Irida. However, I installed Irida and worked backwards to understand how I can launch IDEA from IDEA in 4.5 (I had to install JDK 1.4.2_04 to get it to work).

I'm moving along OK now, but my next big hurdle is: ClassLoading.

I want my plugin to "understand" the classes users are working with. This is for WebWork (web framework like Struts). The WebWork configuration code looks for Class objects when given the class name. I can intercept those requests, but is there any way to ask IDEA for a Class representative? Given that Class is final, I doubt this is possible, but I'm sure others have had similar situations.

In the meantime, my plugin requires you to make the project and then I create my own ClassLoader that looks in the "classes" directory.

Is this the right way to go?

0
Comment actions Permalink

Maybe you should talk to James Holmes. He has a Struts plugin. Perhaps
you can use his code as a starting point.

Norris Shelton
Sun Certified Java Programmer




Pat Lightbody wrote:

>Dave,
>That actually helped me understand what needs to be done. I need this to work with 4.5, so I can't use Irida. However, I installed Irida and worked backwards to understand how I can launch IDEA from IDEA in 4.5 (I had to install JDK 1.4.2_04 to get it to work).
>
>I'm moving along OK now, but my next big hurdle is: ClassLoading.
>
>I want my plugin to "understand" the classes users are working with. This is for WebWork (web framework like Struts). The WebWork configuration code looks for Class objects when given the class name. I can intercept those requests, but is there any way to ask IDEA for a Class representative? Given that Class is final, I doubt this is possible, but I'm sure others have had similar situations.
>
>In the meantime, my plugin requires you to make the project and then I create my own ClassLoader that looks in the "classes" directory.
>
>Is this the right way to go?

>

0
Comment actions Permalink

Maybe I should start with something easier:

How the heck do I get a VirtualFile? I know the file name "com/acme/Foo.java"...

0
Comment actions Permalink

Pat,
You can use Irida to develop plugins for 4.5 (I'm doing it all the
time). So you still have the comfort of simple setup, easy debugging, etc.

Pat Lightbody wrote:

Dave,
That actually helped me understand what needs to be done. I need this to work with 4.5, so I can't use Irida. However, I installed Irida and worked backwards to understand how I can launch IDEA from IDEA in 4.5 (I had to install JDK 1.4.2_04 to get it to work).

I'm moving along OK now, but my next big hurdle is: ClassLoading.

I want my plugin to "understand" the classes users are working with. This is for WebWork (web framework like Struts). The WebWork configuration code looks for Class objects when given the class name. I can intercept those requests, but is there any way to ask IDEA for a Class representative? Given that Class is final, I doubt this is possible, but I'm sure others have had similar situations.

In the meantime, my plugin requires you to make the project and then I create my own ClassLoader that looks in the "classes" directory.

Is this the right way to go?


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

You'll have to use the PSI.

Get the plugin/openapi documentation - idea3117-dev.zip

There is javadoc for the openapi.

In my plugin I have used Psi to get information about the current javafile.

I think there is alot of plugins out there you could sneak to see how they do it.

0
Comment actions Permalink

Claus,
That is very useful code, but it doesn't help me get a handle to a VirtualFile that isn't already open. What I'm trying to do it open a file in to the text editor.

0
Comment actions Permalink

Maybe there's a simpler way, but something like this should work:

Project project = ... // current project
String name = "com/acme/Foo.java";
name = name.substring(0, name.indexOf('.').replace('/', '.');
PsiManager manager = PsiManager.getInstance(project);
PsiClass psi = manager.findClass(name, GlobalSearchScope.allScope(project));
if (psi != null) {
psi = (PsiClass) psi.getNavigationElement();
OpenFileDescriptor file = new
OpenFileDescriptor(psi.getContainingFile().getVirtualFile(), offset);
FileEditorManager.getInstance(project).openTextEditor(file, true);
WindowManager.getInstance().suggestParentWindow(project).toFront();
}


Pat Lightbody wrote:

Claus,
That is very useful code, but it doesn't help me get a handle to a VirtualFile that isn't already open. What I'm trying to do it open a file in to the text editor.


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Martin,
That works great, thanks!

So what about opening a file that isn't a class? My next challenge is to open up a JSP file. I know the name and relative location, but I don't necessararily know which module it is in. Speaking of which, once I have a Project instance, how do I get a handle on the various modules, content roots, etc, etc.

Patrick

PS: I am planning to document all this in to an FAQ when I get further along.

0
Comment actions Permalink

Hurm. I was just about to post the same snippet from the MetricsReloaded project, only to find that it no longer compiles under 3185. The OpenFileDescriptor constructor now requires a Project as it's first argument. Since pretty much any plugin that has "goto" functionality uses that code sequence, it means they will all be broken against 3185. That kinda sucks.

--Dave Griffith

0
Comment actions Permalink

Thanks for the tip, didn't notice it yet.

Dave Griffith wrote:

Hurm. I was just about to post the same snippet from the MetricsReloaded project, only to find that it no longer compiles under 3185. The OpenFileDescriptor constructor now requires a Project as it's first argument. Since pretty much any plugin that has "goto" functionality uses that code sequence, it means they will all be broken against 3185. That kinda sucks.

--Dave Griffith


--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Hurm. I was just about to post the same snippet from the
MetricsReloaded project, only to find that it no longer compiles under
3185. The OpenFileDescriptor constructor now requires a Project as
it's first argument. Since pretty much any plugin that has "goto"
functionality uses that code sequence, it means they will all be
broken against 3185. That kinda sucks.

--Dave Griffith


Things going to be simpler. PsiClass happens to implement newly introduced
Navigatable interface. Just call its navigate method to open text editor
when needed. OpenFileDescriptor is kinda deprecated from now.

0
Comment actions Permalink

This is great stuff -- but I still don't understand how basic file interaction works. Where did you guys learn this information? The JavaDocs are pretty limited and I haven't seen any other documentation.

I'm really interested in getting a high level description of the relationship between Project and modules, as well as the relationship between VirtualFile and PSI*.

Also, I'm still looking for information on opening a single file that is not a Java class.

0
Comment actions Permalink

I'm really interested in getting a high level description of the relationship between Project and modules, as well as the relationship between VirtualFile and PSI*.


That's the reason for plugin development being such a challenge. :)
There's a lot of guessing, experimenting, debugging, sneaking at other
plugins' sources, etc. And sometimes you simply need some luck to
struggle over a particular solution. I recently reworked a vital part of
JBoss Integration plugin just because I moved an API call to some other
place by mistake, recognizing that it greatly improves its runtime
behaviour.

--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com

0
Comment actions Permalink

Yeah I am with you Patrick.

The IDEA guys haven't made it easy for us to write plugins to their absolute cool editor. Kinda disapoinsted that the java api documentation is absent. Don't they internally use javadocs for their own code?

Espeically all that Project, PSI, VirtualFile etc. are less documented and hard to find out how it works from time to time.

Sadly alot of their UI components are not easy to reuse and modify/tweak. I needed a list just like "recent files, ctrl+e". I had to resort to use some code from another plugin that he had manually created his own ui component that looked like this one.

/Claus

0

Please sign in to leave a comment.