non psi-based structured view Follow
hello! Heh, I'm working again on the ANTLR parser -> intellij integration and I am trying to do everything with ANTLR parse trees instead of the "native" PSI stuff in Intellij as I find my trees much easier to deal with. Anyway, this means of course that I have a lot of my own implementation work to do, which I'm okay with. My question is: can I build a structure view that doesn't use PSI? One would normally activate with <lang.psiStructureViewFactory...> in the plugin.xml but Intellij does not have a PsiFile to pass me.
Is it a matter of creating my own pane with my own JTree or something and then triggering an update in that pane when the editor changes?
Any suggestions would be welcome. I would like to use as much of the existing infrastructure as possible without resorting to the PSI.
Thanks!
Terence
PS I have it nicely doing syntax highlighting at the lexical and grammatical level from an antlr grammar. I'm working on a stringtemplate plugin as a demo. https://plugins.jetbrains.com/plugin/8041?pr=
Please sign in to leave a comment.
yes you could display any text in structured view. Follow the tutorial and tweak it like this:
public class CustomStructureViewTreeElement
implement StructureViewTreeElement
@Override
public Object getValue() {
return this;
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false; // if you need to navigate, this can be done too.
}
@Override
public ItemPresentation getPresentation() { /* you need to implement this */ }
@Override
public TreeElement[] getChildren() { /*.. and this */ }
Please check com.intellij.ide.structureView.StructureViewBuilderProvider
Hi Imants, thanks! The issue is not the StructureViewTreeElement but rather how to hook in a tree not based upon Psi. For example, constructor for StructureViewModelBase takes a psifile, which I don't have.
Hi Yann! Thanks :) I was definitely going down that path but couldn't figure out how to hook my provider into intellij. Thanks to your suggestion, I found structureViewBuilder in plugin.xml and will try that to hook in my stuff.
[edit: confirmed. structureViewBuilder invokes my builder when i open the structure pane]
Terence
> a tree not based upon Psi.
will your StructureView be used without any file open in the editor?
if yes, then of course StructureViewTreeElement is not usable - structure view only appears with a file open in editor.
otherwise StructureViewTreeElement implementation may show any data you like - with children if you like.
You could use PsiElement passed to ctor to e.g. get project, or simply not pass the PsiElement to StructureViewTreeElement ctor.
StructureViewTreeElement is only an interface - it does not prescribe a ctor(PsiElement).
If I misunderstand something, let's leave it. ;)
just realized: StructureViewModelBase does require a ctor(PsiFile).
are you using lang.psiStructureViewFactory EP? If yes, PsiFile is passed to getStructureViewBuilder
Hi, yes was able to make it work. My problem was hooking in the generic view builder :) Works great now. thanks for your suggestions.
Terence
Attachment(s):
structview.png
Hi Yann, On a related topic, I assume I can't use the Annotator hierarchy because it relies on PSI trees given the following method?
void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder);
I can build my own daemon but wanted to verify with you that I can't use Annotation or even DaemonCodeAnalyzer due to the dependence on PSI trees.
thanks!
Ter
Indeed, Annotator and Inspections rely on PSI. You should be able to use TextEditorHighlightingPass, see org.jetbrains.idea.devkit.testAssistant.TestDataHighlightingPass for a sample.
Excellent. Thank for all your pointers. Usually that's all I need and they are very helpful.
Terence