IntelliJ:如何强制编辑器将文件视为 javascript?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5790402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ: how to force editor to treat a file as javascript?
提问by Dean Moses
I'm creating a Grails app in IntelliJ 10 and have a javascript file that is created dynamically, as a Grails view.
我正在 IntelliJ 10 中创建一个 Grails 应用程序,并有一个动态创建的 javascript 文件,作为 Grails 视图。
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.
因此,javascript 文件不会以“.js”结尾。它以“.gsp”结尾,因为它是一个吐出 javascript 的 Groovy 服务器页面。
IntelliJ doesn't know it's a javascript file so it doesn't give me code completion or warnings.
IntelliJ 不知道它是一个 javascript 文件,因此它不会给我代码完成或警告。
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 将此特定文件视为 Javascript,而不会在其他地方搞乱 IntelliJ 对 .gsp 文件的正确处理?
Thanks!
谢谢!
回答by Monarch Wadia
The above answer is slightly outdated. You can do the same in IntelliJ 14 by doing the following:
上面的答案有点过时了。您可以通过执行以下操作在 IntelliJ 14 中执行相同的操作:
- 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
- 转到
Preferences
(Mac OSX:Cmd + 逗号) - 在下面
Editor -> File Types
- 在
Recognized File Types
亮点JavaScript files (JavaScript)
- 在
Registered Patterns
按下+
按钮 - 输入您的正则表达式模式(例如:)
*.js.scala.html
并按 OK
Cheers!
干杯!
回答by CrazyCoder
You can add additional extensions to the JavaScriptin Settings
(Preferences
on Mac) | File Types
.
您可以在(在 Mac 上) | 中向JavaScript添加其他扩展。.Settings
Preferences
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.
另见Settings
| Template Data Languages
您可以在其中将项目中的某些文件配置为生成指定语言的模板,以获得正确的代码完成。