Skip to content

Commit 7e83e48

Browse files
committed
Fix two bugs
1 parent a9e3e3b commit 7e83e48

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/commands/export.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import {
1515
import { NodeBase } from "../explorer/models/nodeBase";
1616
import { pickDocuments } from "../utils/documentPicker";
1717

18+
/**
19+
* Array of stringified `Uri`s that have been exported.
20+
* Used by the documentIndex to determine if a created/changed
21+
* file needs to be synced with the server. If the documentIndex
22+
* finds a match in this array, the element is then removed.
23+
*/
24+
export const exportedUris: string[] = [];
25+
1826
export const getCategory = (fileName: string, addCategory: any | boolean): string => {
1927
const fileExt = fileName.split(".").pop().toLowerCase();
2028
if (typeof addCategory === "object") {
@@ -94,6 +102,7 @@ async function exportFile(wsFolderUri: vscode.Uri, namespace: string, name: stri
94102
api.setNamespace(namespace);
95103
let fileUri = vscode.Uri.file(fileName);
96104
if (wsFolderUri.scheme != "file") fileUri = wsFolderUri.with({ path: fileUri.path });
105+
exportedUris.push(fileUri.toString());
97106
const log = (status: string) =>
98107
outputChannel.appendLine(`Export '${name}' to '${fileUri.toString(true)}' - ${status}`);
99108

src/utils/documentIndex.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22
import { CurrentBinaryFile, CurrentTextFile, currentFileFromContent, handleError, notIsfs, outputChannel } from ".";
33
import { AtelierAPI } from "../api";
44
import { compile, importFile } from "../commands/compile";
5+
import { exportedUris } from "../commands/export";
56

67
interface WSFolderIndex {
78
/** The `FileSystemWatcher` for this workspace folder */
@@ -22,7 +23,7 @@ interface WSFolderIndexChange {
2223
/** Map of stringified workspace folder `Uri`s to collection of InterSystems classes and routines contained therein */
2324
const wsFolderIndex: Map<string, WSFolderIndex> = new Map();
2425

25-
/** Glob pattern that matches files we want to index */
26+
/** Glob pattern that matches classes and routines */
2627
const filePattern = "{**/*.cls,**/*.mac,**/*.int,**/*.inc}";
2728

2829
/** We want decoding errors to be thrown */
@@ -42,11 +43,12 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
4243
watcher.onDidChange((uri) => updateIndexAndSyncChanges(uri, documents, uris));
4344
watcher.onDidCreate((uri) => updateIndexAndSyncChanges(uri, documents, uris));
4445
watcher.onDidDelete((uri) => {
46+
// Remove the class/routine in the file from the index,
47+
// then delete it on the server if required
4548
const change = removeDocumentFromIndex(uri, documents, uris);
4649
if (change.removed) {
4750
const api = new AtelierAPI(uri);
4851
if (!api.active) return;
49-
// Delete document on the server
5052
api.deleteDoc(change.removed).catch((error) => handleError(error));
5153
}
5254
});
@@ -94,7 +96,7 @@ export async function updateIndexForDocument(
9496
// since the file may be a non-text file
9597
// with a cls, mac, int or inc extension.
9698
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()}`);
98100
}
99101
return result;
100102
}
@@ -168,6 +170,18 @@ async function updateIndexAndSyncChanges(
168170
): Promise<void> {
169171
const change = await updateIndexForDocument(uri, documents, uris);
170172
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+
}
171185
const api = new AtelierAPI(uri);
172186
if (!api.active) return;
173187
const config = vscode.workspace.getConfiguration("objectscript", uri);

0 commit comments

Comments
 (0)