Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make IntelliJ prominently display Groovy/Grails syntax errors

I'm using IntelliJ IDEA 13 to edit my Grails application and while it is very smart about some things, it doesn't display syntax errors very well.

E.g., I can misspell a property or method name, but IntelliJ shows a mellow barely noticeable black underline in code with the on-hover popup saying Cannot resolve symbol 'foobar'.

If I go into View -> Tool Windows -> Messages then it doesn't even show this issue, even after Build -> Rebuild project (although it shows some useless deprecation messages in 3rd party plugin code).

How do I find a view showing all these potential issues so I can review them?

Edit - @lukelazarovic is totally right, I fixed a significant misconception about how Groovy/Grails works. Also question was partially covered by:

Will groovy (grails) give you compile time checking like java?

like image 425
John M Avatar asked Dec 10 '13 09:12

John M


People also ask

How do I enable Groovy in IntelliJ?

In the Project tool window, right-click the project and from the context menu, select Add Framework Support. In the dialog that opens, select Groovy and click OK. IntelliJ IDEA adds the Groovy SDK to your project and you can add Groovy classes and Groovy scripts.

Does IntelliJ support Groovy?

Groovy The Groovy plugin is bundled with IntelliJ IDEA and enabled by default. IntelliJ IDEA supports the latest stable version of Groovy and Groovy 4 syntax.

Does PyCharm support Groovy?

You can't associate Jenkinsfile with Groovy in PyCharm, but you can associate them with Java.


Video Answer


2 Answers

Here what I've got so far:

Idea inspections should be a way to go. You can set them by right click on the project -> Analyze -> Inspect code ... and there is inspection profile selection which opens Inspections window.

There you can choose what inspections you'd like to run on your codebase and the severity of each inspection.

Go to Groovy -> Probable bugs -> Access to unresolved expression inspection and set the severity to Error.

Now you should see misspelled property or method name not with barely noticeable black underline but with red color, indicating error.

But what makes me mad is that I can't force Idea to show these errors in the results if you run Analyze on whole projects. It shows all the other inspection errors but not this one.

like image 134
lukelazarovic Avatar answered Oct 03 '22 22:10

lukelazarovic


First some background information... IDEA only shows compile errors in the project tool window and in the Problems view. You can open a feature request asking that non-compile errors also show in these views.

Non-compile issues are discovered and shown via "Inspections". Failed inspections are fixed via "Intentions" (a.k.a. "Quick Fixes"). IDEA uses Inspection Profiles in which you can set what inspections are active and what severity level to show a failure of that inspection. You can define multiple profiles if desired. One of these profiles is set as the profile to use in the editor (F*ile > Settings > [Project Settings] > Inspections*). You can then (as you note) run an inspection profile (either the same one used in the editor or a different one) via Analyze > Inspect Code. You can also run a single inspection via Analyze > Run inspection by name.

IntelliJ shows a mellow barely noticeable black underline in code

If you do not think the issue shows prominently enough, you have three options (some of which you have partially discovered):

  1. Change the severity level of the inspection reporting the problem, including creating a new custom level. Different severity levels use different highlighting styles to display
  2. Modify the formatting (i.e. colors and style) of how IDEA displays a severity level
  3. A combination of 1 & 2

Steps:

  1. Place your cursor on the highlighted problem.
  2. Type Alt+Enter () to "Show Intention Actions"
  3. In the popup will be the name of the inspection that is reporting the problem or one or more intentions to fix it. Select one and open the side menu via the right arrow
  4. Select "Edit Inspection Profile Setting"
  5. This will open the inspections setting dialog with the inspection in question selected
    • You can also get to this dialog via File > Settings > Inspections
  6. Change the severity level of the inspection, and/or click the Ellipsis … button to create a custom setting or modify a severity level's color and style
    • Color and Style settings for severity levels can also be opened via File > Settings > [IDE Settings] > Editor > Color & Fonts > General and then selecting the severity (such as "error" or "info") in the list
    • Modifying a severity level's color & style affects all inspections set to that severity level.

There you can choose what inspections you'd like to run on your codebase and the severity of each inspection.

Just for clarification, the severity will determine how the inspections shows in the editor then the profile is used for the editor's inspection profile. When doing a code analysis, the main purpose for the severity is for grouping and filtering inspections in the output tool window. In general, its easiest to have a profile predefined that you use when you want to manually run a code inspection. Of course, you can use the same profile you have defined to be used in the editor.

But what makes me mad is that I can't force Idea to show these errors in the results if you run Analyze on whole projects. It shows all the other inspection errors but not this one.

All inspections defined (i.e. active) in the executed profile should be shown. The fact that the Groovy "access to unresolved expression" inspection is an apparent bug. I recommend opening a bug report for it.

like image 45
Javaru Avatar answered Oct 03 '22 22:10

Javaru