When working with Visual Studio Code and different types of languages, you might want to change some settings only for one specific language.
In my case, this was what I wanted to achieve for Markdown. VSCode is my primary editor, which I use for coding and writing this article. I tried to optimize it for writing blog posts, like increase the line height, different font, and more.
The manual approach
You can add Language-specific settings in VSCode, by opening your settings.json
file and specifying a language property name. You do this by using the square brackets []
and writing the language ID you want to target.
In my case, I went for the following settings for my Markdown-specific project settings:
|
|
The extension approach
To achieve the same from within your extension, you will have to use the getConfiguration
method. You usually use the getConfiguration
method to retrieve the config settings of your extension by specifying the section
name. When you want to do a language-specific setting, you need to set an empty string for the section
name and specify the languageId
. The looks as follows:
|
|
Once you have the config
object and want to set a new setting value, you use the update
method as follows:
|
|
ImportantThe third parameter in the above code snippet is the most important one.
You can use the get
method as you would normally use it:
|
|