VirtualFile is not refreshed

Answered

I have been implementing copy/paste clipboard feature over some kind of node that contains virtualFile field. The problem is when I try to paste a copy, I need to copy file content as well, but for a some reason it caches the old file content. 

The files are changed via Editor.
No one way I found to refresh the virtual files does not work:

LocalFileSystem.getInstance().refreshFiles(listOf(virtualFile), false, false)
//or
virtualFile.refresh(false , false)

These files are created out of Project the following way:

val file = File("${pluginDir.path}${fileSeparator}${node.id}.${extension}")
if (!file.exists()) {
file.createNewFile()
}

return LocalFileSystem.getInstance().findFileByNioFile(
file.toPath()
)

Could you please help, should I refresh it somehow else or the issue is in wrong VirtualFile creation?

0
3 comments

found the working way to read actual data:

val file = PsiManager.getInstance(project).findFile(virtualFile)!!

var content = file.text.encodeToByteArray()
1

also: 

val psiFile = virtualFile.toPsiFile(project)

psiFile.text…

0

That is the answer,thank you, brother

0

Please sign in to leave a comment.