Editor syntax highlighting without specifying extension Follow
Answered
If I create an Editor specifying
FileDocumentManager.getInstance().getDocument(ScratchFileService.getInstance().findFile(rootType, "myfile.json"))
as the document and
new JsonFileType()
as fileType, I get an editor with correct JSON syntax highlighting.
But, since I want to create an Editor that will not store its data in a physical file, but rather in file attributes, I use only
new DocumentImpl("initial text data");
when creating the editor. After that, syntax highlighting becomes limited (see picture):
The 2nd editor is created without using a VirtualFile.
I guess the reason highlighting works in the 1st case is because of specifying the ".json" extension.
How can I get syntax highlighting with using only Document, without VirtualFile? When saving editor data, I use document.getText().
Please sign in to leave a comment.
Have you considered using com.intellij.testFramework.LightVirtualFile ?
Thanks, worked like a charm!
For future reference, here's what I had to do:
It's also better to use com.intellij.json.JsonFileType#INSTANCE
Filetypes may be compared with ==