Load Viewer (or Editor) for large file on disk (outside of project)
I'm trying get my plugin to load a very large (600MB+) file from disk and display it in a read-only window.
The file exists outside of the project.
I'm trying the following (and several variations):
class MyView extends JPanel
{
Path file = Paths.get("C:\\downloads\\server.log");
Project project = ProjectManager.getInstance().getDefaultProject();
VirtualFile vfile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file.toFile());
// Note that I would prefer a read-only FileViewer, but I don't see a LargeFileViewerProvider
FileEditor editor = LargeFileEditorProvider.getInstance().createEditor(project, vfile);
add(editor);
}
I keep getting stuck though because no matter how I come at this, the document associated with `vfile` is `null`.
How can I have IntelliJ load the document and display it in a (ideally read-only) editor?
Specific detail:
Caused by: java.lang.IllegalArgumentException: Argument for @NotNull parameter 'document' of com/intellij/openapi/editor/impl/EditorFactoryImpl.createMainEditor must not be null
Please sign in to leave a comment.
Editing to add:
If I use the code provided above, and pass through a small text file (1KB), it loads up no problem. But it doesn't seem able to log a large file
Edit to add again:
The problem appears to be that IntelliJ is guessing at the contents.
If I rename the large file from server.log to server.txt, it opens in the editor fine.
So my revised question, please, is:
1. How do I specify the type of file that this should be? (i.e. log file format if there is one, or failing that plain text)
2. How do I create a Viewer (read-only) version of the Editor provided by LargeFileEditorProvider?