getVariants() issues

1) When completion, getVariants() is called on an newley created element
with name-element "IntellijIdeaRulezzz".
If seen this before. IDEA simply inserts this text with a trailing
space at cursor position and then passes it through the parser
(which will almost ever report parsing errors).
In my case `getModel()` is passed as `IntellijIdeaRulezzz getModel()`,
so the parser obviously fails. Also, the element being used to get the
reference is now an different type (method acces --> field access).
So how should I find the correct variants? Besides this "element change"
element.getContainingFile().getVirtualFile() also returns null!
Any comments on proper dealing with those problems?
Why isn't the getVariants() called on the element directly?

2) Where can I start searching the error(s) if getVariants() is called
and returns an non-empty array, but the related popup tells
"no suggestion"?

3) How can I order the getVariants() output (other than alphabetically)?

3 comments

1) AFAIK IDEA creates a dummy PsiFile/Element (?!) with content "IntellijIDe....", that's why there's no VF

2) I had these problems too, if I remember right my ReferenceProvider wasn't called at all in this case

3) AFAIK this is hardcoded behaviour in IDEA

0

Sven Steiniger wrote:

Why isn't the getVariants() called on the element directly?

The element most often does not exist yet.

element.getContainingFile().getOriginalFile().getVirtualFile() is not null


2) Where can I start searching the error(s) if getVariants() is called
and returns an non-empty array, but the related popup tells
"no suggestion"?

Completion prefix does not match any element.

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

0

>> Why isn't the getVariants() called on the element directly?

The element most often does not exist yet.
element.getContainingFile().getOriginalFile().getVirtualFile() is not null


I understand. Maybe an extra section about this can be added to the
lang-api documentation. It should guide how to write your references
and where getVariants() should be implemented. This is not clear by the
normal docs.

>>
>> 2) Where can I start searching the error(s) if getVariants() is called
>> and returns an non-empty array, but the related popup tells
>> "no suggestion"?

Completion prefix does not match any element.


My guess :)
But as I have no knowledge about IDEA's internals, this doesn't really help.
Example. Having this code
]]>
which is parsed in to PSI tree
PSI:INCLUDE
<
INCLUDE
PSI:PATH
PSI:PATH
PSI:PATH
sub1
/
sub2
/
file
the references resolve() returns PsiFile or PsiDirectory. Having the
cursor before 'sub2' and calling rename correctly shows the name
popup. When changing the name to 'sub3', the references handleRename()
is called with 'sub3'.
That's clear. Now the problem:
In getVariants() I return an array of PsiFile/PsiDirectory with all
candidates. But on auto completion nothing is shown. I have no clue
where the problem is. I simply don't know how the prefix is computed/
compared.
(PS: I got around this problem by
1. letting getVariants() return an array
ofPsiFile.getName()/PsiDirectory.getName()
2. setting an own CompletionData where getPrefix() returns just
psielement.substring(0, i-psielement.getStartOffset()).
The original getPrefix returned 'sub1/'.
)

0

Please sign in to leave a comment.