Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: how to force editor to treat a file as javascript?

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!

like image 960
Dean Moses Avatar asked Apr 26 '11 12:04

Dean Moses


People also ask

How do I enable JavaScript in IntelliJ?

Open the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Inlay Hints, and select the checkbox next to JavaScript. On the JavaScript page below, specify what hints and in what context you want IntelliJ IDEA to display.

How do I change a read only file in IntelliJ?

To toggle read-only attribute of a file, open file in the editor, or select it in the Project tool window. Do one of the following: On the main menu, choose File | File Properties | Make File Read-Only , or Make File Writable .


1 Answers

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!

like image 53
Monarch Wadia Avatar answered Oct 10 '22 01:10

Monarch Wadia