问题
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!
回答1:
The above answer is slightly outdated. You can do the same in IntelliJ 14 by doing the following:
- Go to
Preferences(Mac OSX : Cmd + Comma) - Under
Editor -> File Types - In the
Recognized File TypesHighlightJavaScript files (JavaScript) - Under
Registered Patternspress the+button - Enter your regex pattern (for example:
*.js.scala.html) and press OK
Cheers!
回答2:
You can add additional extensions to the JavaScript in Settings (Preferences on Mac) | File Types.
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.
来源:https://stackoverflow.com/questions/5790402/intellij-how-to-force-editor-to-treat-a-file-as-javascript