@@ -34,7 +34,15 @@ export const tmpDirDisposal = {
3434 }
3535} ;
3636
37- export class UserCancellationException extends Error { }
37+ export class UserCancellationException extends Error {
38+ /**
39+ * @param message The error message
40+ * @param silent If silent is true, then this exception will avoid showing a warning message to the user.
41+ */
42+ constructor ( message ?: string , public readonly silent = false ) {
43+ super ( message ) ;
44+ }
45+ }
3846
3947/**
4048 * A collection of evaluation-time information about a query,
@@ -307,7 +315,11 @@ async function checkDbschemeCompatibility(
307315
308316/**
309317 * Prompts the user to save `document` if it has unsaved changes.
310- * Returns true if we should save changes.
318+ *
319+ * @param document The document to save.
320+ *
321+ * @returns true if we should save changes and false if we should continue without saving changes.
322+ * @throws UserCancellationException if we should abort whatever operation triggered this prompt
311323 */
312324async function promptUserToSaveChanges ( document : vscode . TextDocument ) : Promise < boolean > {
313325 if ( document . isDirty ) {
@@ -317,9 +329,14 @@ async function promptUserToSaveChanges(document: vscode.TextDocument): Promise<b
317329 else {
318330 const yesItem = { title : 'Yes' , isCloseAffordance : false } ;
319331 const alwaysItem = { title : 'Always Save' , isCloseAffordance : false } ;
320- const noItem = { title : 'No' , isCloseAffordance : true } ;
332+ const noItem = { title : 'No (run anyway)' , isCloseAffordance : false } ;
333+ const cancelItem = { title : 'Cancel' , isCloseAffordance : true } ;
321334 const message = 'Query file has unsaved changes. Save now?' ;
322- const chosenItem = await vscode . window . showInformationMessage ( message , { modal : true } , yesItem , alwaysItem , noItem ) ;
335+ const chosenItem = await vscode . window . showInformationMessage (
336+ message ,
337+ { modal : true } ,
338+ yesItem , alwaysItem , noItem , cancelItem
339+ ) ;
323340
324341 if ( chosenItem === alwaysItem ) {
325342 await config . AUTOSAVE_SETTING . updateValue ( true , vscode . ConfigurationTarget . Workspace ) ;
@@ -329,6 +346,10 @@ async function promptUserToSaveChanges(document: vscode.TextDocument): Promise<b
329346 if ( chosenItem === yesItem ) {
330347 return true ;
331348 }
349+
350+ if ( chosenItem === cancelItem ) {
351+ throw new UserCancellationException ( 'Query run cancelled.' , true ) ;
352+ }
332353 }
333354 }
334355 return false ;
0 commit comments