[英]Make an extension is VSCode work only with specific languages?
I have recently installed an extension in VSCode that I find very useful for my workflow.我最近在 VSCode 中安装了一个扩展,我发现它对我的工作流程非常有用。
The extension is available at This Repository .该扩展可在This Repository获得。 It lets you underline the beginning and ending syntax of code blocks, and I find it to be really useful for working in html.erb files since VSCode doesn't do a really good job at highlighting certain snippets of code.
它可以让你强调代码块的开始和结束语法,我发现它对于在 html.erb 文件中工作非常有用,因为 VSCode 在突出显示某些代码片段方面做得并不好。
Is there a way to make the extension work only in specific languages or specific file types?有没有办法让扩展只在特定语言或特定文件类型中工作? Currently it works globally, even on plain text (for example if I type "do end" it will underline it even if I'm not in ruby language or in a
.rb
file).目前它可以在全球范围内使用,即使是纯文本(例如,如果我输入“do end”,即使我不是在 ruby 语言或
.rb
文件中,它也会给它加下划线)。 I would like it to work only in .rb
and .html.erb
files.我希望它仅适用于
.rb
和.html.erb
文件。
Let me explain it in a more technical way:让我以更技术的方式解释它:
If I open a Plain Text file in VSCode and type do end
the extension will underline it.如果我在 VSCode 中打开纯文本文件并键入
do end
,则扩展名将在其下划线。
If I open a Plain Text file in VSCode and type do end
the extension d̲o̲e̲s̲ ̲n̲o̲t̲ have to underline it.如果我在 VSCode 中打开纯文本文件并键入
do end
扩展名 d̲o̲e̲s̲ ̲n̲o̲t̲ 必须在其下划线。 It has to underline do end
o̲n̲l̲y̲ in .rb
and .html.erb
files.它必须在
.rb
和do end
文件中为.html.erb
加下划线。
Thank you谢谢
Look at language onActivation events .查看语言 onActivation 事件。
In your package.json
file:在您的
package.json
文件中:
"activationEvents": [
"onLanguage:ruby",
"onLanguage: whatever the languageID for .html.erb files is"
]
Replace with your language identifiers for .rb
and .html.erb
files, you can have multiple onLanguage
events as shown.替换为
.rb
和.html.erb
文件的语言标识符,您可以有多个onLanguage
事件,如图所示。
Also, looking at the extension's package.json
link you provided, you should remove the activationEvent
"*"
- so only the above (I don't know what the language identifier for .html.erb
files is).此外,查看您提供的扩展程序的
package.json
链接,您应该删除activationEvent
"*"
- 所以只有上面的(我不知道.html.erb
文件的语言标识符是什么)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.