@@ -5,31 +5,14 @@ import { spellCheckPromises } from "./spell";
55import { ErrorsResult } from "./interface/types" ;
66import { Diagnostics } from "./diagnostics" ;
77import { Configuration } from "./configuration" ;
8- import { showStatusBar } from "./ui" ;
8+ import { showStatusBar , updateEmoji } from "./ui" ;
99
1010let errorsResult : ErrorsResult [ ] = [ ] ;
1111let markCheckList : ErrorsResult [ ] = [ ] ;
12- let isEnableOnSave = false ;
1312
1413export 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
276266function 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
0 commit comments