Document changes not flushed when IDE is not focused
Answered
I have plugin process running as a thread (executeOnPooledThread
) and it performs document update using
vfsDoc.setText(content)
PsiDocumentManager.getInstance(project).commitDocument(vfsDoc)
If IDE window is not focused (I am doing different things in a meantime) changes are not flushed to filesystem. When I click anywhere on IDE it gets flushed immediately.
How to force file flushing? I was trying VfsUtil.markDirtyAndRefresh(false, false, false, vfsFile)
but it's not working.
Please sign in to leave a comment.
Ok, ChatGPT solved issue:
To force file changes to be flushed to the filesystem in an IntelliJ plugin, you can use the FileDocumentManager and VirtualFile APIs. Here's how you can modify your code to ensure that changes are properly flushed:
In this code:
By using FileDocumentManager.getInstance().saveDocument(document), we explicitly trigger the save operation for the document, ensuring that the changes are flushed to the filesystem. Additionally, by calling vfsFile.refresh(true, false), we ensure that the changes are immediately reflected in the IDE.