Creating a LocalInspection for go.mod files Follow
Answered
In our plugin we have created several Code Inspections for different file types.
Example for how we created them:
- plugin.xml: https://github.com/jfrog/jfrog-idea-plugin/blob/master/src/main/resources/META-INF/plugin.xml#L51
- Extending LocalInspectionTool: https://github.com/jfrog/jfrog-idea-plugin/blob/master/src/main/java/com/jfrog/ide/idea/inspections/AbstractInspection.java#L33
- JSON inspector: https://github.com/jfrog/jfrog-idea-plugin/blob/master/src/main/java/com/jfrog/ide/idea/inspections/NpmInspection.java#L32
We need to create an inspector for go.mod files.
What should be used in plugin.xml as a language under localInspection tag?
What is the correct visitor (extending PsiElementVisitor) to be used in this case?
Please sign in to leave a comment.
Hi Barb!
First of all, you should refer to the docs related to the GoLand Plugin Development that describes development of the plugin that depends on Go.
go.mod file is specific to the Go language and is supported by the Go plugin.
To enable such local inspection for the .mod files, you have to find out the language name first - so having the Go plugin installed in your development IDE, you can use PsiViewer plugin to inspect .mod file - it says that the language name is vgo (not go, which is for .go files).
So we're going to set:
Now we need the Go classes to be available in our classpath. In the Gradle build file, specify:
Go versions are listed here: https://plugins.jetbrains.com/plugin/9568-go/versions
You should pick the latest version that matches your target IntelliJ SDK.
Now in Plugin's Manifest file (plugin.xml), add:
Basically that's all - your plugin will be dependent on the Go now.
If you want to make the Go dependency optional, modify the go <depends> to:
And move localInspection to this file:
I will also note that you can file an issue in our bug tracker:
https://youtrack.jetbrains.com/issues/GO
Describe what kind of inspection you would like to have for go.mod files. We'll consider your proposal and it might just make to the next EAPs (https://blog.jetbrains.com/go/) or next releases.
Best regards, Ivan Yarkov. GoLand team.
Thanks Jakub! Your explanation helped a lot.
For future purposes (if anyone bumps this thread) I used 'VgoModuleSpec' as the element type in my visitor method.
Ivan, thanks for your suggestion but the inspection I require is kinda unique so no issue here.
It looks like the vgo language disappeared in one of the latest versions of the IntelliJ platform.
Is there another solution for implementing go.mod files custom inspections?
Thanks.