Language API: Completion without PsiReference? (completion for non-references)

I know PsiReference.getVariants() is supposed to be called when
completion occurs. However, what if I want to provide completion for a
non-reference? How do I do this?

5 comments
Comment actions Permalink

Hello Keith,

KL> I know PsiReference.getVariants() is supposed to be called when
KL> completion occurs. However, what if I want to provide completion for
KL> a non-reference? How do I do this?

Unfortunately this is not currently possible. For non-references, only the
standard word completion can be used in custom language files.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Dmitry Jemerov (JetBrains) wrote:

Hello Keith,

KL> I know PsiReference.getVariants() is supposed to be called when
KL> completion occurs. However, what if I want to provide completion for
KL> a non-reference? How do I do this?

Unfortunately this is not currently possible. For non-references, only
the standard word completion can be used in custom language files.


The simple answer obviously is "make it a reference" ;) But I know this isn't possible in
all cases.

While we're talking about completion, there's something I'd like to know as well: In Java
some completions do some magic after they are done, such as completing the synchronized-
statement that moves the caret inside the parentheses:

sync| -> synchronized(|)

I know there's more than just Strings and PsiElements that can be returned from
getVariants(), but haven't figured out yet how this could work. Dmitry, maybe you can shed
some light on this... :)

Sascha

0
Comment actions Permalink

Hello Sascha,

SW> While we're talking about completion, there's something I'd like to
SW> know as well: In Java some completions do some magic after they are
SW> done, such as completing the synchronized- statement that moves the
SW> caret inside the parentheses:
SW>
SW> sync| -> synchronized(|)
SW>
SW> I know there's more than just Strings and PsiElements that can be
SW> returned from getVariants(), but haven't figured out yet how this
SW> could work. Dmitry, maybe you can shed some light on this... :)

Unfortunately none of this is currently exposed through OpenAPI, and it doesn't
work through returning some magic items from getVariants(). I've added a
request (IDEABKL-3412) to expose this functionality - you can watch it to
get notified when it appears in OpenAPI.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

Dmitry Jemerov (JetBrains) wrote:

Hello Keith,

KL> I know PsiReference.getVariants() is supposed to be called when
KL> completion occurs. However, what if I want to provide completion for
KL> a non-reference? How do I do this?

Unfortunately this is not currently possible. For non-references, only
the standard word completion can be used in custom language files.


Okay, I filed IDEA-4023 for this

0
Comment actions Permalink

Sascha Weinreuter wrote:

Dmitry Jemerov (JetBrains) wrote:

>>Hello Keith,
>>
>>KL> I know PsiReference.getVariants() is supposed to be called when
>>KL> completion occurs. However, what if I want to provide completion for
>>KL> a non-reference? How do I do this?
>>
>>Unfortunately this is not currently possible. For non-references, only
>>the standard word completion can be used in custom language files.


The simple answer obviously is "make it a reference" ;) But I know this isn't possible in
all cases.


Doesn't that make things like Find Usages and Ctrl+Click work? I don't
want that at all.

0

Please sign in to leave a comment.