@@ -7,6 +7,7 @@ import * as vscode from 'vscode';
77import { ErrorCodes , ResponseError } from 'vscode-languageclient' ;
88
99import * as cli from './cli' ;
10+ import * as config from './config' ;
1011import { DatabaseItem , getUpgradesDirectories } from './databases' ;
1112import * as helpers from './helpers' ;
1213import { DatabaseInfo , QueryMetadata , ResultsPaths } from './interface-types' ;
@@ -121,6 +122,9 @@ export class QueryInfo {
121122 ) : Promise < messages . CompilationMessage [ ] > {
122123 let compiled : messages . CheckQueryResult | undefined ;
123124 try {
125+ const target = this . quickEvalPosition ? {
126+ quickEval : { quickEvalPos : this . quickEvalPosition }
127+ } : { query : { } } ;
124128 const params : messages . CompileQueryParams = {
125129 compilationOptions : {
126130 computeNoLocationUrls : true ,
@@ -136,11 +140,7 @@ export class QueryInfo {
136140 } ,
137141 queryToCheck : this . program ,
138142 resultPath : this . compiledQueryPath ,
139- target : this . quickEvalPosition ? {
140- quickEval : { quickEvalPos : this . quickEvalPosition }
141- } : {
142- query : { }
143- }
143+ target,
144144 } ;
145145
146146 compiled = await helpers . withProgress ( {
@@ -259,7 +259,7 @@ async function checkDbschemeCompatibility(
259259
260260 if ( query . dbItem . contents !== undefined && query . dbItem . contents . dbSchemeUri !== undefined ) {
261261 const { scripts, finalDbscheme } = await cliServer . resolveUpgrades ( query . dbItem . contents . dbSchemeUri . fsPath , searchPath ) ;
262- const hash = async function ( filename : string ) : Promise < string > {
262+ const hash = async function ( filename : string ) : Promise < string > {
263263 return crypto . createHash ( 'sha256' ) . update ( await fs . readFile ( filename ) ) . digest ( 'hex' ) ;
264264 }
265265
@@ -294,14 +294,33 @@ async function checkDbschemeCompatibility(
294294 }
295295}
296296
297- /** Prompts the user to save `document` if it has unsaved changes. */
298- async function promptUserToSaveChanges ( document : vscode . TextDocument ) : Promise < void > {
297+ /**
298+ * Prompts the user to save `document` if it has unsaved changes.
299+ * Returns true if we should save changes.
300+ */
301+ async function promptUserToSaveChanges ( document : vscode . TextDocument ) : Promise < boolean > {
299302 if ( document . isDirty ) {
300- // TODO: add 'always save' button which records preference in configuration
301- if ( await helpers . showBinaryChoiceDialog ( 'Query file has unsaved changes. Save now?' ) ) {
302- await document . save ( ) ;
303+ if ( config . AUTOSAVE_SETTING . getValue ( ) ) {
304+ return true ;
305+ }
306+ else {
307+ const yesItem = { title : 'Yes' , isCloseAffordance : false } ;
308+ const alwaysItem = { title : 'Always Save' , isCloseAffordance : false } ;
309+ const noItem = { title : 'No' , isCloseAffordance : true }
310+ const message = 'Query file has unsaved changes. Save now?' ;
311+ const chosenItem = await vscode . window . showInformationMessage ( message , { modal : true } , yesItem , alwaysItem , noItem ) ;
312+
313+ if ( chosenItem === alwaysItem ) {
314+ await config . AUTOSAVE_SETTING . updateValue ( true , vscode . ConfigurationTarget . Workspace ) ;
315+ return true ;
316+ }
317+
318+ if ( chosenItem === yesItem ) {
319+ return true ;
320+ }
303321 }
304322 }
323+ return false ;
305324}
306325
307326type SelectedQuery = {
@@ -357,7 +376,9 @@ export async function determineSelectedQuery(selectedResourceUri: vscode.Uri | u
357376 // if the same file is open with unsaved changes in the active editor,
358377 // then prompt the user to save it first.
359378 if ( editor !== undefined && editor . document . uri . fsPath === queryPath ) {
360- await promptUserToSaveChanges ( editor . document ) ;
379+ if ( await promptUserToSaveChanges ( editor . document ) ) {
380+ editor . document . save ( ) ;
381+ }
361382 }
362383
363384 let quickEvalPosition : messages . Position | undefined = undefined ;
0 commit comments