EditorTextField and Kotlin code fragment

Answered

Hi, I am coding an Intellij plugin and have a TextEditorField object. It can show the Kotlin code fragment.

This texteditorfield is a kotlin function reference and if you hold "Ctrl" + click the "log_flyt_start", it will popup a list and finally jump to file that you selected one of these functions. (see attached figure)

I want to change this action to get function parameters (psiElement) instead of opening the file. 

I have done some investigation, it is from SearchTextField. I dont know to get SearchTextfield from TextEditorField and get PsiElement/PsiReference finally. 

5 comments
Comment actions Permalink

Please clarify, what is TextEditorField? What is the FQN?

What does "get function parameters (psiElement)" mean? Please show a sample code and expected result.

0
Comment actions Permalink

Hi, Thanks for the reply!

Sorry, my spelling mistake, it is EditorTextField, not TextEditorField. 

We have a kotlin code fragment as an input area in an editor plugin.  From the screenshot in the above message, you will see it is near JLabel "Implementation". Following is the core code that can recognize user input kotlin code (F.eks: package name + kotlin function name) and Intellij can check its reference object exists or not.

PsiFile psiFile1 = PsiManager.getInstance(p).findFile(virturalFile);
TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION,kotlinCode);
KtBlockCodeFragment codeFragment = new KtBlockCodeFragment(p, "fragment.kt",kotlinCode, textWithImports.getImports(), psiFile1);
Document doc = PsiDocumentManager.getInstance(p).getDocument(codeFragment);
EditorTextField ktEditorField = new EditorTextField(doc, p, FileTypeManager.getInstance().getStdFileType("kt"), false, false);

FQN is the shortname for the full qualified name, for the function in the kotlin, it is the package name plus function name.

As an example from the screenshot, there are two "log_flyt_start" functions (one function with paramter Integer, another function with parameter String) in the log_flyt_startKt.class , after User input "packagename.log_flyt_start()" , then user hold "Ctrl" + click the "log_flyt_start", the Intellij can popup to show functions list with this name (See screenshot popup list).  User will select/click one function of them, and then Intellij will open the selected file and jump the cursor to the function postion. 

The result that I expect is that User will click one function of them, and then I can get this function information (like its parameters and return type) and fill these values in a table, instead of Intellij opening the file. Basically, I want to find this "User Click action" on the selected function and rewrite it.

With help of analysing "SearchEveryWhere" UI and SymbolSearchEverywhereContributor , I guess I need to get "KtUltraLightMethod" based on the Intellij help. This method has Parameters (KtUltraLightParameter) and Returntype (PsiClassReferenceType) for the kotlin function. But not quite sure.

 

 

 

 

0
Comment actions Permalink

Sorry for delay. CTRL=Click is default behavior for all editors and will always provide navigation to declaration. I suggest to introduce a different UI or separate action to have different behavior.

0
Comment actions Permalink

Hi, Happy new year!

Back to the question, I have tried other ways, the only possible solution for me reuse the "SymbolSearchEverywhereContributor" and overwrite the processSelectedItem method. This contributor analyses the kotlin syntax for me. However, it does not provide the code auto-completion function, only can search for the file/Class/Symbol name without package name. 

Is it possible to overwrite "Mousebinding" action for CTRL=Click, like KeyBinding? If not, what kind of UI or separate action do you suggest? I need a bit more clue. For these UI or separate action, hopes Intellij can provide something, like "KtUltraLightMethod" for developer. If not, I do not know how to convert a Kotlin file text to "KtLightMethodImpl". 

Thanks again!

 

0
Comment actions Permalink

SymbolSearchEverywhereContributor is completely unrelated API. My previous suggestion still stands.

0

Please sign in to leave a comment.