How to trigger method code completion even i type classname
Answered
Because in my plugin, request
Is a build-in variable and it should not call new request()
. So i make the constructor private.
And it has a method for example test()
.
When I type request and press code completion shortcut, it the popup, it item result item does not appear test()
.
Maybe it cause by that I need write request request = new request();
and then method code completion will appear test()
.
But I want the code completion result show test()
item.
How should I do?
code of request
public class request {
private request(){}
public void test(){
}
}
Please sign in to leave a comment.
Hi,
I'm sorry, but I don't understand your question. What is the language context? Do you write
request.
in Java or in another language? If in Java, then it is expected behavior and if you want to complete members of this class, you should implement custom code completion for this:https://plugins.jetbrains.com/docs/intellij/code-completion.html
Finally I use CompletionContributor to solve this problem. You can see the following example.
But it have a bug. I have include the jar of HttpRequest. When I click the words
form
, it show the property but not the method.There are many form method in the HttpRequest class.
Because request is a build-in param, if I use request r = new request(), it will show correct result. So if there is any idea ?
Source Code:Upload id: 2024_08_26_23xsihqBzsVN5CPsjXW1zF (file: RequestCompletionContributor.java)
Jar: Upload id: 2024_08_26_QPDjAPH1etu8j8H8FRSZBm (files: hutool-all-5.8.12.jar, fast-request-script-2024.1.jar)
config in plugin.xml
Please add jar to project like following
In groovy editor please write
request.form()
and holdCmd
, the refrence show the property of HttpRequest but not the methodRegarding completion, you shouldn't use such a pattern:
I suggest using a pattern that will match a Groovy variable with the “request” name. I suggest checking intellij-community sources for example patterns. Anyway, it is not related to the resolving, just a general hint.
Regarding resolving, I asked my colleague to help.
Hi, king s!
Please, note, that you are trying to introduce dynamic property via class declaration and therefore some IDE features might not work properly. In particular, you implemented `RequestCompletionContributor`, which added non-static members to lookup items. In case of resolving, there is an inevitable filter for class access which filters all non-static members. I would recommend you to look at these EP:
org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor
- creates dynamic properties andorg.jetbrains.plugins.groovy.lang.typing.GrTypeCalculator
- tries to resolve by a custom type.There was a bit similar problem to which you can refer to make your own implementation: https://intellij-support.jetbrains.com/hc/en-us/community/posts/20305750834194-GrReferenceTypeEnhancer-adds-autocompletion-but-marks-field-as-unknown