XML like language, Refused to parse text

Hello,

I am trying to create a plugin for an XML like language. My language extends XMLLanguage, and my File type extends from XMLLikeFileType, and I have registered the FiletypeFactory and dom.fileDescription in the plugin.xml file. My Classes all extend from DomElement, and they all have SubTag, SubTagList and Attribute annotations on their fields. I have been looking at the other plugins listed in the XML Dom API page, but they seem to be doing the same things I am, only mine does not work.

The custom files do not allow any real editing. I am not able to close the opening tag unless I close the file and then open it and try again. I cannot type more than a character inside the tags before it stops registering input. At times the ide will delete the input. . In the main IDE I get the same error repeated over and over (Stack trace below).

I am having a hard time figuring any of this out. The XML DOM API page does not offer much information about how to set up your own file and language with the DOM API. Any help would be really appreciated.

StackTrace

2018-10-01 16:19:59,878 [ 62574] ERROR - llij.ide.plugins.PluginManager - View provider SingleRootFileViewProvider{myVirtualFile=file:///{{user_dir}}/Test.mjml, content=com.intellij.psi.AbstractFileViewProvider$PsiFileContent@3cbbf83f} refused to parse text with Language: XML; languages: [Language: MJML]; base: Language: MJML; copy: SingleRootFileViewProvider{myVirtualFile=LightVirtualFile: /Test.mjml, content=VirtualFileContent{size=40}}; copy.base: Language: MJML; vFile: file:///{{user_dir}}/Test.mjml; copy.vFile: LightVirtualFile: /Test.mjml; fileType: intellij.plugin.mjml.lang.MJMLFileType@7da5a007; copy.original(): file:///{{user_dir}}/Test.mjml 
java.lang.RuntimeException: View provider SingleRootFileViewProvider{myVirtualFile=file:///{{user_dir}}/Test.mjml, content=com.intellij.psi.AbstractFileViewProvider$PsiFileContent@3cbbf83f} refused to parse text with Language: XML; languages: [Language: MJML]; base: Language: MJML; copy: SingleRootFileViewProvider{myVirtualFile=LightVirtualFile: /Test.mjml, content=VirtualFileContent{size=40}}; copy.base: Language: MJML; vFile: file:///{{user_dir}}/Test.mjml; copy.vFile: LightVirtualFile: /Test.mjml; fileType: intellij.plugin.mjml.lang.MJMLFileType@7da5a007; copy.original(): file:///{{user_dir}}/Test.mjml
at com.intellij.psi.impl.BlockSupportImpl.getFileCopy(BlockSupportImpl.java:271)
at com.intellij.psi.impl.BlockSupportImpl.makeFullParse(BlockSupportImpl.java:235)
at com.intellij.psi.impl.BlockSupportImpl.reparse(BlockSupportImpl.java:104)
at com.intellij.psi.impl.DocumentCommitThread.doCommit(DocumentCommitThread.java:679)
at com.intellij.psi.impl.DocumentCommitThread.lambda$commitUnderProgress$4(DocumentCommitThread.java:450)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1156)
at com.intellij.psi.impl.DocumentCommitThread.commitUnderProgress(DocumentCommitThread.java:471)
at com.intellij.psi.impl.DocumentCommitThread.commitSynchronously(DocumentCommitThread.java:365)
at com.intellij.psi.impl.PsiDocumentManagerBase.lambda$doCommit$1(PsiDocumentManagerBase.java:450)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1038)
at com.intellij.psi.impl.PsiDocumentManagerBase.doCommit(PsiDocumentManagerBase.java:458)
at com.intellij.psi.impl.PsiDocumentManagerBase.commitDocument(PsiDocumentManagerBase.java:299)
at com.intellij.codeInsight.editorActions.EnterBetweenXmlTagsHandler.isAtTheEndOfEmptyTag(EnterBetweenXmlTagsHandler.java:90)
at com.intellij.codeInsight.editorActions.EnterBetweenXmlTagsHandler.isBetweenXmlTags(EnterBetweenXmlTagsHandler.java:65)
at com.intellij.codeInsight.editorActions.EnterBetweenXmlTagsHandler.preprocessEnter(EnterBetweenXmlTagsHandler.java:46)
at com.intellij.codeInsight.editorActions.EnterHandler.executeWriteActionInner(EnterHandler.java:114)
at com.intellij.codeInsight.editorActions.EnterHandler.lambda$executeWriteAction$0(EnterHandler.java:67)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.lambda$disablePostprocessFormattingInside$1(PostprocessReformattingAspect.java:109)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:117)
at com.intellij.psi.impl.source.PostprocessReformattingAspect.disablePostprocessFormattingInside(PostprocessReformattingAspect.java:108)
at com.intellij.codeInsight.editorActions.EnterHandler.executeWriteAction(EnterHandler.java:66)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(EditorWriteActionHandler.java:51)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1038)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.doExecute(EditorWriteActionHandler.java:64)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:210)
at com.intellij.codeInsight.template.impl.editorActions.EnterHandler.executeWriteAction(EnterHandler.java:49)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(EditorWriteActionHandler.java:51)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1038)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.doExecute(EditorWriteActionHandler.java:64)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$null$2(EditorActionHandler.java:202)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.doIfEnabled(EditorActionHandler.java:110)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$execute$3(EditorActionHandler.java:201)
at com.intellij.openapi.editor.impl.CaretModelImpl.lambda$runForEachCaret$2(CaretModelImpl.java:363)
at com.intellij.openapi.editor.impl.CaretModelImpl.doWithCaretMerging(CaretModelImpl.java:452)
at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:355)
at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:346)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:201)
at com.intellij.openapi.editor.actionSystem.EditorAction.lambda$actionPerformed$0(EditorAction.java:96)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:139)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:97)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:105)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:80)
at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:220)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:237)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:620)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$processAction$2(IdeKeyEventDispatcher.java:669)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:195)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:668)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:520)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:475)
at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:212)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:697)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:382)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
2018-10-01 16:19:59,879 [ 62575] ERROR - llij.ide.plugins.PluginManager - IntelliJ IDEA 2018.2.4 Build #IU-182.4505.22
2018-10-01 16:19:59,879 [ 62575] ERROR - llij.ide.plugins.PluginManager - JDK: 1.8.0_162
2018-10-01 16:19:59,879 [ 62575] ERROR - llij.ide.plugins.PluginManager - VM: Java HotSpot(TM) 64-Bit Server VM
2018-10-01 16:19:59,879 [ 62575] ERROR - llij.ide.plugins.PluginManager - Vendor: Oracle Corporation
2018-10-01 16:19:59,879 [ 62575] ERROR - llij.ide.plugins.PluginManager - OS: Mac OS X
2018-10-01 16:19:59,879 [ 62575] ERROR - llij.ide.plugins.PluginManager - Last Action: EditorEnter 

 

Base Language Classes

public class MJMLLanguage extends XMLLanguage {
public static final MJMLLanguage INSTANCE = new MJMLLanguage();

private MJMLLanguage() {
super(XMLLanguage.INSTANCE, "MJML");
}
}

public class MJMLFileType extends XmlLikeFileType {

public static final String FILE_EXTENSION = "mjml";
public static final MJMLFileType INSTANCE = new MJMLFileType();

private MJMLFileType() {
super(MJMLLanguage.INSTANCE);
}

@NotNull
@Override
public String getName() {
return "MJML File";
}

@NotNull
@Override
public String getDescription() {
return "MJML Email Template File";
}

@NotNull
@Override
public String getDefaultExtension() {
return FILE_EXTENSION;
}

@Nullable
@Override
public Icon getIcon() {
return MJMLIcons.DOC_ICON;
}
}
public class MjmlFileDescription extends DomFileDescription<Mjml> {
public MjmlFileDescription() {
super(Mjml.class, "mjml");
}

@Nullable
public Icon getFileIcon(@Iconable.IconFlags
int flags) {
return MJMLIcons.DOC_ICON;
}
}

 

 

2 comments

Another note, Some attributes repeat, so I put them in interfaces. Will that cause the xml file to fail?

0

If anyone is interested, I was able to fix the problem by registering a file type and parser definition. The two files are brief, but as I defined my own language and file type, I guess it was necessary. When looking through the example projects, I decided to look specifically for a Parser definition to see if one existed, and the first project I checked did indeed have one. I took it and modified it. Here is an example in case anyone ever needs it. This may be documented somewhere that I didn't see.

Parser Definition:

package intellij.plugin.mjml.psi;

import com.intellij.lang.*;
import com.intellij.lang.xml.XMLLanguage;
import com.intellij.lang.xml.XMLParserDefinition;
import com.intellij.lexer.Lexer;
import com.intellij.lexer.XmlLexer;
import com.intellij.openapi.project.Project;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;

/**
*
* adapted from TmlParser by Alexey Chmutov
*/
public class MjmlParserDefinition implements ParserDefinition {
@Override
@NotNull
public Lexer createLexer(Project project) {
return new XmlLexer();
}

@Override
public IFileElementType getFileNodeType() {
return MjmlFile.MJML_FILE_ELEMENT_TYPE;
}

@Override
@NotNull
public TokenSet getWhitespaceTokens() {
return LanguageParserDefinitions.INSTANCE.forLanguage(Language.findInstance(XMLLanguage.class)).getWhitespaceTokens();
}

@Override
@NotNull
public TokenSet getCommentTokens() {
return LanguageParserDefinitions.INSTANCE.forLanguage(Language.findInstance(XMLLanguage.class)).getCommentTokens();
}

@Override
@NotNull
public TokenSet getStringLiteralElements() {
return TokenSet.EMPTY;
}

@Override
@NotNull
public PsiParser createParser(final Project project) {
return LanguageParserDefinitions.INSTANCE.forLanguage(Language.findInstance(XMLLanguage.class)).createParser(project);
}

@Override
public PsiFile createFile(FileViewProvider viewProvider) {
return new MjmlFile(viewProvider);
}

@Override
public SpaceRequirements spaceExistenceTypeBetweenTokens(ASTNode left, ASTNode right) {
final Lexer lexer = createLexer(left.getPsi().getProject());
return XMLParserDefinition.canStickTokensTogetherByLexerInXml(left, right, lexer, 0);
}

@Override
@NotNull
public PsiElement createElement(ASTNode node) {
throw new IllegalArgumentException("Unknown element: "+node);
}
}

File

package intellij.plugin.mjml.psi;

import com.intellij.psi.FileViewProvider;
import com.intellij.psi.impl.source.xml.XmlFileImpl;
import com.intellij.psi.tree.IFileElementType;
import com.intellij.psi.xml.XmlFile;
import intellij.plugin.mjml.lang.MJMLLanguage;

/**
* @author Daniel Badal
*/
public class MjmlFile extends XmlFileImpl implements XmlFile {

static final IFileElementType MJML_FILE_ELEMENT_TYPE = new IFileElementType("MJML_FILE_ELEMENT_TYPE", MJMLLanguage.INSTANCE);

MjmlFile(FileViewProvider viewProvider) {
super(viewProvider, MJML_FILE_ELEMENT_TYPE);
}

@Override
public String toString() {
return "MjmlFile:" + getName();
}
}
0

Please sign in to leave a comment.