How to associate a Document with a PsiFile (or vice versa)?
I am trying to add a code preview pane to the tabifier plugin, similar to the preview panes available under several Code Style tabs. Maxim Shafirov suggested:
This approach would work if all my edits could be performed against the psiFile object. However, I use the Document.replaceString() method to update psiFile. For this I need a Document.
I tried to obtain a Document from the newly created psiFile, or a psiFile from the Document, but both return null, as follows:
How do I establish a connection between a Document and a newly created PsiFile?
Thanks-
Dave
Please sign in to leave a comment.
Maybe you need to get the document from the psifile instead of the editor. the psifile might now have been commited yet.
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
Document document = documentManager.getDocument(psiFile);
//your edit here
// then you commit the document
documentManager.commitDocument(newDocument);
Jacques
Forget what I said. Obviously I should read more carefully ;)
Dave,
Unfortunately we do not have any support for synchronization between
"in the air" Documents and "in the air" PsiFile (that is, items without
associtated VirtualFile).
I am afraid your only option if you want to have the same code in preview
and for "real" reformatting is to write your own synchronization.
Something along the following lines:
Friendly,
Dmitry
Dave Kriewall wrote:
--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"