Skip to content

Commit ded0326

Browse files
Merge pull request #366 from timleavitt/fix-extension-reload
Fix extension reload
2 parents 56a1c82 + 08ccb14 commit ded0326

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/commands/studio.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ function getOtherStudioActionLabel(action: OtherStudioAction): string {
5959
return label;
6060
}
6161

62+
// Used to avoid triggering the edit listener when files are reloaded by an extension
63+
const suppressEditListenerMap = new Map<string, boolean>();
64+
6265
class StudioActions {
6366
private uri: vscode.Uri;
6467
private api: AtelierAPI;
@@ -86,10 +89,6 @@ class StudioActions {
8689
outputChannel.appendLine(errorText);
8790
outputChannel.show();
8891
}
89-
if (userAction.reload) {
90-
const document = vscode.window.activeTextEditor.document;
91-
loadChanges([currentFile(document)]);
92-
}
9392
if (config().studioActionDebugOutput) {
9493
outputChannel.appendLine(JSON.stringify(userAction));
9594
}
@@ -267,6 +266,14 @@ class StudioActions {
267266
}
268267
const actionToProcess = data.result.content.pop();
269268

269+
if (actionToProcess.reload) {
270+
const document = vscode.window.activeTextEditor.document;
271+
const file = currentFile(document);
272+
// Avoid the reload triggering the edit listener here
273+
suppressEditListenerMap.set(file.uri.toString(), true);
274+
await loadChanges([file]);
275+
}
276+
270277
// CSP pages should not have a progress bar
271278
if (actionToProcess.action === 2) {
272279
resolve();
@@ -359,6 +366,12 @@ class StudioActions {
359366
label: getOtherStudioActionLabel(action),
360367
};
361368
if (action === OtherStudioAction.AttemptedEdit) {
369+
// Check to see if this "attempted edit" was an action by this extension due to a reload.
370+
// There's no way to detect at a higher level from the event.
371+
if (suppressEditListenerMap.has(this.uri.toString())) {
372+
suppressEditListenerMap.delete(this.uri.toString());
373+
return;
374+
}
362375
const query = "select * from %Atelier_v1_Utils.Extension_GetStatus(?)";
363376
this.api.actionQuery(query, [this.name]).then((statusObj) => {
364377
const docStatus = statusObj.result.content.pop();

0 commit comments

Comments
 (0)