Custom completion in editor

Inside of a string in the editor window, I'd like to be able to offer completions under certain circumstances, how would I go about doing this? As a practical example, I want the following to show the list of all methods that start with 'wom':

@Foo(method="wom|")

1
6 comments

Hello Hani,

Inside of a string in the editor window, I'd like to be able to offer
completions under certain circumstances, how would I go about doing
this? As a practical example, I want the following to show the list of
all methods that start with 'wom':

@Foo(method="wom|")


Others will correct me if there's a better way, but I think a ReferenceProvider
is the way to go:
1) Minimal sample that works from XML to Java methods (provided by Sascha
Weinreuter):
http://intellij.net/forums/thread.jspa?messageID=5157247&#5157247
2) You want to provide references for String literals in specific places.
Use PsiViewer to look an some example source, and build your matching
logic from that.
I guess you'll need to register your provider for PsiLiteralExpression.class,
and do additional context check inside getReferencesByElement()
3) There's no need to do any matching on prefix (IDEA will do that).
Just implement getVariants() in your PsiReference implementation.
4) If it's possible that the string literal resolve()s to multiple methods,
implement PsiPolyVariantReference (also mentioned in linked thread)
5) Consider making your references non-soft, otherwise you'll get a lot of
cluttering suggestions for built-in providers.

That should get you started. Feel free to ask when you run into problems.

Regards,
Taras

ps. How's the testing book going?


0

Some additional details missing from last post:
1) You can use com.intellij.psi.PsiReferenceBase as a base for your references
2) The Lookup* Objects that you can return from getVariants() can be produced
by com.intellij.codeInsight.lookup.LookupValueFactory


0

Wow, thanks for the prompt and incredibly helpful response!

I've implemented this in the next version of the TestNG plugin, so dependsOnMethods now autocompletes.

The book is done, just putting on finishing touches now (which evidently takes ages!)

0

Excellent - you bet me to it :) I'd been meaning to look at that for awhile now..

Re: the book - any chance of any sneak previews of whats covered? Table of contents etc?

Look forward to reading it.

0

Out of curiosity, where does the code live?

And what's the plan for Selena? Roadmap mentions "adaptation" (?) of existing plugin.

0

The code is at http://code.google.com/p/testng-idea/ and we're still hoping it'll be bundled as part of Selena.

0

Please sign in to leave a comment.