Need help understanding the stub API

Hi everyone,

Please forgive my ignorance, but I need help understanding how to implement a stub index in order to get "Go To Symbol" working for my custom language plugin. I tried looking at the La Clojure source, but there's a lot going on in there, and I was hoping someone could explain how it would work for a hypothetical, super-simple language, consisting of nothing but PSI elements called "named expressions".

For such a language, I imagine I'd have my PSI element class:

NamedExpression<T extends StubElement> extends StubBasedPsiElementBase<T>

And then I'd make a stub index class:

NamedExpressionIndex extends StringStubIndexExtension<NamedExpression>

And then I'd register the stub index in the plugin.xml:

<stubIndex implementation="com.bitbakery.fake.NamedExpressionIndex"/>



And then presumably I could implement a ChooseByNameContributor that would use my NamedExpressionIndex stub index. But... beyond this I don't see what I'm missing, because I don't know what all the moving parts are and what they're doing, and why. Again, thanks for your help and your patience. I originally worked on my language plugin when IntelliJ was at version 6, so my understanding of the current API has some big gaps.

Thanks,
Kurt Christensen
3 comments
Comment actions Permalink


Your IStubElementType should have indexStub method implemented, like
following:

final String name = stub.getName();
     if (name != null) {
       sink.occurrence(JavaFieldNameIndex.KEY, name);
     }

And you also need ChooseByNameContributor implementation bound to
com.intellij.gotoSymbolContributor extension point (for sample please
look into IntelliJ IDEA Community Edition sources)

On 21.07.2010 21:27, Kurt Christenen wrote:

Hi everyone,

>

Please forgive my ignorance, but I need help understanding how to implement a stub index in order to get "Go To Symbol" working for my custom language plugin. I tried looking at the La Clojure source, but there's a lot going on in there, and I was hoping someone could explain how it would work for a hypothetical, super-simple language, consisting of nothing but PSI elements called "named expressions".

>

For such a language, I imagine I'd have my PSI element class:

>

NamedExpression<T extends StubElement>  extends StubBasedPsiElementBase<T>

>

And then I'd make a stub index class:

>

NamedExpressionIndex extends StringStubIndexExtension<NamedExpression>

>

And then I'd register the stub index in the plugin.xml:

>

<stubIndex implementation="com.bitbakery.fake.NamedExpressionIndex"/>

>
>

And then presumably I could implement a ChooseByNameContributor that would use my NamedExpressionIndex stub index. But... beyond this I don't see what I'm missing, because I don't know what all the moving parts are and what they're doing, and why. Again, thanks for your help and your patience. I originally worked on my language plugin when IntelliJ was at version 6, so my understanding of the current API has some big gaps.

>

Thanks,
Kurt Christensen

>

---
Original message URL: http://devnet.jetbrains.net/message/5268174#5268174



--
Best regards,
   Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

So let's assume that I've already created a class which implements ChooseByNameContributor and that I've registered it in the plugin.xml. Continuing with my example, which classes and/or interfaces would my "NamedExpression" PSI element class have to extend or implement? And if I had this and my StubIndex, would that be sufficient, or are there other classes which I would have to create? If so, which classes or interfaces would they have to extend or implement?

If these questions aren't focused enough, could you guide me to a place in the source code which explains the stub mechanism? Again, the La Clojure plugin is a bit complicated for learning this. Do you have another, simpler example?

Thanks,
Kurt Christensen

0
Comment actions Permalink

Look for com.intellij.psi.impl.java.stubs.JavaFieldStubElementType / com.intellij.psi.impl.source.PsiFieldImpl / com.intellij.ide.util.gotoByName.DefaultSymbolNavigationContributor in IDEA community sources

0

Please sign in to leave a comment.