CustomLanguageHint - Parameter hint
Hello,
I'm building a custom language plugin and I've run in kind of a brick wall of Parameter hints (ctrl + p) and apart from that it has to be done via ParameterInfoHandler I don't know what next as that part is blank in tutorial page.
Is there any other material that might give a simple example of how to use it? The only method that is triggered in debugger is findElementForParameterInfo and I've found a ParameterInfoUtils:
PsiReferenceParameterList referenceParameterList = ParameterInfoUtils.findParentOfType(
context.getFile(), context.getOffset(), PsiReferenceParameterList.class
);
Which unfortunately always returns null... can anybody please point me into the right direction of which methods are important, what they should return (an Object is a little bit imprecise) or how to use that utils? At least a simple example that would serve a static paramater for any method would be nice.
I'd really appreciate it and wish you a nice day, David.
Please sign in to leave a comment.
Hello,
It's relatively simple.
findElementForParameterInfo() and findElementForUpdatingParameterInfo() should return owner element of parameters. Usually something like a call expression.
showParameterInfo() should show the hints UI and can be implemented as a simple call to context.showHint().
updateUI() should set UI state by calling context.setupUIComponentPresentation() method.
In ParameterInfoUtils.getCurrentParameterIndex() is useful to find index of current parameter under cursor.
You can check my implementation for a custom language:
https://github.com/casteng/i-pascal/blob/master/plugin/src/editor/PascalParameterInfoHandler.java
Home this helps.
Yes, It helped me to understand it, thank you...today I've finally gave it another try and got it working.
Although I must admit it took me a couple of hours for a dumb reason... haven't realized that I have to implement both create and update context returning the PsiElement to get it shown at first... was trying to get the create context working first with no idea, why nothing is visible and not realizing that hint's update is not user triggered action, but a visual update... :)
But if may I ask for the last detail, for some yet unknown reason to me, those hints are rendered in a column one under another instead of a single row, don't you have any idea why that happened?
This is an example on which I'm trying it... might it be because the handler is typed as ParameterInfoHandler<GmlFunction, String> so it requires an actual PsiElement which will contain all parameters? I'll try it probably tomorrow, but not sure if that might be the cause.
In your example "test" and "asd" should be rendered under each other. It's as intended as the possibility to add multiple items is provided to support overloaded methods. Those hints are rendered this way.