Skip to content

Commit 3057b76

Browse files
authored
Fix issue where Undo after a save deletes the file being edited (#1524)
1 parent 36817ac commit 3057b76

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## [3.0.1] 04-Apr-2025
4+
- Fixes
5+
- Fix issue where `Undo` after a save deletes the file being edited (#1524)
6+
- Fix endless save loop when one local workspace folder is a subfolder of another (#1525)
7+
38
## [3.0.0] 02-Apr-2025
49
- Enhancements
510
- Client-side editing overhaul (#1401, #1470, #1515, #1520):

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ To unlock these features (optional):
5555

5656
1. Download and install a beta version from GitHub. This is necessary because Marketplace does not allow publication of extensions that use proposed APIs.
5757
- Go to https://github.com/intersystems-community/vscode-objectscript/releases
58-
- Locate the beta immediately above the release you installed from Marketplace. For instance, if you installed `3.0.0`, look for `3.0.1-beta.1`. This will be functionally identical to the Marketplace version apart from being able to use proposed APIs.
59-
- Download the VSIX file (for example `vscode-objectscript-3.0.1-beta.1.vsix`) and install it. One way to install a VSIX is to drag it from your download folder and drop it onto the list of extensions in the Extensions view of VS Code.
58+
- Locate the beta immediately above the release you installed from Marketplace. For instance, if you installed `3.0.1`, look for `3.0.2-beta.1`. This will be functionally identical to the Marketplace version apart from being able to use proposed APIs.
59+
- Download the VSIX file (for example `vscode-objectscript-3.0.2-beta.1.vsix`) and install it. One way to install a VSIX is to drag it from your download folder and drop it onto the list of extensions in the Extensions view of VS Code.
6060

6161
2. From [Command Palette](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_command-palette) choose `Preferences: Configure Runtime Arguments`.
6262
3. In the argv.json file that opens, add this line (required for both Stable and Insiders versions of VS Code):

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)