Custom Structure View - how to get more than one level of structure
I am building a plugin for custom language, i have a basic prototype grammar / lexer and am building the PSI no problem. Ive done this in conjunction with working through the sample customer language tutorial.
Recently i started working on the structure view for the a sample source file, ive managed to get a single level of top level objects but cant seem to fathom how i add more to the structure tree below the top level objects.
unfortunately i cant share source so need to describe this in abstract terms.
Say source file consists of a number of objects say like a c function
fun myfunction {
obja {
}
objb {
}
}
fun anotherFunc {
objc {
objd {
}
}
}
here ive two functions myfunction and anotherfunction, the first has two children (obja and objb) lets call them innerfunctions, the second has only one child objc but that has its own child objd. these are both innerfunctions
What i need to see in the structure view for this file is something like
|
+ myfunction
| |-- obja
| +--objb
+ anotherfunction
+-- objc
+ objd
My first question is - in my StructureViewModel - do i need to put in objects in the array returned by getSuitableClasses() which represent the objects at the different levels. I have a Function.class PSI object for the top level function - am i correct in assuming i need a corresponding class for the object to represent (obja and objb) ?
Second q - assuming i have two PSI objects (and their corresponding interfaces) can the both implement the same PsiNameIdentifieredOwner ?
Further to that does the walking of the PSI tree to build the structure view happen "automatically" - i am a bit puzzled...
are there any example code bases i can look at to give me some direction.
Sorry to be opaque !
Please sign in to leave a comment.
com.intellij.ide.structureView.TextEditorBasedStructureViewModel#getSuitableClassesmust return all PSI elements that are (possibly) represented in the Structure View, as per its javadoc.Your plugin must provide all elements to be shown, e.g. via
com.intellij.ide.structureView.impl.common.PsiTreeElementBase#getChildrenBase. See also sample implementations from OSS plugins here: https://plugins.jetbrains.com/intellij-platform-explorer/extensions?extensions=com.intellij.lang.psiStructureViewFactorycom.intellij.psi.PsiNameIdentifierOwnerquestion - there are no strict rules on how to model/implement your PSI, e.g. you could share same implementation in common base class for multiple PSI elements.Thanks Yann - i will check out the link you mention, it sounds like i am going in the right direction.