IntelliJ:如何强制编辑器将文件视为javascript? [英] IntelliJ: how to force editor to treat a file as javascript?
问题描述
我正在IntelliJ 10中创建一个Grails应用程序,并且有一个动态创建的javascript文件,作为Grails视图。
I'm creating a Grails app in IntelliJ 10 and have a javascript file that is created dynamically, as a Grails view.
因此javascript文件没有结束'.js'。它以'.gsp'结尾,因为它是一个吐出javascript的Groovy服务器页面。
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不知道它是一个javascript文件所以它不给我代码完成或警告。
IntelliJ doesn't know it's a javascript file so it doesn't give me code completion or warnings.
我希望我的代码完整并进行语法检查!有没有办法强制IntelliJ将此特定文件视为Javascript,而不会搞乱IntelliJ对其他地方.gsp文件的正确处理?
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?
谢谢!
推荐答案
上述答案略显过时。您可以通过执行以下操作在IntelliJ 14中执行相同的操作:
The above answer is slightly outdated. You can do the same in IntelliJ 14 by doing the following:
- 转到
首选项
(Mac OSX:Cmd +逗号) - 在
编辑器 - >下;文件类型
- 在
已识别的文件类型中
突出显示JavaScript文件(JavaScript)
- 在
注册模式下
按+
按钮 - 输入您的正则表达式模式(例如:
* .js.scala.html
)并按OK
- Go to
Preferences
(Mac OSX : Cmd + Comma) - Under
Editor -> File Types
- In the
Recognized File Types
HighlightJavaScript files (JavaScript)
- Under
Registered Patterns
press the+
button - Enter your regex pattern (for example:
*.js.scala.html
) and press OK
干杯!
这篇关于IntelliJ:如何强制编辑器将文件视为javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!