Skip to content

Commit d5cbf25

Browse files
committed
feat: don't ask to restart when enable or disable chckOnSave
1 parent 71b2b35 commit d5cbf25

1 file changed

Lines changed: 27 additions & 40 deletions

File tree

src/extension.ts

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,10 @@ import { showStatusBar, updateEmoji } from "./ui";
99

1010
let errorsResult: ErrorsResult[] = [];
1111
let markCheckList: ErrorsResult[] = [];
12-
let isEnableOnSave = false;
1312

1413
export function activate(context: vscode.ExtensionContext) {
1514
showStatusBar(context);
1615

17-
vscode.workspace.onDidChangeConfiguration((event) => {
18-
if (event.affectsConfiguration("longdo-spell-checker.checkOnSave")) {
19-
vscode.window
20-
.showInformationMessage(
21-
"Longdo Spell Checker: Settings changed. Restart window for changes to take effect?",
22-
"Restart",
23-
"Later"
24-
)
25-
.then((selection) => {
26-
if (selection === "Restart") {
27-
vscode.commands.executeCommand("workbench.action.reloadWindow");
28-
}
29-
});
30-
}
31-
});
32-
3316
context.subscriptions.push(
3417
vscode.languages.registerCodeActionsProvider(
3518
Configuration.languages,
@@ -52,12 +35,12 @@ export function activate(context: vscode.ExtensionContext) {
5235
async () => {
5336
const url = "https://map.longdo.com/console";
5437
try {
55-
vscode.env.openExternal(vscode.Uri.parse(url));
38+
vscode.env.openExternal(vscode.Uri.parse(url));
5639
} catch (error) {
57-
console.error("Failed to open URL:", error);
58-
vscode.window.showErrorMessage(
59-
"Failed to open Longdo Web Console. Please check your internet connection."
60-
);
40+
console.error("Failed to open URL:", error);
41+
vscode.window.showErrorMessage(
42+
"Failed to open Longdo Web Console. Please check your internet connection."
43+
);
6144
}
6245
}
6346
);
@@ -95,7 +78,7 @@ export function activate(context: vscode.ExtensionContext) {
9578
Command.OpenSetKey,
9679
async () => {
9780
const currentAPIKey = vscode.workspace
98-
.getConfiguration("longdo-spell-checker")
81+
.getConfiguration("longdoSpellChecker")
9982
.get("apiKey") as string;
10083
if (currentAPIKey) {
10184
const confirm = await vscode.window.showInformationMessage(
@@ -116,7 +99,7 @@ export function activate(context: vscode.ExtensionContext) {
11699
});
117100

118101
if (apiKey) {
119-
const config = vscode.workspace.getConfiguration("longdo-spell-checker");
102+
const config = vscode.workspace.getConfiguration("longdoSpellChecker");
120103
try {
121104
await config.update(
122105
"apiKey",
@@ -166,7 +149,10 @@ export function activate(context: vscode.ExtensionContext) {
166149
vscode.commands.executeCommand(Command.OpenSetKey);
167150
break;
168151
case "Longdo Spell Checker: Open Settings":
169-
vscode.commands.executeCommand('workbench.action.openSettings', 'longdo-spell-checker');
152+
vscode.commands.executeCommand(
153+
"workbench.action.openSettings",
154+
"longdo-spell-checker"
155+
);
170156
break;
171157
case "Longdo Spell Checker: Open Web Console":
172158
vscode.commands.executeCommand(Command.openWebAPI);
@@ -175,10 +161,6 @@ export function activate(context: vscode.ExtensionContext) {
175161
}
176162
);
177163

178-
isEnableOnSave = vscode.workspace
179-
.getConfiguration("longdo-spell-checker")
180-
.get("checkOnSave", false);
181-
182164
context.subscriptions.push(openWebConsole);
183165
context.subscriptions.push(disposable);
184166
context.subscriptions.push(clearCommand);
@@ -201,12 +183,16 @@ async function onSpellCheck() {
201183

202184
try {
203185
let results = await spellCheckPromises();
204-
results = results.filter(error =>
205-
!markCheckList.some(mark => mark.word === error.word)
186+
results = results.filter(
187+
(error) => !markCheckList.some((mark) => mark.word === error.word)
206188
);
207-
189+
208190
if (results.length === 0) {
209-
if (!isEnableOnSave) {
191+
if (
192+
vscode.workspace
193+
.getConfiguration("longdoSpellChecker")
194+
.get("checkOnSave")
195+
) {
210196
vscode.window.showInformationMessage("No spelling errors found.");
211197
}
212198
updateEmoji("$(pass)");
@@ -229,7 +215,7 @@ async function onSpellCheck() {
229215
"API key is not set. Do you want to set it now?",
230216
...actionItems
231217
);
232-
218+
233219
if (notification === "Yes") {
234220
vscode.commands.executeCommand(Command.OpenSetKey);
235221
} else if (notification === "Get API Key") {
@@ -278,17 +264,18 @@ function listenerDocumentChanged() {
278264
}
279265

280266
function listenerDocumentSaved(): vscode.Disposable {
281-
if (!isEnableOnSave) {
282-
return { dispose: () => {} };
283-
}
284267
return vscode.workspace.onDidSaveTextDocument((document) => {
285268
const editor = vscode.window.activeTextEditor;
286269
if (!editor) {
287270
return;
288271
}
289-
textProcessor.processDocument({ document }).then(() => {
290-
onSpellCheck();
291-
});
272+
if (
273+
vscode.workspace.getConfiguration("longdoSpellChecker").get("checkOnSave")
274+
) {
275+
textProcessor.processDocument({ document }).then(() => {
276+
onSpellCheck();
277+
});
278+
}
292279
});
293280
}
294281

0 commit comments

Comments
 (0)