@@ -39,7 +39,7 @@ const wsFolderIndex: Map<string, WSFolderIndex> = new Map();
39
39
const textDecoder = new TextDecoder ( "utf-8" , { fatal : true } ) ;
40
40
41
41
/** The number of milliseconds that we should wait before sending a compile or delete request */
42
- const debounceDelay = 500 ;
42
+ const debounceDelay = 1000 ;
43
43
44
44
/**
45
45
* Create an object describing the file in `uri`.
@@ -86,20 +86,11 @@ function generateCompileFn(): (doc: CurrentTextFile | CurrentBinaryFile) => void
86
86
// Clear the previous timeout to reset the debounce timer
87
87
clearTimeout ( timeout ) ;
88
88
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
-
99
89
// Set a new timeout to call the function after the specified delay
100
90
timeout = setTimeout ( ( ) => {
101
- compile ( [ ...docs ] ) ;
91
+ const docsCopy = [ ...docs ] ;
102
92
docs . length = 0 ;
93
+ compile ( docsCopy ) ;
103
94
} , debounceDelay ) ;
104
95
} ;
105
96
}
@@ -118,7 +109,9 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
118
109
119
110
// Set a new timeout to call the function after the specified delay
120
111
timeout = setTimeout ( ( ) => {
121
- api . deleteDocs ( [ ...docs ] ) . then ( ( data ) => {
112
+ const docsCopy = [ ...docs ] ;
113
+ docs . length = 0 ;
114
+ api . deleteDocs ( docsCopy ) . then ( ( data ) => {
122
115
let failed = 0 ;
123
116
for ( const doc of data . result ) {
124
117
if ( doc . status != "" && ! doc . status . includes ( "#16005:" ) ) {
@@ -142,7 +135,6 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
142
135
) ;
143
136
}
144
137
} ) ;
145
- docs . length = 0 ;
146
138
} , debounceDelay ) ;
147
139
} ;
148
140
}
@@ -227,8 +219,8 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
227
219
const api = new AtelierAPI ( uri ) ;
228
220
const conf = vscode . workspace . getConfiguration ( "objectscript" , wsFolder ) ;
229
221
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 ) ) ;
232
224
touchedByVSCode . delete ( uriString ) ;
233
225
let change : WSFolderIndexChange = { } ;
234
226
if ( isClassOrRtn ( uri ) ) {
@@ -241,7 +233,16 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
241
233
// Create or update the document on the server
242
234
importFile ( change . addedOrChanged )
243
235
. 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
+ }
245
246
} )
246
247
// importFile handles any server errors
247
248
. catch ( ( ) => { } ) ;
0 commit comments