38

I'm creating a Grails app in IntelliJ 10 and have a javascript file that is created dynamically, as a Grails view.

For that reason the javascript file doesn't end in '.js'. It ends in '.gsp' because it's a Groovy Server Page that spits out javascript.

IntelliJ doesn't know it's a javascript file so it doesn't give me code completion or warnings.

I want my code complete and syntax checking! Is there a way to force IntelliJ to treat this specific file as Javascript, WITHOUT messing up the IntelliJ's correct treatment of .gsp files everywhere else?

Thanks!

Dean Moses
  • 2,372
  • 2
  • 24
  • 36

2 Answers2

43

The above answer is slightly outdated. You can do the same in IntelliJ 14 by doing the following:

  1. Go to Preferences (Mac OSX : Cmd + Comma)
  2. Under Editor -> File Types
  3. In the Recognized File Types Highlight JavaScript files (JavaScript)
  4. Under Registered Patterns press the + button
  5. Enter your regex pattern (for example: *.js.scala.html) and press OK

Cheers!

Monarch Wadia
  • 4,400
  • 4
  • 36
  • 37
  • 1
    It may work for other Jetbrains products as well... Jetbrain's other IDE's are PhpStorm, PyCharm, RubyMine, AppCode and CLion (mentioning them here so people might stumble upon this answer) – Monarch Wadia Oct 12 '15 at 01:40
  • Also, if you accidentally added a wrong file association for a specific file (like plain text after forgetting the extension), you can find it and remove it from one of the lists under File Types. – Micros Mar 06 '18 at 16:50
  • 1
    Another case: you create a new file without an extension, accept default type assignment (text) for what Intellij thinks is some new type of file. Later you decide to add the extension and somehow agree to adding the new filename to map to text type (in a hurry...?), You wonder why the file will not display code formatting! Add the exact filename to the fileType you want to map it to and Intellij will ask you if you want to remap it from the previous type is was set to (probably text), agree, apply, and then you can delete it if you want. – davidjmcclelland Apr 01 '19 at 19:09
22

You can add additional extensions to the JavaScript in Settings (Preferences on Mac) | File Types.

enter image description here

See also Settings | Template Data Languages where you can configure certain files in the project as templates producing specified language to get proper code completion.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904