Custom language plugin: a new PsiFile instance at every parse (ie. after every edit)?

Hi,

I'm developing a custom language plugin (Ceylon language). A new PsiFile instance is created (ie. ParserDefinition#createFile gets called) each time the file is edited. Is this normal? I'd expect same PsiFile to remain the same, since it says here http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview#IntelliJIDEAArchitecturalOverview-PsiFiles :

Unlike VirtualFile and Document, which have application scope (even if multiple projects are open, each file is represented by the same VirtualFile instance), PSI has project scope (the same file is represented by multiple PsiFile instances if the file belongs to multiple projects open at the same time).

The reason this is problematic for me is that I'm using an Annotator that tries to access some data that I store in my implementation of the PsiFile, and the Annotator always gets the same PsiFile instance, while there are new instances created when editing and the one Annotator gets is thus stale.

If it's normal that createFile is called after each edit, why does the Annotator then get the old instance? If it's not normal, what might I be doing wrong to cause this?

Thanks for any help!
Matija
2 comments

That's normal. On any change to a text, IDEA builds a parallel PSI tree with a newly created PsiFile at the top, then builds a diff by comparing it to an existing one, then modifies original tree by inserting, replacing, or deleting parts of it (see BlockSupportImpl.makeFullParse() for reference). The new PsiFile is then discarded.

0

Please sign in to leave a comment.