@@ -39,7 +39,7 @@ const wsFolderIndex: Map<string, WSFolderIndex> = new Map();
3939const textDecoder = new TextDecoder ( "utf-8" , { fatal : true } ) ;
4040
4141/** The number of milliseconds that we should wait before sending a compile or delete request */
42- const debounceDelay = 500 ;
42+ const debounceDelay = 1000 ;
4343
4444/**
4545 * Create an object describing the file in `uri`.
@@ -86,20 +86,11 @@ function generateCompileFn(): (doc: CurrentTextFile | CurrentBinaryFile) => void
8686 // Clear the previous timeout to reset the debounce timer
8787 clearTimeout ( timeout ) ;
8888
89- // Compile right away if this document is in the active text editor
90- // and there are no other documents in the queue. This is needed
91- // to avoid noticeable latency when a user is editing a client-side
92- // file, saves it, and the auto-compile kicks in.
93- if ( docs . length == 1 && vscode . window . activeTextEditor ?. document . uri . toString ( ) == doc . uri . toString ( ) ) {
94- compile ( [ ...docs ] ) ;
95- docs . length = 0 ;
96- return ;
97- }
98-
9989 // Set a new timeout to call the function after the specified delay
10090 timeout = setTimeout ( ( ) => {
101- compile ( [ ...docs ] ) ;
91+ const docsCopy = [ ...docs ] ;
10292 docs . length = 0 ;
93+ compile ( docsCopy ) ;
10394 } , debounceDelay ) ;
10495 } ;
10596}
@@ -118,7 +109,9 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
118109
119110 // Set a new timeout to call the function after the specified delay
120111 timeout = setTimeout ( ( ) => {
121- api . deleteDocs ( [ ...docs ] ) . then ( ( data ) => {
112+ const docsCopy = [ ...docs ] ;
113+ docs . length = 0 ;
114+ api . deleteDocs ( docsCopy ) . then ( ( data ) => {
122115 let failed = 0 ;
123116 for ( const doc of data . result ) {
124117 if ( doc . status != "" && ! doc . status . includes ( "#16005:" ) ) {
@@ -142,7 +135,6 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
142135 ) ;
143136 }
144137 } ) ;
145- docs . length = 0 ;
146138 } , debounceDelay ) ;
147139 } ;
148140}
@@ -227,8 +219,8 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
227219 const api = new AtelierAPI ( uri ) ;
228220 const conf = vscode . workspace . getConfiguration ( "objectscript" , wsFolder ) ;
229221 const syncLocalChanges : string = conf . get ( "syncLocalChanges" ) ;
230- const sync : boolean =
231- api . active && ( syncLocalChanges == "all" || ( syncLocalChanges == "vscodeOnly" && touchedByVSCode . has ( uriString ) ) ) ;
222+ const vscodeChange = touchedByVSCode . has ( uriString ) ;
223+ const sync = api . active && ( syncLocalChanges == "all" || ( syncLocalChanges == "vscodeOnly" && vscodeChange ) ) ;
232224 touchedByVSCode . delete ( uriString ) ;
233225 let change : WSFolderIndexChange = { } ;
234226 if ( isClassOrRtn ( uri ) ) {
@@ -241,7 +233,16 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
241233 // Create or update the document on the server
242234 importFile ( change . addedOrChanged )
243235 . then ( ( ) => {
244- if ( conf . get ( "compileOnSave" ) ) debouncedCompile ( change . addedOrChanged ) ;
236+ if ( conf . get ( "compileOnSave" ) ) {
237+ // Compile right away if this document is in the active text editor.
238+ // This is needed to avoid noticeable latency when a user is editing
239+ // a client-side file, saves it, and the auto-compile kicks in.
240+ if ( vscodeChange && vscode . window . activeTextEditor ?. document . uri . toString ( ) == uriString ) {
241+ compile ( [ change . addedOrChanged ] ) ;
242+ } else {
243+ debouncedCompile ( change . addedOrChanged ) ;
244+ }
245+ }
245246 } )
246247 // importFile handles any server errors
247248 . catch ( ( ) => { } ) ;
0 commit comments