Skip to content

Commit 3a639ab

Browse files
committed
show info about reloading when changing settings
1 parent 38c92b4 commit 3a639ab

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

src/compilers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as which from "which";
33
import * as fs from "fs";
44
import * as path from "path";
55
import * as ChildProcess from "child_process";
6-
import { config } from './extension';
6+
import { config, hideNextPotentialConfigUpdateWarning } from './extension';
77
import { determineOutputFolder, downloadFileInteractive } from './installer';
88
import { reqText } from './util';
99

@@ -395,6 +395,7 @@ export function makeCompilerInstallButtons(compiler: DetectedCompiler): [UIQuick
395395
detail: detail,
396396
action: function () {
397397
settings.forEach(setting => {
398+
hideNextPotentialConfigUpdateWarning();
398399
config(null).update(setting[0], setting[1], vscode.ConfigurationTarget.Global);
399400
});
400401
}

src/extension.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ function startClient(context: vscode.ExtensionContext) {
242242
client.onReady().then(() => {
243243
var updateSetting = new NotificationType<{ section: string, value: any, global: boolean }>("coded/updateSetting");
244244
client.onNotification(updateSetting, (arg: { section: string, value: any, global: boolean }) => {
245+
hideNextPotentialConfigUpdateWarning();
245246
config(null).update(arg.section, arg.value, arg.global);
246247
});
247248

@@ -405,6 +406,7 @@ export function activate(context: vscode.ExtensionContext): CodedAPI {
405406

406407
context.subscriptions.push(addSDLProviders());
407408
context.subscriptions.push(addJSONProviders());
409+
context.subscriptions.push(createConfigUpdateWatcher());
408410

409411
context.subscriptions.push(registerCompilerInstaller(context));
410412

@@ -526,8 +528,10 @@ async function preStartup(context: vscode.ExtensionContext) {
526528
}
527529
}
528530

529-
if (updateSetting)
531+
if (updateSetting) {
532+
hideNextPotentialConfigUpdateWarning();
530533
await config(null).update("dubPath", path);
534+
}
531535
return true;
532536
}
533537

@@ -690,6 +694,7 @@ async function preStartup(context: vscode.ExtensionContext) {
690694
}
691695

692696
if (isLegacyBeta && servedReleaseChannel && !servedReleaseChannel.globalValue) {
697+
hideNextPotentialConfigUpdateWarning();
693698
config(null).update("servedReleaseChannel", "nightly", vscode.ConfigurationTarget.Global);
694699
channelString = "nightly";
695700

@@ -703,9 +708,11 @@ async function preStartup(context: vscode.ExtensionContext) {
703708
if (item == userConfig) {
704709
vscode.commands.executeCommand("workbench.action.openGlobalSettings");
705710
} else if (item == stable) {
711+
hideNextPotentialConfigUpdateWarning();
706712
let done = config(null).update("servedReleaseChannel", "stable", vscode.ConfigurationTarget.Global);
707713
didChangeReleaseChannel(done);
708714
} else if (item == beta) {
715+
hideNextPotentialConfigUpdateWarning();
709716
let done = config(null).update("servedReleaseChannel", "beta", vscode.ConfigurationTarget.Global);
710717
didChangeReleaseChannel(done);
711718
}
@@ -904,3 +911,49 @@ function shortenPath(p: string) {
904911
});
905912
return short;
906913
}
914+
915+
/**
916+
* Watches for config updates that need a vscode window reload to be effective
917+
* and shows a hint to the user in these cases.
918+
*/
919+
function createConfigUpdateWatcher(): vscode.Disposable {
920+
return vscode.workspace.onDidChangeConfiguration((e) => {
921+
const needReloadSettings = [
922+
"d.servedPath",
923+
"d.servedReleaseChannel",
924+
"d.dcdServerPath",
925+
"d.dcdClientPath",
926+
"d.scanAllFolders",
927+
"d.neverUseDub",
928+
"d.disabledRootGlobs",
929+
"d.extraRoots",
930+
];
931+
932+
if (lastConfigUpdateWasInternal && new Date().getTime() - lastConfigUpdateWasInternal < 1000)
933+
return; // ignore config updates that come from code-d or serve-d
934+
935+
var changed: string | null = null;
936+
needReloadSettings.forEach(setting => {
937+
if (!changed && e.affectsConfiguration(setting))
938+
changed = setting;
939+
});
940+
941+
let reloadBtn = "Reload VSCode";
942+
let ignoreBtn = "Ignore";
943+
944+
if (changed)
945+
vscode.window.showInformationMessage("You have changed code-d's `"
946+
+ changed + "` setting. To apply the new value, you need to reload VSCode.",
947+
reloadBtn, ignoreBtn)
948+
.then(btn => {
949+
if (btn == reloadBtn)
950+
vscode.commands.executeCommand("workbench.action.reloadWindow");
951+
});
952+
});
953+
}
954+
955+
var lastConfigUpdateWasInternal: number | null;
956+
export function hideNextPotentialConfigUpdateWarning() {
957+
lastConfigUpdateWasInternal = new Date().getTime();
958+
}
959+

src/installer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as vscode from "vscode"
33
import * as path from "path"
44
import * as fs from "fs"
55
import { reqJson, reqType } from "./util"
6-
import { config, extensionContext } from "./extension"
6+
import { config, extensionContext, hideNextPotentialConfigUpdateWarning } from "./extension"
77
import expandTilde = require("expand-tilde");
88
import { AxiosResponse } from "axios"
99
import { Readable } from "stream"
@@ -390,6 +390,7 @@ export function installServeD(urls: { url: string, title: string }[], ref: strin
390390
return done(undefined);
391391
}
392392
else {
393+
hideNextPotentialConfigUpdateWarning();
393394
await config(null).update("servedPath", finalDestination, true);
394395
installationLog.appendLine("Finished installing into " + finalDestination);
395396
done(true);
@@ -503,6 +504,7 @@ export function compileServeD(ref?: string): (env: NodeJS.ProcessEnv) => Promise
503504
], env, ref);
504505
var finalDestination = path.join(outputFolder, "serve-d", "serve-d" + (process.platform == "win32" ? ".exe" : ""));
505506

507+
hideNextPotentialConfigUpdateWarning();
506508
await config(null).update("servedPath", finalDestination, true);
507509
return true;
508510
});

0 commit comments

Comments
 (0)