You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow Extensions To Contribute Language Specific Settings #26707
Allow extensions to mark settings as being valid language specific settings.
Add apis for better working with language specific settings
Reacted by Ramya Rao, James Harris, Jon Gjengset, Ivan Kuznetsov, Cyril Junod, Joan Llenas, Henning Pohlmeyer, Jeremy Chone, Lucas Azzola, Matt Downs and 39 more
It'd be really neat if the flow worked the other way: if the extension didn't need to know about what language is currently being used, but instead vscode simply changed the setting appropriately for the extension when a file of a different type was opened. That would mean that things like vim.textwidth could also be set. Of course, this has the drawback of not being able to support multiple languages inside a single file, but it's not clear that that's something the vim extension for example cares about..
Matt Bierner (@mjbvz) Ignore my earlier comment, I misunderstood with configuration defaults.
Yes, Currently only editor settings are supported as lang specific settings.
It'd be really neat if the flow worked the other way: if the extension didn't need to know about what language is currently being used, but instead vscode simply changed the setting appropriately for the extension when a file of a different type was opened. That would mean that things like vim.textwidth could also be set.
I don't think this would work very well as you can have multiple files open side-by-side (there may also be side effects of firing config change events frequently if extensions currently only expect them to happen infrequently). I think it'd be much better to design something sane and have cooperation of extensions than try to make it work transparently.
On a side note, it might be good to add something to the doc. Took me a while to understand how to allow per language customization for my extension. Thanks to Matt Bierner (@mjbvz) for this useful example.
Json validation/intellisense might be hard to solve (I am not familiar with Json schema), but adding a workspace.getConfiguration signature with languageId or Editor as argument would be pretty neat.
Sandeep Somavarapu (@sandy081) I was maybe confused with your comment, so if this feature request has nothing to do with contributes.configurationDefaults then my comment is indeed off-topic.
I think above proposal makes sense if WorkspaceConfiguration object is not scoped. Since this can be scoped to resource or languageId or both, it will take two steps process to access scoped language values. Eg: workspaceConfiguration.inspect(key).languages[scopedLanguage].defaultValue. Also this is not consistent with resource scope. Inspect is not returning workspaceFolderValues for all workspace folders. Hence I would suggest following:
This is consistent with inspecting resource scope. Inspect result provides all languages in which the key is configured at. One can get the language values by scoping WorkspaceConfiguration for the language.
After writing doc, preferred to have slim inspectAPI with language values for requested language and language ids under which the configuration is defined at. This structure also makes it easy to explain how an effective value is computed.
Final Solution
Introduced language-overridable scope to define a a language overridable configuration that can be configured in user, workspace and folder settings.
API
exporttypeConfigurationScope=Uri|TextDocument|WorkspaceFolder|{uri?: Uri,languageId: string};/** * An event describing the change in Configuration */exportinterfaceConfigurationChangeEvent{/** * Returns `true` if the given section is affected in the provided scope. * * @param section Configuration name, supports _dotted_ names. * @param scope A scope in which to check. * @return `true` if the given section is affected in the provided scope. */affectsConfiguration(section: string,scope?: ConfigurationScope): boolean;}exportnamespaceworkspace{/** * Get a workspace configuration object. * * When a section-identifier is provided only that part of the configuration * is returned. Dots in the section-identifier are interpreted as child-access, * like `{ myExt: { setting: { doIt: true }}}` and `getConfiguration('myExt.setting').get('doIt') === true`. * * When a scope is provided configuraiton confined to that scope is returned. Scope can be a resource or a language identifier or both. * * @param section A dot-separated identifier. * @return The full configuration or a subset. */exportfunctiongetConfiguration(section?: string|undefined,scope?: ConfigurationScope|null): WorkspaceConfiguration;}/** * Represents the configuration. It is a merged view of * * - *Default Settings* * - *Global (User) Settings* * - *Workspace settings* * - *Workspace Folder settings* - From one of the [Workspace Folders](#workspace.workspaceFolders) under which requested resource belongs to. * - *Language settings* - Settings defined under requested language. * * The *effective* value (returned by [`get`](#WorkspaceConfiguration.get)) is computed by overriding or merging the values in the following order. * * ``` * `defaultValue` * `globalValue` (if defined) * `workspaceValue` (if defined) * `workspaceFolderValue` (if defined) * `defaultLanguageValue` (if defined) * `globalLanguageValue` (if defined) * `workspaceLanguageValue` (if defined) * `workspaceLanguageValue` (if defined) * ``` * **Note:** Only `object` value types are merged and all other value types are overridden. * * Example 1: Overriding * * ```ts * defaultValue = 'on'; * globalValue = 'relative' * workspaceFolderValue = 'off' * value = 'off' * ``` * * Example 2: Language Values * * ```ts * defaultValue = 'on'; * globalValue = 'relative' * workspaceFolderValue = 'off' * globalLanguageValue = 'on' * value = 'on' * ``` * * Example 3: Object Values * * ```ts * defaultValue = { "a": 1, "b": 2 }; * globalValue = { "b": 3, "c": 4 }; * value = { "a": 1, "b": 3, "c": 4 }; * ``` * * *Note:* Workspace and Workspace Folder configurations contains `launch` and `tasks` settings. Their basename will be * part of the section identifier. The following snippets shows how to retrieve all configurations * from `launch.json`: * * ```ts * // launch.json configuration * const config = workspace.getConfiguration('launch', vscode.workspace.workspaceFolders[0].uri); * * // retrieve values * const values = config.get('configurations'); * ``` * * Refer to [Settings](https://code.visualstudio.com/docs/getstarted/settings) for more information. */exportinterfaceWorkspaceConfiguration{/** * Return a value from this configuration. * * @param section Configuration name, supports _dotted_ names. * @return The value `section` denotes or `undefined`. */get<T>(section: string): T|undefined;/** * Return a value from this configuration. * * @param section Configuration name, supports _dotted_ names. * @param defaultValue A value should be returned when no value could be found, is `undefined`. * @return The value `section` denotes or the default. */get<T>(section: string,defaultValue: T): T;/** * Check if this configuration has a certain value. * * @param section Configuration name, supports _dotted_ names. * @return `true` if the section doesn't resolve to `undefined`. */has(section: string): boolean;/** * Retrieve all information about a configuration setting. A configuration value * often consists of a *default* value, a global or installation-wide value, * a workspace-specific value, folder-specific value * and language-specific values (if [WorkspaceConfiguration](#WorkspaceConfiguration) is scoped to a language). * * Also provides all language ids under which the given configuration setting is defined. * * *Note:* The configuration name must denote a leaf in the configuration tree * (`editor.fontSize` vs `editor`) otherwise no result is returned. * * @param section Configuration name, supports _dotted_ names. * @return Information about a configuration setting or `undefined`. */inspect<T>(section: string): {key: string;defaultValue?: T;globalValue?: T;workspaceValue?: T,workspaceFolderValue?: T,defaultLanguageValue?: T;userLanguageValue?: T;workspaceLanguageValue?: T;workspaceFolderLanguageValue?: T;languageIds?: string[];}|undefined;/** * Update a configuration value. The updated configuration values are persisted. * * A value can be changed in * * - [Global settings](#ConfigurationTarget.Global): Changes the value for all instances of the editor. * - [Workspace settings](#ConfigurationTarget.Workspace): Changes the value for current workspace, if available. * - [Workspace folder settings](#ConfigurationTarget.WorkspaceFolder): Changes the value for settings from one of the [Workspace Folders](#workspace.workspaceFolders) under which the requested resource belongs to. * - Language settings: Changes the value for the requested languageId. * * *Note:* To remove a configuration value use `undefined`, like so: `config.update('somekey', undefined)` * * @param section Configuration name, supports _dotted_ names. * @param value The new value. * @param configurationTarget The [configuration target](#ConfigurationTarget) or a boolean value. * - If `true` updates [Global settings](#ConfigurationTarget.Global). * - If `false` updates [Workspace settings](#ConfigurationTarget.Workspace). * - If `undefined` or `null` updates to [Workspace folder settings](#ConfigurationTarget.WorkspaceFolder) if configuration is resource specific, * otherwise to [Workspace settings](#ConfigurationTarget.Workspace). * @param scopeToLanguage Whether to update the value in the scope of requested languageId or not. * - If `true` updates the value under the requested languageId. * - If `undefined` updates the value under the requested languageId only if the configuration is defined for the language. * @throws error while updating * - configuration which is not registered. * - window configuration to workspace folder * - configuration to workspace or workspace folder when no workspace is opened. * - configuration to workspace folder when there is no workspace folder settings. * - configuration to workspace folder when [WorkspaceConfiguration](#WorkspaceConfiguration) is not scoped to a resource. */update(section: string,value: any,configurationTarget?: ConfigurationTarget|boolean,scopeToLanguage?: boolean): Thenable<void>;/** * Readable dictionary that backs this configuration. */readonly[key: string]: any;}
Sandeep Somavarapu (@sandy081), ok thanks!
One Question: How can I get the current setting in my extension (or the global one?
Currently, I read it with
Sandeep Somavarapu (@sandy081), sorry, but nothing worked for language-specific configuration.
VSC stable and preview (both v1.42.0) raised an error, that a proposed API is used:
Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ...
Activity
jonhoo commentedon May 16, 2017
It'd be really neat if the flow worked the other way: if the extension didn't need to know about what language is currently being used, but instead vscode simply changed the setting appropriately for the extension when a file of a different type was opened. That would mean that things like
vim.textwidthcould also be set. Of course, this has the drawback of not being able to support multiple languages inside a single file, but it's not clear that that's something thevimextension for example cares about..sandy081 commentedon May 22, 2017
Matt Bierner (@mjbvz) You can contribute default language specific settings as follows
Above should work.
Regarding API, agreed that we need better support there.
sandy081 commentedon May 22, 2017
Matt Bierner (@mjbvz) Ignore my earlier comment, I misunderstood with configuration defaults.
Yes, Currently only editor settings are supported as lang specific settings.
DanTup commentedon May 22, 2017
I don't think this would work very well as you can have multiple files open side-by-side (there may also be side effects of firing config change events frequently if extensions currently only expect them to happen infrequently). I think it'd be much better to design something sane and have cooperation of extensions than try to make it work transparently.
jeremychone commentedon Nov 5, 2017
On a side note, it might be good to add something to the doc. Took me a while to understand how to allow per language customization for my extension. Thanks to Matt Bierner (@mjbvz) for this useful example.
Json validation/intellisense might be hard to solve (I am not familiar with Json schema), but adding a
workspace.getConfigurationsignature with languageId or Editor as argument would be pretty neat.blfpd commentedon Jul 19, 2018
Something that I would love the most for extensions would be
"files.associations":sandy081 commentedon Jul 23, 2018
@batisteo How is your comment is related to this feature request?
blfpd commentedon Jul 23, 2018
Sandeep Somavarapu (@sandy081) I was maybe confused with your comment, so if this feature request has nothing to do with
contributes.configurationDefaultsthen my comment is indeed off-topic.sandy081 commentedon Jul 24, 2018
@batisteo So you want
files.associationssetting to be language specific?24 remaining items
eamodio commentedon Jan 8, 2020
I was more thinking something like:
or
sandy081 commentedon Jan 9, 2020
I think above proposal makes sense if
WorkspaceConfigurationobject is not scoped. Since this can be scoped to resource or languageId or both, it will take two steps process to access scoped language values. Eg:workspaceConfiguration.inspect(key).languages[scopedLanguage].defaultValue. Also this is not consistent withresourcescope. Inspect is not returningworkspaceFolderValues for all workspace folders. Hence I would suggest following:This is consistent with inspecting resource scope. Inspect result provides all languages in which the key is configured at. One can get the language values by scoping
WorkspaceConfigurationfor the language.#26707 Inspect returns languages
sandy081 commentedon Jan 20, 2020
After writing doc, preferred to have slim
inspectAPI with language values for requested language and language ids under which the configuration is defined at. This structure also makes it easy to explain how an effective value is computed.Final Solution
Introduced
language-overridablescope to define a a language overridable configuration that can be configured in user, workspace and folder settings.API
Example
DoCode commentedon Feb 6, 2020
Sandeep Somavarapu (@sandy081), is this currently in nightly builds (v1.42.0)?
sandy081 commentedon Feb 6, 2020
Yes and will be available in next stable (v1.42.0)
DoCode commentedon Feb 6, 2020
Sandeep Somavarapu (@sandy081), ok thanks!
One Question: How can I get the current setting in my extension (or the global one?
Currently, I read it with
and this doesn't work and read only the global one.
sandy081 commentedon Feb 6, 2020
Please refer to sample here - https://github.com/microsoft/vscode-extension-samples/tree/master/configuration-sample
DoCode commentedon Feb 7, 2020
Sandeep Somavarapu (@sandy081), sorry, but nothing worked for language-specific configuration.
VSC stable and preview (both v1.42.0) raised an error, that a proposed API is used:
The code is simple:
sandy081 commentedon Feb 7, 2020
My bad it is still under proposed API check.
#90201
Remove per-language text width