Skip to content

Commit

Permalink
Merge pull request #306 from getgauge/302_recommendedSettings
Browse files Browse the repository at this point in the history
adding option to ignore recommended settings, #302
  • Loading branch information
Apoorva-GA authored Nov 21, 2018
2 parents 4151d7b + 349b2b0 commit 9f99ece
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@
"type": "boolean",
"default": true,
"description": "When true, reference codeLenses appers in implementation files."
},
"gauge.showRecommendedSettings": {
"type": "boolean",
"default": true,
"description": "When true, Gauge recommended settings are shown."
}
}
},
Expand Down
22 changes: 13 additions & 9 deletions src/config/configProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ export class ConfigProvider extends Disposable {

this.applyDefaultSettings();
this._disposable = commands.registerCommand(GaugeVSCodeCommands.SaveRecommendedSettings,
() => this.applyAndReload());
() => this.applyAndReload(this.recommendedSettings));

if (!this.verify()) {
if (!this.verifyRecommendedConfig()) {
window.showInformationMessage("Gauge [recommends](https://docs.gauge.org/using.html#id31) " +
"some settings for best experience with Visual Studio Code.", "Apply & Reload", "Ignore")
"some settings for best experience with Visual Studio Code.",
"Apply & Reload", "Ignore", "Ignore Always")
.then((option) => {
if (option === "Apply & Reload") {
return this.applyAndReload();
return this.applyAndReload(this.recommendedSettings);
} else if (option === "Ignore Always") {
return this.applyAndReload({"gauge.showRecommendedSettings": false});
}
});
}
Expand All @@ -40,7 +43,8 @@ export class ConfigProvider extends Disposable {
workspace.getConfiguration().update(FILE_ASSOCIATIONS_KEY, recomendedConfig, ConfigurationTarget.Workspace);
}

private verify(): boolean {
private verifyRecommendedConfig(): boolean {
if (!workspace.getConfiguration().get("gauge.showRecommendedSettings")) return true;
for (const key in this.recommendedSettings) {
if (this.recommendedSettings.hasOwnProperty(key)) {
let configVal = workspace.getConfiguration().inspect(key);
Expand All @@ -53,12 +57,12 @@ export class ConfigProvider extends Disposable {
return true;
}

private applyAndReload(): Thenable<any> {
private applyAndReload(settings: Object): Thenable<any> {
let updatePromises = [];
for (const key in this.recommendedSettings) {
if (this.recommendedSettings.hasOwnProperty(key)) {
for (const key in settings) {
if (settings.hasOwnProperty(key)) {
updatePromises.push(workspace.getConfiguration()
.update(key, this.recommendedSettings[key], ConfigurationTarget.Global));
.update(key, settings[key], ConfigurationTarget.Global));
}
}
return Promise.all(updatePromises).then(() => commands.executeCommand(VSCodeCommands.ReloadWindow));
Expand Down

0 comments on commit 9f99ece

Please sign in to comment.