JavaScript API: Change Icon for JSLike file.
Is there a way to extend the JavaScript Language FileType? I would like to register files with the extension of .ds as JavaScript files with my plugin and provide a custom icon for those files. I would also like to potentially provide custom completions and such as well. Is this possible through the open api? I'm fine with providing only basic syntax with the community edition and the full JavaScript plugin with the ultimate edition, I'd just like to make some customizations if possible, specifcally the file icon.
Please sign in to leave a comment.
For Icons, use IconProvider (search the forum for more pointers).
It's no problem to register additional extensions for existing filetype, just register them via com.intellij.openapi.fileTypes.FileTypeFactory.
Regarding custom completions, please could you give more details on what you have in mind exactly?
I was able to register my Icon using the IconProvider using the following code.
Generic JS filetype is com.intellij.lang.javascript.JavaScriptFileType#INSTANCE (make sure to add jars from JavaScript plugin to your plugin SDK, not to your project).
OK that makes sense. Are the jars bundled with the community edition? Do you know what they are called and where I would find them? Thanks again!
JavaScript support is only available in Ultimate Edition.
$IDEA_HOME$/plugins/JavaScriptLanguage/lib
I was able to find all the jars and added them to my plugins lib folder. I then registered the ds file with the code below, but first the basic syntax highlighting does not work and second this seems to unregister JavaScript from the js extension. Is this the behavior I should expect?
Certainly not. Please make sure you do not override your code with previous manual mapping of filetype to DS extension.
If I register the filetype in this way I get *.js files to open with an unregistered extension. If I remove this code I get the reverse for *.ds. I checked and there are no previous mappings. I created a branch with my code maybe you could take a peek?
https://github.com/nek4life/intellij-demandware/tree/feature/ds-js-support
My lib folder: Do I need all of these? Which version of Intellij should I use? currently using Intellij 14.
https://github.com/nek4life/intellij-demandware/tree/feature/ds-js-support/lib
My Plugin XML
https://github.com/nek4life/intellij-demandware/blob/feature/ds-js-support/resources/META-INF/plugin.xml#L39
And My FileTypeFactory class
https://github.com/nek4life/intellij-demandware/blob/feature/ds-js-support/src/com/demandware/studio/ds/DSLanguageTypeFactory.java
Your plugin.xml must contain a <dependency> on JavaScript plugin:
I added this line, but now I get an error saying that the "required plugin "JavaScript" not installed."
Does this mean that I cannot use this feature unless I'm using the ultimate edition? I'm currently running and debugging this with the Community Edition. My hope was that I could support Highlighting only with Community and Full JS support for Ultimate.
I really appreciate the time you're spending helping me with this. Thank you.
Exactly, you cannot provide this functionality outside of running Ultimate Edition.
You could extract this into optional plugin descriptor, which would only be loaded if required plugin is really available.
Just put this functionality into separate plugin.xml named javascript.xml and change your plugin.xml to something like
<depends config-file="javascript.xml" optional="true">JavaScript</depends>
Thank you. Is there any way to hook into the syntax highlighting only for community edition? Or would that entail writing my own language support? I have in the past registered ds using the new file type UI and added all the keywords there. In fact I've gone into the settings folder and found the XML after I set it all up so I could share it. Could I somehow create a file type using that XML for community edition through an API and then if the JS plugin is available load that instead? Hooking into the support already provided in community edition would be preferred of course though.
Thanks!
I've updated my code as you suggest and now it does not throw any errors in the community edition, however it does not map the files with a ds extension to the JavaScript language in the ultimate edition. I checked in the UI and in fileTypes.xml and ds is not mapped anywhere. I feel like I'm so close, but I'm not really sure how to proceed. :D
Link to updated code branch
https://github.com/nek4life/intellij-demandware/tree/feature/ds-js-support
Your javascript.xml has wrong declaration, it should be
If this doesn't help. please check that your fileTypeConsumer is really called.
Alright I think that worked finally! Thank you so much. Just for future reference, how should I go about debugging in the Ultimate Edition, do I just create an SDK with the Ultimate Edition and debug from there? I could have sworn in the documentation it said you could only debug with the community edition and adding the sources. Thanks again!
Great! No idea about debugging though.. a simple System.println can help here, too :-)
Hey nothing like a good old System.out.println(); :D
Thanks again for the help!