Incorrect help when caret at word end

I'm developing a custom language provider and struggling with the way IJ identifies the expression at the caret. When the caret is at the beginning or in the middle of a psi-element for which help is requested everything is working well:

However, when the caret is at the end it does NOT pull up any help:

What happens internally is that com.intellij.lang.documentation.DocumentationProviderEx#generateDoc is called with the next psi-sibling (in this case the new-line) instead.

In the java language integration this does not happen, and also identifier-final carets result in the correct help popup. Is there an easy way (e.g. some psi-utility method) to achieve a similar behavior for custom languages?

So in other words my issue is not so much related to DocumentationProvider but rather to the question about how to identify the psi-element under the caret when the caret is at its end.

 

 

1 comment

PSI element under caret for use by DocumentationManager (and other clients) is determined by com.intellij.codeInsight.TargetElementUtil#findTargetElement method. Basic logic (working e.g. for Java) adjusts target offset to point at identifier-part character before caret if there's non-identifier-part character after the caret (see TargetElementUtil.adjustOffset). If this is not enough for your language, it's possible to customize TargetElementUtil's behaviour by registering TargetElementEvaluator for your language. Check the code in TargetElementUtil for details.

0

Please sign in to leave a comment.