Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Idea Ultimate red-underlines Ruby shorthand hash literal

Anybody know why IntelliJ Idea Ultimate doesn't like Ruby hash literals in the newer syntax? Refer to the red underlines in my screenshot from the IDE below. Syntax:

{key1: "value", key2: 123}

Really annoying as it means my entire project has a red underline all the way up the directory tree.

I have setup a Ruby SDK version greater than 1.9 (which is when i think the new hash literal syntax was introduced) in the IDE preferences, so there is no excuse!

Thanks.

Screenshot from IntelliJ Ultimate

like image 251
Robin Smith Avatar asked Sep 29 '14 06:09

Robin Smith


3 Answers

How I fixed this in Intellij 14.1:

  1. File -> Project Structure
  2. Delete the existing module which defaulted to Java (doesn't delete the actual files)
  3. Use green + button to create a new module with same name/location, but this time associated with Ruby on Rails instead of Java (with correct SDK)
  4. File -> Close Project
  5. Reopen project.

Previously I tried just changing the project SDK from the default of Java to Ruby, but this didn't fix the issue.

like image 69
Ryan Avatar answered Nov 13 '22 22:11

Ryan


Under OSX IntelliJ 14 I was able to fix this by closing the project and reopening it.

In fairness, I did try setting the project's "language level", but it only shows Java SDKs, which shouldn't affect my main Ruby module.

like image 3
Dave Newton Avatar answered Nov 13 '22 23:11

Dave Newton


This seems to be a bug in the Ruby plugin: http://devnet.jetbrains.com/thread/457333

Anyone who doesn't feel like changing his code base, the following steps resolved the issue for me:

  • Open File -> Project Structure
  • Open the Project Tab
  • Change the Project Language Level
  • Click OK

IntelliJ now asks if you would like to reload your project. After doing so the "new" Hash Syntax is considered correct...

Edit: It doesn't really matter what you select as language level as it is only relevant for Java code, but apparently this triggers something in the code parser...

like image 3
dsager Avatar answered Nov 13 '22 21:11

dsager