@@ -6,9 +6,13 @@ import { ErrorsResult } from "./interface/types";
66import { Diagnostics } from "./diagnostics" ;
77import { Configuration } from "./configuration" ;
88import { showStatusBar , updateEmoji } from "./statusbar" ;
9+ import { showErrorAPIKey , showWarningAPIKey } from "./notification" ;
910
1011let errorsResult : ErrorsResult [ ] = [ ] ;
1112let markCheckList : ErrorsResult [ ] = [ ] ;
13+ let checkCountWithDefaultKey = 0 ;
14+ const DEFAULT_API_KEY = "longdospellcheckervscodedemo" ;
15+ const NOTIFICATION_THRESHOLD = 3 ;
1216
1317export function activate ( context : vscode . ExtensionContext ) {
1418 showStatusBar ( context ) ;
@@ -171,10 +175,6 @@ export function activate(context: vscode.ExtensionContext) {
171175 context . subscriptions . push ( listenerDocumentSaved ( ) ) ;
172176}
173177
174- let checkCountWithDefaultKey = 0 ;
175- const DEFAULT_API_KEY = "longdospellcheckervscodedemo" ;
176- const NOTIFICATION_THRESHOLD = 3 ;
177-
178178async function onSpellCheck ( ) {
179179 errorsResult = [ ] ;
180180 Diagnostics . clearDiagnostics ( ) ;
@@ -192,19 +192,7 @@ async function onSpellCheck() {
192192 checkCountWithDefaultKey ++ ;
193193
194194 if ( checkCountWithDefaultKey >= NOTIFICATION_THRESHOLD ) {
195- const action = await vscode . window . showWarningMessage (
196- "You're using the default API key. For best results, please set your own API key." ,
197- "Set API Key" , "Get API Key" , "Dismiss"
198- ) ;
199-
200- if ( action === "Set API Key" ) {
201- vscode . commands . executeCommand ( Command . OpenSetKey ) ;
202- return ;
203- } else if ( action === "Get API Key" ) {
204- vscode . commands . executeCommand ( Command . openWebAPI ) ;
205- return ;
206- }
207-
195+ showWarningAPIKey ( ) ;
208196 checkCountWithDefaultKey = 0 ;
209197 }
210198 }
@@ -213,7 +201,14 @@ async function onSpellCheck() {
213201 await textProcessor . processDocument ( { document } ) ;
214202
215203 try {
216- let results = await spellCheckPromises ( apiKey ) ;
204+ const textData = await textProcessor . getTextData ( ) ;
205+ if ( textData . length === 0 ) {
206+ return ;
207+ }
208+ if ( textData . length >= 3 && apiKey === DEFAULT_API_KEY ) {
209+ showWarningAPIKey ( ) ;
210+ }
211+ let results = await spellCheckPromises ( apiKey , textData ) ;
217212 results = results . filter (
218213 ( error ) => ! markCheckList . some ( ( mark ) => mark . word === error . word )
219214 ) ;
@@ -231,20 +226,9 @@ async function onSpellCheck() {
231226 ? error . message
232227 : "An error occurred while checking spelling." ;
233228 const isErrorNetwork = errorMessage . includes ( "NetworkError" ) ;
234-
235229 const errorApiKeyEmpty = errorMessage . includes ( "API key is not set" ) ;
236230 if ( errorApiKeyEmpty ) {
237- const actionItems = [ "Yes" , "No" , "Get API Key" ] ;
238- const notification = await vscode . window . showWarningMessage (
239- "API key is not set. Do you want to set it now?" ,
240- ...actionItems
241- ) ;
242-
243- if ( notification === "Yes" ) {
244- vscode . commands . executeCommand ( Command . OpenSetKey ) ;
245- } else if ( notification === "Get API Key" ) {
246- vscode . commands . executeCommand ( Command . openWebAPI ) ;
247- }
231+ showErrorAPIKey ( ) ;
248232 return ;
249233 }
250234
0 commit comments