Make an extension is VSCode work only with specific languages?

Viewed 163

I have recently installed an extension in VSCode that I find very useful for my workflow.

The extension is available at 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.

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). I would like it to work only in .rb and .html.erb files.

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.

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. It has to underline do end o̲n̲l̲y̲ in .rb and .html.erb files.


Thank you

1 Answers

Look at language onActivation events.

In your package.json file:

"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.


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).

Related