简体   繁体   English

进行扩展是 VSCode 仅适用于特定语言吗?

[英]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:让我以更技术的方式解释它:

Current behavior:当前行为:

If I open a Plain Text file in VSCode and type do end the extension will underline it.如果我在 VSCode 中打开纯文本文件并键入do end ,则扩展名将在其下划线。

Expected behavior:预期行为:

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.它必须在.rbdo 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.

相关问题 我对JQuery所做的更改只能暂时起作用 - Changes I make with JQuery only work temporarily 是否可以强制执行仅适用于特定HTTP方法的控制器方法? - Is it possible to enforce a controller method to work only for specific HTTP methods? 如何使部分代码仅针对特定集合显示 - How to make partial show some code only for specific collection Rails 4-如何仅在第一次单击复选框时使回调起作用? - Rails 4 - How to make a callback work only the first time a checkbox is clicked? 仅在用户登录后如何使AJAX工作? -轨道 - How to make an AJAX work only if the user is logged in? -rails 如何使某些属性仅对具有特定角色的用户可访问? - How do I make some attributes accessible only to Users that have a specific role? 如何在仅显示具有特定属性的选项的rails中进行collection_select - How to make a collection_select in rails that only displays options with a specific attribute 仅以特定形式进行验证 - Validation only in specific form 如果有文件扩展名,如何验证文件扩展名? 回复:载波 - How to validate a file extension only if there is a file extension? Re: carrierwave 滑轨| 验证带有特定扩展名的电子邮件地址 - Rails | Validate email address wth specific extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM