Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Handling of Settings Sections #9255

Open
colin-grant-work opened this issue Mar 25, 2021 · 0 comments
Open

Better Handling of Settings Sections #9255

colin-grant-work opened this issue Mar 25, 2021 · 0 comments
Labels
preferences issues related to preferences

Comments

@colin-grant-work
Copy link
Contributor

colin-grant-work commented Mar 25, 2021

Feature Description:

At the moment we use the same classes to handle JSON files for all of our settings sections (settings, tasks, launch), and all of them can be reached using the .set and .get methods of the PreferenceService. As a consequence, we've introduced logic that analysis the preference name string fed to those methods and directs the call to the appropriate file handler. For example:

async setPreference(preferenceName: string, value: any, resourceUri?: string): Promise<boolean> {
const sectionName = preferenceName.split('.', 1)[0];
const configName = this.configurations.isSectionName(sectionName) ? sectionName : this.configurations.getConfigName();

async setPreference(preferenceName: string, value: any, resourceUri?: string): Promise<boolean> {
const sectionName = preferenceName.split('.', 1)[0];
const configName = this.configurations.isSectionName(sectionName) ? sectionName : this.configurations.getConfigName();

protected getPath(preferenceName: string): string[] {
const firstSegment = preferenceName.split('.')[0];
if (firstSegment && this.configurations.isSectionName(firstSegment)) {

protected getPath(preferenceName: string): string[] | undefined {
if (!this.isSection) {
return super.getPath(preferenceName);
}
if (preferenceName === this.section) {
return [];
}
if (preferenceName.startsWith(`${this.section}.`)) {
return [preferenceName.slice(this.section.length + 1)];
}
return undefined;

One consequence of this approach is that we cannot easily handle preferences (that belong in settings.json) with the same prefix as a section. For tasks and launch, that isn't generally a problem because the prefix for settings is different from the file name: task rather than tasks, debug rather than launch. However, VSCode also supports an extensions.json file and several preferences with the prefix extensions, and our system cannot correctly handle those settings. If we support extensions.json, then extensions.ignoreRecommendations will be treated as the ignoreRecommendations field of the object in extensions.json rather than the extensions.ignoreRecommendations key of the object in settings.json.

The cleanest solution would be to modify our .set and .get methods to include the section name as an explicit argument (defaulting to settings) or to introduce alternative .getFromSection and .setInSection methods that would include such an argument. If those were used across the board, we could also dispense with some of the logic (dangerously) extracting the section name from the single preference name argument.

@colin-grant-work colin-grant-work added the preferences issues related to preferences label Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preferences issues related to preferences
Projects
None yet
Development

No branches or pull requests

1 participant