custom language: resolving psi elements (for ParameterInfoHandler) while there are syntax errors
While implementing a custom language plugin, I stumbled upon a problem with displaying a function call hints using ParameterInfoHandler
. Basically:
* it works correctly for empty function call, like method(|)
and for typed parameter, like method(a;b|)
(with pipe being a caret position)
* it breaks when typing parameter separator, method(a;|)
because in the second case, the call doesn't meet the grammar requirements (trailing separator is not allowed) and ParameterInfoHandler::findElementForParameterInfo
and findElementForUpdatingParameterInfo
provide only )
psi element parented to PsiErrorElement
. Which means I can't resolve the function call expression.
I can see that this works correctly in kotlin (e.g. method(|,foo)
displays the popup, despite invalid syntax).
Is there a way to resolve this function call and find the declaration in this case? Alternatively, does the grammar need to allow such cases (and report errors via an annotator instead)?
请先登录再写评论。
Hi,
I think that you should play with your grammar to make a tree less broken in this case.
For example, this is a Java method call with redundant comma:
The error element is inside and it seems to not break the situation.
If you use GrammarKit, consider playing with pins (see https://github.com/JetBrains/Grammar-Kit/blob/master/TUTORIAL.md).
If it doesn't help, an annotator is an alternative solution.
Wow, pins were definitely the thing that was missing. Adding one immediately fixed the issue (
PsiErrorElement
became a sibling of other call parameters/separators).Thanks a lot for the quick answer! So far I mostly avoided playing with pins/recoverWhile, but I probably need to look at it more.