what is the PSI data structure responsible for retrieving static types of a language? Follow
i need to know how intellij idea features like (quick documentation) reach the static types of a language local variables and methods parameters.
this is a java local variable
and this is a dart local variable
i'm working with dart PSI for a plugin, i need to get dart variables and methods parameters static types but i couldn't find a clue on how it could be done. so is there a structure in PSI that is responsibile for such a task?
i managed to debug dart document provider in order to reach the statements which are responsibile for gathering the documentation info. it appears to be the following two statements.
List<HoverInformation> hoverList = psiFileVirtualFile != null ? DartAnalysisServerService
.analysis_getHover(psiFileVirtualFile, o.getTextOffset()) :
var information = hoverList.isEmpty() ? null : (HoverInformation)hoverList.get(0);
i tried to debug the statements above further more to understand how it reflect on static type only, but it was extremely diffucult to follow the debugger and i couldn't get a useful information out of debugging.
so, if i want to reach the variables and methods parameters static types in dart langugage, how could it be done?
if you don't know just help me with anything could be useful for searching.
Please sign in to leave a comment.
Dart support in IntelliJ IDEA is based on the Dart Analysis Server. It's a special tool from the Dart SDK that works as a language server. While the Dart plugin still builds PSI, it's not used directly for smart features such as reference resolution or type evaluation.
Here's the server API. DartAnalysisServerService class is used to handle requests/responses. analysis_getHover() is one of the methods. You can debug the info that it returns and see if it is useful for your task.
Also, I would like to add that the type inference mechanism depends on the language and PSI implementation.
In the case of Java variable declaration ("var i = 1;"), you can get the type form PSI by calling PsiLocalVariable.getType() for the declaration element. For usage (e.g. "i++;"), it is similar: PsiReferenceExpression.getType().
Thanks to both of you!
but i have a question to Alexander Doroshko: do you mean there is nothing similar to the psi statements from java PSI PsiLocalVariable.getType() and PsiReferenceExpression.getType() in dart PSI?
If you need somthing trivial, based only on file text, you'll get it by using Dart PSI, without help of Analysis Server. Use PSI Viewer to explore the syntax tree and call getText() of the required PsiElement (unless the required PsiElement already has a more convenient method that matches your needs).
All info that requires being smart (reference resolution, type calculation, etc.) can only be gotten from the server.
your speach is ambiguous, What i simply need is the following:
the code above is a dart code. i need a way to get the following information:
- PSI Element "s" static type which is (String) in this example.
- PSI Element "TextFunc" static type which is (String Function (int)).
- PSI Element "4" static type which is (dynamic).
from your comment, i uderstand that this task can't be accomplished with dart PSI. so i must use the server. but i couldn't find the function in the server which is responsibile for (only and only) this task.
So, do you know the function that will give me (only and only) this information in Dart analysis Server?
You are right, you need to use server. There's no function responsible for only and only this task. Searching server api for "staticType" I see that ony HoverInformation contains it.
Thank you very much for your efforts! :D