Skip to content

Commit e60a6de

Browse files
committed
Fix issuse where Undo deletes the file
1 parent 6c3e4d2 commit e60a6de

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/commands/compile.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
notNull,
3131
outputChannel,
3232
RateLimiter,
33-
replaceFile,
3433
routineNameTypeRegex,
3534
} from "../utils";
3635
import { StudioActions } from "./studio";
@@ -228,12 +227,14 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
228227
if (notIsfs(file.uri)) {
229228
const content = await api.getDoc(file.name).then((data) => data.result.content);
230229
exportedUris.add(file.uri.toString()); // Set optimistically
231-
await replaceFile(file.uri, content).catch((e) => {
232-
// Save failed, so remove this URI from the set
233-
exportedUris.delete(file.uri.toString());
234-
// Re-throw the error
235-
throw e;
236-
});
230+
await vscode.workspace.fs
231+
.writeFile(file.uri, Buffer.isBuffer(content) ? content : new TextEncoder().encode(content.join("\n")))
232+
.then(undefined, (e) => {
233+
// Save failed, so remove this URI from the set
234+
exportedUris.delete(file.uri.toString());
235+
// Re-throw the error
236+
throw e;
237+
});
237238
if (isClassOrRtn(file.uri)) {
238239
// Update the document index
239240
updateIndexForDocument(file.uri, undefined, undefined, content);

src/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ import {
104104
isClassOrRtn,
105105
addWsServerRootFolderData,
106106
getWsFolder,
107-
replaceFile,
108107
} from "./utils";
109108
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
110109
import { DocumentLinkProvider } from "./providers/DocumentLinkProvider";
@@ -1272,7 +1271,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12721271
// Generate the new content
12731272
const newContent = generateFileContent(uri, fileName, sourceContent);
12741273
// Write the new content to the file
1275-
return replaceFile(uri, newContent.content);
1274+
const wsEdit = new vscode.WorkspaceEdit();
1275+
wsEdit.replace(
1276+
uri,
1277+
new vscode.Range(0, 0, newContent.content.length + 1, 0),
1278+
newContent.content.join("\n"),
1279+
{
1280+
label: "ObjectScript autoAdjustName",
1281+
needsConfirmation: false,
1282+
}
1283+
);
1284+
await vscode.workspace.applyEdit(wsEdit);
12761285
})
12771286
);
12781287
}),

0 commit comments

Comments
 (0)