JSON highlighting in LanguageTextField

Hello!

I wrote a small Plugin to display formatted and highlighted XML out of the debugger:

new LanguageTextField(Language.findInstance(XmlLanguage.class);

Now I would like to do the same with JSON, but I don't know which language class to use. If I use PlainTextLanguage the JSON gets formatted but is not highlighted.

Regards

Chris

11 comments

com.intellij.lang.javascript.json.JSONLanguageDialect.JSON

You'll need to add jars from JavaScript Language plugin to your Plugin SDK classpath and dependency on 'JavaScript' in plugin.xml.

0

I tried

new LanguageTextField(com.intellij.lang.javascript.json.JSONLanguageDialect.JSON, project, text);

Now i get:

[  43922]  ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.InvocationEvent[INVOCATION_DEFAULT,runnable=com.intellij.debugger.DebuggerInvocationUtil$1@2a02ce09,notifier=null,catchExceptions=false,when=1383047453462] on sun.lwawt.macosx.LWCToolkit@67345131
java.lang.AssertionError
 at com.intellij.ui.LanguageTextField.a(LanguageTextField.java:86)
 at com.intellij.ui.LanguageTextField.access$000(LanguageTextField.java:33)
 at com.intellij.ui.LanguageTextField$SimpleDocumentCreator.createDocument(LanguageTextField.java:74)
 at com.intellij.ui.LanguageTextField.<init>(LanguageTextField.java:58)
 at com.intellij.ui.LanguageTextField.<init>(LanguageTextField.java:42)
 at com.intellij.ui.LanguageTextField.<init>(LanguageTextField.java:38)
 at com.os.showas.EditorWrapper.<init>(EditorWrapper.java:32)
 at com.os.showas.ShowAs.processText(ShowAs.java:29)
 at com.intellij.debugger.actions.BaseValueAction$1$1.run(BaseValueAction.java:84)
 at com.intellij.debugger.DebuggerInvocationUtil$1.run(DebuggerInvocationUtil.java:33)
 at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
 at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
 at java.awt.EventQueue.access$200(EventQueue.java:103)
 at java.awt.EventQueue$3.run(EventQueue.java:688)
 at java.awt.EventQueue$3.run(EventQueue.java:686)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
 at com.intellij.ide.IdeEventQueue.d(IdeEventQueue.java:700)
 at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:525)
 at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:348)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
[  43923]  ERROR - com.intellij.ide.IdeEventQueue - IntelliJ IDEA 12.1.6  Build #IU-129.1359
[  43923]  ERROR - com.intellij.ide.IdeEventQueue - JDK: 1.7.0_13
[  43923]  ERROR - com.intellij.ide.IdeEventQueue - VM: Java HotSpot(TM) 64-Bit Server VM
[  43923]  ERROR - com.intellij.ide.IdeEventQueue - Vendor: Oracle Corporation
[  43923]  ERROR - com.intellij.ide.IdeEventQueue - OS: Mac OS X
[  43923]  ERROR - com.intellij.ide.IdeEventQueue - Last Action: Debugger.ShowAsJson

0

Make sure you added dependency to plugin.xml:

<depends>JavaScript</depends>

0

I did:

<idea-plugin version="2">
    ...
    <depends>JavaScript</depends>
     ...
</idea-plugin>

0

Still the same:

java.lang.NullPointerException
 at com.intellij.ui.LanguageTextField.a(LanguageTextField.java:89)
 at com.intellij.ui.LanguageTextField.access$000(LanguageTextField.java:33)
 at com.intellij.ui.LanguageTextField$SimpleDocumentCreator.createDocument(LanguageTextField.java:74)
 at com.intellij.ui.LanguageTextField.<init>(LanguageTextField.java:58)
 at com.intellij.ui.LanguageTextField.<init>(LanguageTextField.java:42)
 at com.intellij.ui.LanguageTextField.<init>(LanguageTextField.java:38)
 at sample.SampleDialog.createCenterPanel(SampleDialog.java:23)
 at com.intellij.openapi.ui.DialogWrapper.init(DialogWrapper.java:1116)
 at sample.SampleDialog.<init>(SampleDialog.java:17)
 at sample.SampleAction.actionPerformed(SampleAction.java:14)
 at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:162)
 at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter$1.run(ActionMenuItem.java:259)
 at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:892)
 at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:114)
 at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:230)
 at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
 at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:104)
 at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:512)
 at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:44)
 at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:532)
 at java.awt.Component.processMouseEvent(Component.java:6505)
 at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
 at java.awt.Component.processEvent(Component.java:6270)
 at java.awt.Container.processEvent(Container.java:2229)
 at java.awt.Component.dispatchEventImpl(Component.java:4861)
 at java.awt.Container.dispatchEventImpl(Container.java:2287)
 at java.awt.Component.dispatchEvent(Component.java:4687)
 at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
 at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
 at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
 at java.awt.Container.dispatchEventImpl(Container.java:2273)
 at java.awt.Window.dispatchEventImpl(Window.java:2719)
 at java.awt.Component.dispatchEvent(Component.java:4687)
 at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
 at java.awt.EventQueue.access$200(EventQueue.java:103)
 at java.awt.EventQueue$3.run(EventQueue.java:688)
 at java.awt.EventQueue$3.run(EventQueue.java:686)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
 at java.awt.EventQueue$4.run(EventQueue.java:702)
 at java.awt.EventQueue$4.run(EventQueue.java:700)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
 at com.intellij.ide.IdeEventQueue.d(IdeEventQueue.java:700)
 at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:521)
 at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:348)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
[  36143]  ERROR - com.intellij.ide.IdeEventQueue - IntelliJ IDEA 12.1.6  Build #IU-129.1359
[  36143]  ERROR - com.intellij.ide.IdeEventQueue - JDK: 1.7.0_13
[  36143]  ERROR - com.intellij.ide.IdeEventQueue - VM: Java HotSpot(TM) 64-Bit Server VM
[  36143]  ERROR - com.intellij.ide.IdeEventQueue - Vendor: Oracle Corporation
[  36143]  ERROR - com.intellij.ide.IdeEventQueue - OS: Mac OS X
[  36143]  ERROR - com.intellij.ide.IdeEventQueue - Last Action: sample.action.id


Maybe I am using the wrong JavaScript jar. I took IDEA_HOME/plugins/JavaScriptLanguage/lib/JavascriptLanguage.jar

0

Yes,  IDEA_HOME/plugins/JavaScriptLanguage/lib/JavascriptLanguage.jar is enough, though it is recommenden to add all jars from  IDEA_HOME/plugins/JavaScriptLanguage/lib/
Just checked with a clean IntelliJ IDEA 12.1.6 installation in Windows 7 and my sample plugin works.



Attachment(s):
Untitled.png
0

Ok, got it! Had to change the scope of JavaScriptLanguage.jar to provided. Now it works.

Thanks for the help!

0

Instead you'd better add JavaScriptLanguage.jar and other jars from the corresponding folder to Plugin SDK classpath as I recommended in my first answer (Project Structure | SDKs).

0

Currently I am trying to migrate my plugin to IDEA 14 an I realized that com.intellij.lang.javascript.json.JSONLanguageDialect.JSON is not present any more. Which Language should be used to format JSON in IDEA 14?

0

Please sign in to leave a comment.