PSI Structure for binary file

I'm developing a plugin for IDEA to support specific files with xml-like syntax.
They just provide some tree of elements, and I want to show them in project tree (with expandable tree node for the file).
So, from my point of view - it's not a language, even the file is actually xml. I don't want to allow manual editing of these files.

For the first, my assumption is that PSI tree will be perfect for the case.
So I made class SchemaFile (that extends PsiFile) - it's being created by custom FileViewProvider (extended from SingleRootFileViewProvider).

And I stuck here :)

So, the question is: how do I create psi-childs for that SchemaFile? For instance, each schema file contains several SchemaModel.
PsiBuilder requires language lexer and parser - but it's impossible for that file format, it can even be binary of free format. So some psi elements (like SchemaModel and descendants) will be virtual, without textual representation. And I need an ability to alter those psi elements and flush changes to the schema file (that's not a point right now - I'll create custom designer for SchemaModel later).

Am I going wrong with all this PSI structure? Future plan is to map some Java classes to SchemaModel elements, so imho it's a good start.

Thanks a lot

5 comments
Comment actions Permalink

I'm thinking about another approach - by adding VFS implementation (based on file content).

So the schema file itself is like archive of some entities, that can be represented as VirtualFile (with corresponding "file" editors etc).
In this case it'd be easier to create editors support.

I'll try this first, as long as I have no answers yet.

0
Comment actions Permalink

ol-loginov wrote:

I'm thinking about another approach - by adding VFS implementation (based on file content).

So the schema file itself is like archive of some entities, that can be represented as VirtualFile (with corresponding "file" editors etc).
In this case it'd be easier to create editors support.

I'll try this first, as long as I have no answers yet.

This seems to be a bad idea. My entry point - file with known extension. And it's already a virtual file. Go back to PSIs

0
Comment actions Permalink

If you simply want to display the structure of a file in the project view, you need neither the PSI nor a custom VFS. Instead, you need to implemen the TreeStructureProvider extension point, which will let you customize the presentation of your files in the project view, including adding a hierarchy of nodes below the original file.

0
Comment actions Permalink

Thanks,

It was easy to implement. And I did so first.

But still, I need to setup designer for entities stored in file (and displayed under file in project tree). They should be different for every entity type.
I noticed that com.intellij.designer.DesignerEditor requires VirtualFile in constructor. At the same time com.intellij.openapi.editor.EditorFactory requires Document.

Can you give some direction in developing such editors/designers (that based on part of file)?
Maybe some open-source plugin? I tried android-related sources, but with no luck (cannot observe those completely)

0
Comment actions Permalink

If you need to open editor tabs for the nodes inside your file, you need to provide a custom VirtualFileSystem and VirtualFile implementation that will represent the nodes.(It doesn't matter whether the top node of your hierarchy is a virtual file or not; the idea is that anything that can be opened in an editor tab needs to be represented as a distinct VirtualFile.)

The EditorFactory class is not relevant here unless your designer will use IntelliJ IDEA's standard text editor.

0

Please sign in to leave a comment.