When implementing code hints for custom languages, CompletionUtilCore#DUMMY_IDENTIFIER affects the logic of the CompletionContributor where CompletionParameters recognizes the PSI structure at the cursor.
This is the bnf definition of the syntactic structure I describe below(Temporarily removed some of the definition code for the sake of the screenshot, so there are some warnings):
This is the structure in the PSI tree:
This is when the code hint shortcut is pressed, the structure recognized by parameters
in fillCompletionVariants
:
The result is that I can't write a suitable place
(the second parameter of the extend
method) for this situation.
After I set the value of com.intellij.codeInsight.completion.CompletionUtilCore#DUMMY_IDENTIFIER
to an empty string, parameter
correctly recognizes the PSI structure(PsiWhiteSpace → ENUM_BODY → POSITIVE_PROP → etc.), but with that comes various errors when completing the code prompts.
So I think setting DUMMY_IDENTIFIER
to an empty string is probably not the right solution... So how do I deal with the problem that parameters doesn't recognize the PSI structure correctly when DUMMY_IDENTIFIER
is the default value?
Please sign in to leave a comment.
Hi,
I'm sorry, but I don't understand the issue. What errors come when you set the dummy identifier to an empty string? What is your pattern? Did you try adding pin rules to the places where the error occurs? I guess that the structure is invalid after inserting dummy identifier, but maybe you can use pin to match the rule even if there is an error?
After setting
DUMMY_IDENTIFIER
to an empty string, when I enter a character that triggers a prompt, the inserted message loses the first character, for example:Typing 'abc' matches 'abcde', and when I press
tab
to insert the prompt, it becomes 'aabcde'.Yes, the PSI structure is illegal after inserting
DUMMY_IDENTIFIER
... I'll try the pin rule.Thanks!
By adding the pin rule, I managed to complete the code hint, then I realized that in some cases
DUMMY_IDENTIFIER
causes interference, and having it instead causes the PSI parsing to report an error.Combining the findings here with some previous test results, I've tried to reorganize the
DUMMY_IDENTIFIER
comments:That is, this value is only needed if the precondition of the code hint is not met without the identifier?
So, should this value actually be in the
beforeCompletion
method, dynamically determining if it should be the empty string by the current element type (context.file.findElementAt(context.startOffset)
) fetched fromcontext
parameter?I don't understand what kind of parsing error the dummy identifier causes.