@@ -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}
@@ -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 ( 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