How create Symbol for Psi
Hello,
I'm toying with newer Symbol API, but cannot get to how to correctly create Symbols for it.
At https://plugins.jetbrains.com/docs/intellij/declarations-and-references.html#own-references
There are two ways of:
implement and register PsiSymbolDeclarationProvider or implement PsiSymbolDeclaration directly in the PsiElement
For for that PsiSymbolDeclaration I'm not sure how.
My PsiElement is implementing currently as
@Override
public @NotNull PsiElement getDeclaringElement() {
return this;
}
@Override
public @NotNull TextRange getRangeInDeclaringElement() {
return this.getTextRange();
}
@Override
public @NotNull Symbol getSymbol() {
var service = ApplicationManager.getApplication().getService(PsiSymbolService.class);
return service.asSymbol(this);
}
I can get servise like this or by PsiSymbolService.getInstance() but both of them are marked as Internal so I cannot use it.
https://plugins.jetbrains.com/docs/intellij/api-internal.html#intellij-platform doesn't have anything regarding this servise as well.
What are ways of creating Symbol that are not @Internal?
Please sign in to leave a comment.
Hi,
Yes, this is an internal API. You should create your own symbol implementation and create it directly in declaration.
That'd be worth adding to documentation, please.
Also why not open that servise for public?
I've actually tried copy-pasting Psi2Symbol and it's MyPointer classes, which for whatever reason didn't work, unline actually using those @Internals, but I'll try to figure it out later.
But those implementations look so minimalistic, that why not open them up for features requiring Symbols as a GoTo default solution?
Thank you for the feedback.
The Symbol API is under active development, and it is not stable enough to document it in the details. Please keep in mind it is experimental and implementing it may require digging in the code to understand it, and dealing with incompatible API changes.
Ah ok.
But while I'm at it, I've also found reason why my own Symbol doesn't work is, that it always falls into PsiSymbolServiceImpl where it's thrown away:
I'm trying to create Implicit GoTo reference so I can click on name of file within a string Token and open that file if it exists.
But this Usage is populated from CtrlMouseData.kt, where it calls aforementioned service throwing it away.
And now I'm lost.
So if I'm supposed to implement my own Symbols does it mean I cannot use already existing APIs like Implicit references?
This seems to be an overlooked problem.
Hello,
is there any update on this? I don't see any changes in the SymbolAPI which is kind of useless for non-internal plugin devs.
At least removal of that @ApiStatus.Internal on PsiSymbolService would make this useable.
Or if this is still under develoment and not meant to be used maybe revert Custom language tutorial back to the old API?