Grammar-Kit and older versions of IDEA
At work we currently only have licenses for IDEA 12.x and are unlikely to upgrade this year. At home I use IDEA CE 13.x for my own development. In particular I've been working on a custom language plugin that will help one aspect of our development process dramatically. IDEA 12.x can only seem to use a plugin generated with Grammar-Kit 1.1.2 while IDEA 13.x is able to use the latest-and-greatest version. Right now my process is to delete the generated files, make the slight adjustments required to work with the older version, re-generate the parser, and build the plugin, but obviously I'd prefer to avoid that.
Obviously I could point my IDEA CE 13.x at the older version of Grammar-Kit and the older IDEA plugin SDK, but before I do that I wanted to see if perhaps there's some better way to write custom language plugins in the latest version of IDEA that are compatible with older versions of IDEA (not looking for anything earlier than the latest patch of 12.x). Thoughts?
Please sign in to leave a comment.
Scott,
Certain compilation erros will arise and have to be addressed on the described path but it is all doable.
1. First, you'll need to get the latest Grammar-Kit sources from github and build the plugin with any IDEA installation as "IntelliJ Platform SDK".
(It is far better than trying employ some outdated version of the plugin. Lots of fixes were implemented since IDEA 12 time.)
2. Then, to make the generated parser compile, you will need to use the latest GeneratedParserUtilBase.java from Grammar-Kit sources. It has to be specified in the grammar file ("parserUtilClass" attribute).
Another solution is to employ IDEA 14 CE, no paid license required.
Thanks for the info. I haven't yet tried building my own GK plugin but could certainly give that a while. I do have things working pretty well using the IDEA 12.x plugin under IDEA 13.x against the IDEA 12.x SDK. The resulting plugin works properly for IDEA 12.x+, but as you pointed out, the newer versions of GK have addressed some issues that I'm seeing, e.g., an unbalanced tree issue during recovery.
As for requiring users to have a more recent version of IDEA CE, that's a non-starter. Even using our own internal developers as a litmus test, we use Perforce for our SCM and there's no good way to use CE against it. I'd rather have my custom language plugin support the version for which we (and many others) are licensed.
I'll look into building my own GK...that's a solid suggestion! Thanks again!
Okay, so I looked into this today and the going is a little rocky so far. I pulled down the latest source from git (should I pull from a label such as 1.1.10_1?) and have been trying to build it. To do so, I've set up IDEA CE 13 against IDEA CE 12's SDK. When I first tried to build the plugin, it complained about missing diagram sources which appear to be associated with IDEA Ultimate's UML feature, so I removed the reference from plugin.xml, removed plugin-uml.xml, and removed BnfDiagramProvider.java. The next issue I hit was that com.sun.jdi was missing, but I figured out that I just add the JDK's tools.jar to the classpath.
Now when I try to build using IDEA 12's SDK, I get all kinds of compilation errors about missing symbols like CaretAdapter, Contract, etc. When I try to build using IDEA 13's SDK, it gets further but it still fails with errors like the following:
Error:(201, 50) java: constructor DumbServiceImpl in class com.intellij.openapi.project.DumbServiceImpl cannot be applied to given types;
required: com.intellij.openapi.project.Project,com.intellij.util.messages.MessageBus
found: com.intellij.mock.MockProjectEx
reason: actual and formal argument lists differ in length
Error:(236, 20) java: constructor ProgressManagerImpl in class com.intellij.openapi.progress.impl.ProgressManagerImpl cannot be applied to given types;
required: com.intellij.openapi.application.Application
found: no arguments
reason: actual and formal argument lists differ in length
Error:(260, 35) java: cannot find symbol
symbol: variable HARD_REF_TO_DOCUMENT_KEY
location: class com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl
Before I continue to make changes, I wanted to make sure I'm even going the right direction here. Am I making this too difficult and there's a much more straightforward local build process?
Thanks!
Hmmm...I think I have a working solution to this now. I grabbed GeneratedParserUtilBase from IDEA 13 and set up my grammar to use it instead of the one in the IDEA 12 SDK. I had to make one small change to the file to allow current_position_(PsiBuilder) to work. Basically that ends up calling PsiBuilderImpl to retrieve the current value of myCurrentLexeme, but in IDEA 12 that's not exposed. I just changed the implementation of that method to use reflection to access the value (VERY defensively!). Once I regenerated my parser classes and of course the jar, it appears that everything works properly (in fact, better!) in IDEA 12 with a plugin built using the latest version of Grammar-Kit. I'll keep hammering on it a bit, but a reasonable pass over some fairly complex source files shows positive results.
Thanks again!