@@ -2,6 +2,7 @@ import * as vscode from "vscode";
2
2
import { CurrentBinaryFile , CurrentTextFile , currentFileFromContent , handleError , notIsfs , outputChannel } from "." ;
3
3
import { AtelierAPI } from "../api" ;
4
4
import { compile , importFile } from "../commands/compile" ;
5
+ import { exportedUris } from "../commands/export" ;
5
6
6
7
interface WSFolderIndex {
7
8
/** The `FileSystemWatcher` for this workspace folder */
@@ -22,7 +23,7 @@ interface WSFolderIndexChange {
22
23
/** Map of stringified workspace folder `Uri`s to collection of InterSystems classes and routines contained therein */
23
24
const wsFolderIndex : Map < string , WSFolderIndex > = new Map ( ) ;
24
25
25
- /** Glob pattern that matches files we want to index */
26
+ /** Glob pattern that matches classes and routines */
26
27
const filePattern = "{**/*.cls,**/*.mac,**/*.int,**/*.inc}" ;
27
28
28
29
/** We want decoding errors to be thrown */
@@ -42,11 +43,12 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
42
43
watcher . onDidChange ( ( uri ) => updateIndexAndSyncChanges ( uri , documents , uris ) ) ;
43
44
watcher . onDidCreate ( ( uri ) => updateIndexAndSyncChanges ( uri , documents , uris ) ) ;
44
45
watcher . onDidDelete ( ( uri ) => {
46
+ // Remove the class/routine in the file from the index,
47
+ // then delete it on the server if required
45
48
const change = removeDocumentFromIndex ( uri , documents , uris ) ;
46
49
if ( change . removed ) {
47
50
const api = new AtelierAPI ( uri ) ;
48
51
if ( ! api . active ) return ;
49
- // Delete document on the server
50
52
api . deleteDoc ( change . removed ) . catch ( ( error ) => handleError ( error ) ) ;
51
53
}
52
54
} ) ;
@@ -94,7 +96,7 @@ export async function updateIndexForDocument(
94
96
// since the file may be a non-text file
95
97
// with a cls, mac, int or inc extension.
96
98
if ( error instanceof vscode . FileSystemError ) {
97
- outputChannel . appendLine ( `Failed to get text contents of '${ uri . toString ( true ) } ': ${ error . toString ( ) } ` ) ;
99
+ outputChannel . appendLine ( `Failed to read contents of '${ uri . toString ( true ) } ': ${ error . toString ( ) } ` ) ;
98
100
}
99
101
return result ;
100
102
}
@@ -168,6 +170,18 @@ async function updateIndexAndSyncChanges(
168
170
) : Promise < void > {
169
171
const change = await updateIndexForDocument ( uri , documents , uris ) ;
170
172
if ( ! change . added && ! change . removed ) return ;
173
+ const uriString = uri . toString ( ) ;
174
+ const exportedIdx = exportedUris . findIndex ( ( e ) => e == uriString ) ;
175
+ if ( exportedIdx != - 1 ) {
176
+ // This creation/change event was fired due to a server
177
+ // export, so don't re-sync the file with the server
178
+ exportedUris . splice ( exportedIdx , 1 ) ;
179
+ return ;
180
+ }
181
+ if ( vscode . workspace . textDocuments . some ( ( td ) => td . uri . toString ( ) == uriString ) ) {
182
+ // Don't sync with the server because onDidSaveTextDocument will handle it
183
+ return ;
184
+ }
171
185
const api = new AtelierAPI ( uri ) ;
172
186
if ( ! api . active ) return ;
173
187
const config = vscode . workspace . getConfiguration ( "objectscript" , uri ) ;
0 commit comments