Skip to content

Commit 4ba0677

Browse files
committed
fix #276 refresh from server correctly after isfs save and compile
1 parent 69c2cc3 commit 4ba0677

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/commands/compile.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,29 @@ What do you want to do?`,
122122
});
123123
}
124124

125-
function updateOthers(others: string[]) {
125+
function updateOthers(others: string[], baseUri: vscode.Uri) {
126+
let workspaceFolder = vscode.workspace.getWorkspaceFolder(baseUri);
127+
if (!workspaceFolder && baseUri.scheme !== "file") {
128+
// hack to deal with problem seen with isfs* schemes
129+
workspaceFolder = vscode.workspace.getWorkspaceFolder(baseUri.with({ path: "" }));
130+
}
131+
const workspaceFolderName = workspaceFolder ? workspaceFolder.name : "";
126132
others.forEach((item) => {
127-
const uri = DocumentContentProvider.getUri(item);
128-
documentContentProvider.update(uri);
133+
const uri = DocumentContentProvider.getUri(item, workspaceFolderName);
134+
if (uri.scheme === FILESYSTEM_SCHEMA || uri.scheme === FILESYSTEM_READONLY_SCHEMA) {
135+
// Massage uri.path to change the first N-1 dots to slashes, where N is the number of slashes in baseUri.path
136+
// For example, when baseUri.path is /Foo/Bar.cls and uri.path is /Foo.Bar.1.int
137+
const partsToConvert = baseUri.path.split("/").length - 1;
138+
const dotParts = uri.path.split(".");
139+
const correctPath =
140+
dotParts.length <= partsToConvert
141+
? uri.path
142+
: dotParts.slice(0, partsToConvert).join("/") + "." + dotParts.slice(partsToConvert).join(".");
143+
console.log(`updateOthers: uri.path=${uri.path} baseUri.path=${baseUri.path} correctPath=${correctPath}`);
144+
fileSystemProvider.fireFileChanged(uri.with({ path: correctPath }));
145+
} else {
146+
documentContentProvider.update(uri);
147+
}
129148
});
130149
}
131150

@@ -145,15 +164,14 @@ export async function loadChanges(files: CurrentFile[]): Promise<any> {
145164
if (file.uri.scheme === "file") {
146165
fs.writeFileSync(file.fileName, content);
147166
} else if (file.uri.scheme === FILESYSTEM_SCHEMA || file.uri.scheme === FILESYSTEM_READONLY_SCHEMA) {
148-
fileSystemProvider.writeFile(file.uri, Buffer.from(content), {
149-
overwrite: true,
150-
create: false,
151-
});
167+
fileSystemProvider.fireFileChanged(file.uri);
152168
}
153169
})
154170
.then(() => api.actionIndex([file.name]))
155171
.then((data) => data.result.content[0].others)
156-
.then(updateOthers)
172+
.then((others) => {
173+
updateOthers(others, file.uri);
174+
})
157175
)
158176
);
159177
}
@@ -191,13 +209,14 @@ async function compile(docs: CurrentFile[], flags?: string): Promise<any> {
191209
outputChannel.show(true);
192210
});
193211
}
194-
return [];
212+
// Even when compile failed we should still fetch server changes
213+
return docs;
195214
})
196215
)
197216
.then(loadChanges);
198217
}
199218

200-
export async function importAndCompile(askFLags = false, document?: vscode.TextDocument): Promise<any> {
219+
export async function importAndCompile(askFlags = false, document?: vscode.TextDocument): Promise<any> {
201220
const file = currentFile(document);
202221
if (!file) {
203222
return;
@@ -209,7 +228,7 @@ export async function importAndCompile(askFLags = false, document?: vscode.TextD
209228
}
210229

211230
const defaultFlags = config().compileFlags;
212-
const flags = askFLags ? await compileFlags() : defaultFlags;
231+
const flags = askFlags ? await compileFlags() : defaultFlags;
213232
return importFile(file)
214233
.catch((error) => {
215234
// console.error(error);

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export function checkConnection(clearCookies = false, uri?: vscode.Uri): void {
296296
})
297297
.finally(() => {
298298
explorerProvider.refresh();
299-
if (schemas.includes(uri.scheme)) {
299+
if (uri && schemas.includes(uri.scheme)) {
300300
vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer");
301301
}
302302
});

src/providers/FileSystemPovider/FileSystemProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
2222
this.onDidChangeFile = this._emitter.event;
2323
}
2424

25+
public fireFileChanged(uri: vscode.Uri): void {
26+
this._fireSoon({ type: vscode.FileChangeType.Changed, uri });
27+
}
28+
2529
public stat(uri: vscode.Uri): Promise<vscode.FileStat> {
2630
return this._lookup(uri);
2731
}

0 commit comments

Comments
 (0)