Show file not in local file system
I am developing a plugin for Intellij IDEA where I would like to show the user a read only file not from the local file system. Right now I am able to make an API request to get the file as a string, however I could not find any way to display the file in the editor without saving it to the project directory. Right now, I'm creating a new folder in the base project directory, storing the files there and displaying them with
new OpenFileDescriptor(p, target).navigate(true);
where target is the virtual file I downloaded and saved to the project. However this solution is not ideal because it messes with the user's project structure, and it would require the user to edit their .gitignore as well. So in summary, is there any way to display a file/string in intellij's editor without saving to the project directory?
请先登录再写评论。
Implement your own `com.intellij.openapi.vfs.VirtualFileSystem` (see e.g. `com.intellij.openapi.vfs.impl.http.HttpFileSystemImpl`).
For anyone finding this thread looking for help, I actually accomplished my goal in a different way rather than creating an entire new VirtualFileSystem. I first get the directory of my plugin by using
Then I create a directory under my plugin directory to save the files I want the user to be able to open in the editor, but not have under the user's project directory.
I get the VirtualFile of this directory by using
I then save the file to the directory, and on a vfs refresh I set the content, set to read only and navigate to the file
I then plan on deleting these files on a project close.
I thought you wanted to avoid storing temporary files. Better use `PathManager.getTempPath()` instead of a plugin directory, then.