Skip to content

Commit 8a0805f

Browse files
authored
Merge pull request #38 from MetamediaTechnology/staging
refactor: Dynamic status bar & improved alert dialog
2 parents 95ee2d2 + 3a48c5f commit 8a0805f

7 files changed

Lines changed: 77 additions & 67 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to the "longdo-spell-checker" extension will be documented i
55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

77
## [Released]
8+
### [0.2.8] : 21/04/2568
9+
- feat: Set spell checking on save as the default behavior
10+
- refactor: Change configuration name from longdo-spell-checker to Longdo Spell Checker.
11+
- feat: Enhanced status bar to reflect different states:
12+
- Check mark when no spelling errors are found
13+
- Disconnection icon when API key is missing
14+
- Offline indicator when internet connection is unavailable
15+
816
### [0.2.7] : 10/04/2568
917
- chore: Add URL to web console page in the setting description
1018
- refactor: Dialog to ask before change API Key

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
],
2525
"description": "Thai/English Spell Checker: A fast and intelligent multilingual spell checker from Longdo Dict online dictionary service.",
2626
"publisher": "MetamediaTechnology",
27-
"version": "0.2.7",
27+
"version": "0.2.8",
2828
"engines": {
2929
"vscode": "^1.80.0"
3030
},
@@ -41,17 +41,17 @@
4141
"configuration": {
4242
"title": "Longdo Spell",
4343
"properties": {
44-
"longdo-spell-checker.apiKey": {
44+
"longdoSpellChecker.apiKey": {
4545
"type": "string",
4646
"default": "",
4747
"description": "Longdo Spell Checker Api Key"
4848
},
49-
"longdo-spell-checker.checkOnSave": {
49+
"longdoSpellChecker.checkOnSave": {
5050
"type": "boolean",
51-
"default": false,
51+
"default": true,
5252
"description": "Check spelling on save"
5353
},
54-
"longdo-spell-checker.locale": {
54+
"longdoSpellChecker.locale": {
5555
"type": "string",
5656
"enum": [
5757
"Thai",
@@ -60,7 +60,7 @@
6060
"default": "Thai",
6161
"description": "Set the primary language for spell checking"
6262
},
63-
"longdo-spell-checker.language": {
63+
"longdoSpellChecker.language": {
6464
"type": "array",
6565
"default": [
6666
"Thai",

src/api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ApiResponse } from "./interface/types";
2+
import { updateEmoji } from "./ui";
23
import * as vscode from "vscode";
34

45
/**
@@ -29,11 +30,13 @@ async function postProof(text: string) {
2930
try {
3031
const isConnected = await checkInternetConnection();
3132
if (!isConnected) {
33+
updateEmoji("$(debug-disconnect)");
3234
throw new Error("NetworkError");
3335
}
3436

35-
const apiKey = vscode.workspace.getConfiguration("longdo-spell-checker").get("apiKey");
37+
const apiKey = vscode.workspace.getConfiguration("longdoSpellChecker").get("apiKey");
3638
if (!apiKey) {
39+
updateEmoji("$(debug-disconnect)");
3740
throw new Error("API key is not set. Please set it in the settings.");
3841
}
3942

src/extension.ts

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,14 @@ import { spellCheckPromises } from "./spell";
55
import { ErrorsResult } from "./interface/types";
66
import { Diagnostics } from "./diagnostics";
77
import { Configuration } from "./configuration";
8-
import { showStatusBar } from "./ui";
8+
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",
@@ -144,6 +127,7 @@ export function activate(context: vscode.ExtensionContext) {
144127
"Longdo Spell Checker: Check Spelling (Current Tab)",
145128
"Longdo Spell Checker: Clear All Errors (Current Tab)",
146129
"Longdo Spell Checker: Set API Key",
130+
"Longdo Spell Checker: Open Settings",
147131
"Longdo Spell Checker: Open Web Console",
148132
];
149133
const selected = await vscode.window.showQuickPick(options, {
@@ -153,25 +137,30 @@ export function activate(context: vscode.ExtensionContext) {
153137
if (!selected) {
154138
return;
155139
}
156-
if (options[0] === selected) {
157-
vscode.commands.executeCommand(Command.CheckSpelling);
158-
}
159-
if (options[1] === selected) {
160-
vscode.commands.executeCommand(Command.ClearSpell);
161-
}
162-
if (options[2] === selected) {
163-
vscode.commands.executeCommand(Command.OpenSetKey);
164-
}
165-
if (options[3] === selected) {
166-
vscode.commands.executeCommand(Command.openWebAPI);
140+
switch (selected) {
141+
case "Longdo Spell Checker: Check Spelling (Current Tab)":
142+
await onSpellCheck();
143+
break;
144+
case "Longdo Spell Checker: Clear All Errors (Current Tab)":
145+
errorsResult = [];
146+
Diagnostics.clearDiagnostics();
147+
break;
148+
case "Longdo Spell Checker: Set API Key":
149+
vscode.commands.executeCommand(Command.OpenSetKey);
150+
break;
151+
case "Longdo Spell Checker: Open Settings":
152+
vscode.commands.executeCommand(
153+
"workbench.action.openSettings",
154+
"longdo-spell-checker"
155+
);
156+
break;
157+
case "Longdo Spell Checker: Open Web Console":
158+
vscode.commands.executeCommand(Command.openWebAPI);
159+
break;
167160
}
168161
}
169162
);
170163

171-
isEnableOnSave = vscode.workspace
172-
.getConfiguration("longdo-spell-checker")
173-
.get("checkOnSave", false);
174-
175164
context.subscriptions.push(openWebConsole);
176165
context.subscriptions.push(disposable);
177166
context.subscriptions.push(clearCommand);
@@ -194,23 +183,24 @@ async function onSpellCheck() {
194183

195184
try {
196185
let results = await spellCheckPromises();
197-
if (results.length === 0) {
198-
if (isEnableOnSave) {
199-
return;
200-
} else {
201-
vscode.window.showInformationMessage("No spelling errors found.");
202-
return;
203-
}
204-
}
205186
results = results.filter(
206187
(error) => !markCheckList.some((mark) => mark.word === error.word)
207188
);
189+
208190
if (results.length === 0) {
209-
vscode.window.showInformationMessage("No spelling errors found.");
191+
if (
192+
vscode.workspace
193+
.getConfiguration("longdoSpellChecker")
194+
.get("checkOnSave")
195+
) {
196+
vscode.window.showInformationMessage("No spelling errors found.");
197+
}
198+
updateEmoji("$(pass)");
210199
return;
211200
}
212201
Diagnostics.onShowDiagnostics(results, editor);
213202
errorsResult = results;
203+
updateEmoji("$(warning)");
214204
} catch (error: unknown) {
215205
const errorMessage =
216206
error instanceof Error
@@ -225,7 +215,7 @@ async function onSpellCheck() {
225215
"API key is not set. Do you want to set it now?",
226216
...actionItems
227217
);
228-
218+
229219
if (notification === "Yes") {
230220
vscode.commands.executeCommand(Command.OpenSetKey);
231221
} else if (notification === "Get API Key") {
@@ -274,17 +264,18 @@ function listenerDocumentChanged() {
274264
}
275265

276266
function listenerDocumentSaved(): vscode.Disposable {
277-
if (!isEnableOnSave) {
278-
return { dispose: () => {} };
279-
}
280267
return vscode.workspace.onDidSaveTextDocument((document) => {
281268
const editor = vscode.window.activeTextEditor;
282269
if (!editor) {
283270
return;
284271
}
285-
textProcessor.processDocument({ document }).then(() => {
286-
onSpellCheck();
287-
});
272+
if (
273+
vscode.workspace.getConfiguration("longdoSpellChecker").get("checkOnSave")
274+
) {
275+
textProcessor.processDocument({ document }).then(() => {
276+
onSpellCheck();
277+
});
278+
}
288279
});
289280
}
290281

src/language.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ export class Language {
3333
*/
3434
public switchLanguage() {
3535
const currentLanguage =
36-
vscode.workspace.getConfiguration("longdo-spell-checker").get("locale") ?? "en";
36+
vscode.workspace.getConfiguration("longdoSpellChecker").get("locale") ?? "en";
3737
const newLanguage = currentLanguage === "en" ? "fr" : "en";
3838
vscode.workspace
39-
.getConfiguration("longdo-spell-checker")
39+
.getConfiguration("longdoSpellChecker")
4040
.update("locale", newLanguage, vscode.ConfigurationTarget.Global);
4141
}
4242

4343
/**
4444
* Returns the language of the current editor
4545
*/
4646
public getLanguage(): string {
47-
const locale = vscode.workspace.getConfiguration("longdo-spell-checker").get("locale") as string;
47+
const locale = vscode.workspace.getConfiguration("longdoSpellChecker").get("locale") as string;
4848
return locale === "Thai" ? "th" : "en";
4949
}
5050

src/text.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class TextProcessor {
7070
document.fileName.split(".").pop()?.toLowerCase() || "txt";
7171
const isSupportedFile = fileExtension in languageMap;
7272

73-
const config = vscode.workspace.getConfiguration("longdo-spell-checker");
73+
const config = vscode.workspace.getConfiguration("longdoSpellChecker");
7474
const languages = config.get<string[]>("language") || [];
7575
const isEnglishEnabled = languages.includes("English");
7676

src/ui.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export function showStatusBar(context: vscode.ExtensionContext) {
1111
context.subscriptions.push(statusBar);
1212
}
1313

14+
export function updateStatusBar(text:string) {
15+
statusBar.text = text;
16+
}
17+
18+
export function updateEmoji(emoji: string) {
19+
statusBar.text = emoji + " Longdo Spell";
20+
}
21+
1422
export function hideStatusBar(context: vscode.ExtensionContext) {
1523
statusBar.hide();
1624
context.subscriptions.push(statusBar);

0 commit comments

Comments
 (0)