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?
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
Forget what I said. Obviously I should read more carefully ;)
Unfortunately we do not have any support for synchronization between
"in the air" Documents and "in the air" PsiFile (that is, items without
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:
Dave Kriewall wrote:
IntelliJ Labs / JetBrains Inc.
"Develop with pleasure!"