Skip to content

Commit 3a48c5f

Browse files
authored
Merge pull request #39 from MetamediaTechnology/refactoring
Change config name
2 parents 0b80981 + 85a6b7a commit 3a48c5f

6 files changed

Lines changed: 38 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
77
## [Released]
88
### [0.2.8] : 21/04/2568
99
- feat: Set spell checking on save as the default behavior
10+
- refactor: Change configuration name from longdo-spell-checker to Longdo Spell Checker.
1011
- feat: Enhanced status bar to reflect different states:
11-
- Checkmark when no spelling errors are found
12+
- Check mark when no spelling errors are found
1213
- Disconnection icon when API key is missing
1314
- Offline indicator when internet connection is unavailable
1415

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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",
5151
"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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function postProof(text: string) {
3434
throw new Error("NetworkError");
3535
}
3636

37-
const apiKey = vscode.workspace.getConfiguration("longdo-spell-checker").get("apiKey");
37+
const apiKey = vscode.workspace.getConfiguration("longdoSpellChecker").get("apiKey");
3838
if (!apiKey) {
3939
updateEmoji("$(debug-disconnect)");
4040
throw new Error("API key is not set. Please set it in the settings.");

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

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

0 commit comments

Comments
 (0)