Skip to content

Fix issue where Undo after a save deletes the file being edited #1524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [3.0.1] 04-Apr-2025
- Fixes
- Fix issue where `Undo` after a save deletes the file being edited (#1524)
- Fix endless save loop when one local workspace folder is a subfolder of another (#1525)

## [3.0.0] 02-Apr-2025
- Enhancements
- Client-side editing overhaul (#1401, #1470, #1515, #1520):
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ To unlock these features (optional):

1. Download and install a beta version from GitHub. This is necessary because Marketplace does not allow publication of extensions that use proposed APIs.
- Go to https://github.com/intersystems-community/vscode-objectscript/releases
- 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.
- 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.
- 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.
- 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.

2. From [Command Palette](https://code.visualstudio.com/docs/getstarted/tips-and-tricks#_command-palette) choose `Preferences: Configure Runtime Arguments`.
3. In the argv.json file that opens, add this line (required for both Stable and Insiders versions of VS Code):
Expand Down
15 changes: 8 additions & 7 deletions src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
notNull,
outputChannel,
RateLimiter,
replaceFile,
routineNameTypeRegex,
} from "../utils";
import { StudioActions } from "./studio";
Expand Down Expand Up @@ -228,12 +227,14 @@ export async function loadChanges(files: (CurrentTextFile | CurrentBinaryFile)[]
if (notIsfs(file.uri)) {
const content = await api.getDoc(file.name).then((data) => data.result.content);
exportedUris.add(file.uri.toString()); // Set optimistically
await replaceFile(file.uri, content).catch((e) => {
// Save failed, so remove this URI from the set
exportedUris.delete(file.uri.toString());
// Re-throw the error
throw e;
});
await vscode.workspace.fs
.writeFile(file.uri, Buffer.isBuffer(content) ? content : new TextEncoder().encode(content.join("\n")))
.then(undefined, (e) => {
// Save failed, so remove this URI from the set
exportedUris.delete(file.uri.toString());
// Re-throw the error
throw e;
});
if (isClassOrRtn(file.uri)) {
// Update the document index
updateIndexForDocument(file.uri, undefined, undefined, content);
Expand Down
13 changes: 11 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ import {
isClassOrRtn,
addWsServerRootFolderData,
getWsFolder,
replaceFile,
} from "./utils";
import { ObjectScriptDiagnosticProvider } from "./providers/ObjectScriptDiagnosticProvider";
import { DocumentLinkProvider } from "./providers/DocumentLinkProvider";
Expand Down Expand Up @@ -1272,7 +1271,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
// Generate the new content
const newContent = generateFileContent(uri, fileName, sourceContent);
// Write the new content to the file
return replaceFile(uri, newContent.content);
const wsEdit = new vscode.WorkspaceEdit();
wsEdit.replace(
uri,
new vscode.Range(0, 0, newContent.content.length + 1, 0),
newContent.content.join("\n"),
{
label: "ObjectScript autoAdjustName",
needsConfirmation: false,
}
);
await vscode.workspace.applyEdit(wsEdit);
})
);
}),
Expand Down