Skip to content

Commit 6619739

Browse files
Merge pull request #253 from gjsjohnmurray/fix-250
fix #250 Get isfs saving to work again
2 parents 6acb227 + 468fa5e commit 6619739

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

src/commands/compile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ export async function importAndCompile(askFLags = false, document?: vscode.TextD
202202
if (!file) {
203203
return;
204204
}
205-
if (!config("conn").active) {
205+
206+
// Do nothing if it is a local file and objectscript.conn.active is false
207+
if (document.uri.scheme === "file" && !config("conn").active) {
206208
return;
207209
}
208210

src/providers/FileSystemPovider/FileSystemProvider.ts

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -132,40 +132,51 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
132132
return;
133133
}
134134
const api = new AtelierAPI(uri);
135-
return this._lookupAsFile(uri)
136-
.then(() => Promise.reject())
137-
.catch((error) => {
138-
if (error.code === "FileNotFound") {
139-
return;
135+
return this._lookupAsFile(uri).then(
136+
() => {
137+
// Weirdly, if the file exists on the server we don't actually write its content here.
138+
// Instead we simply return as though we succeeded. The actual writing is done by our
139+
// workspace.onDidSaveTextDocument handler.
140+
return;
141+
},
142+
(error) => {
143+
if (error.code !== "FileNotFound" || !options.create) {
144+
return Promise.reject();
140145
}
141-
return Promise.reject();
142-
})
143-
.then(() => {
146+
// File doesn't exist on the server, and we are allowed to create it.
147+
// Create content (typically a stub).
144148
const newContent = this.generateFileContent(fileName, content);
145-
return api.putDoc(
146-
fileName,
147-
{
148-
...newContent,
149-
mtime: Date.now(),
150-
},
151-
false
152-
);
153-
})
154-
.catch((error) => {
155-
if (error.error?.result?.status) {
156-
throw vscode.FileSystemError.Unavailable(error.error.result.status);
157-
}
158-
throw vscode.FileSystemError.Unavailable(error.message);
159-
})
160-
.then((response) => {
161-
if (response && response.result.ext && response.result.ext[0] && response.result.ext[1]) {
162-
fireOtherStudioAction(OtherStudioAction.CreatedNewDocument, uri, response.result.ext[0]);
163-
fireOtherStudioAction(OtherStudioAction.FirstTimeDocumentSave, uri, response.result.ext[1]);
164-
}
165-
this._lookupAsFile(uri).then((entry) => {
166-
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
167-
});
168-
});
149+
150+
// Write it to the server
151+
return api
152+
.putDoc(
153+
fileName,
154+
{
155+
...newContent,
156+
mtime: Date.now(),
157+
},
158+
false
159+
)
160+
.catch((error) => {
161+
// Throw all failures
162+
if (error.error?.result?.status) {
163+
throw vscode.FileSystemError.Unavailable(error.error.result.status);
164+
}
165+
throw vscode.FileSystemError.Unavailable(error.message);
166+
})
167+
.then((response) => {
168+
// New file has been written
169+
if (response && response.result.ext && response.result.ext[0] && response.result.ext[1]) {
170+
fireOtherStudioAction(OtherStudioAction.CreatedNewDocument, uri, response.result.ext[0]);
171+
fireOtherStudioAction(OtherStudioAction.FirstTimeDocumentSave, uri, response.result.ext[1]);
172+
}
173+
// Sanity check that we find it there, then make client side update things
174+
this._lookupAsFile(uri).then(() => {
175+
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
176+
});
177+
});
178+
}
179+
);
169180
}
170181

171182
public delete(uri: vscode.Uri, options: { recursive: boolean }): void | Thenable<void> {

0 commit comments

Comments
 (0)