Skip to content

Check all local folders in multi-root workspace for local copy of file #785

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 1 commit into from
Nov 29, 2021
Merged
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
34 changes: 34 additions & 0 deletions src/providers/DocumentContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@ export class DocumentContentProvider implements vscode.TextDocumentContentProvid
// Exists as a local file and we aren't viewing a different namespace on the same server,
// so return a file:// uri that will open the local file.
return vscode.Uri.file(localFile);
} else {
// The local file doesn't exist in this folder, so check any other
// local folders in this workspace if it's a multi-root workspace
const wFolders = vscode.workspace.workspaceFolders;
if (wFolders && wFolders.length > 1) {
// This is a multi-root workspace
for (const wFolder of wFolders) {
if (wFolder.uri.scheme === "file" && wFolder.name !== workspaceFolder) {
// This isn't the folder that we checked originally
const wFolderConn = config("conn", wFolder.name);
const compareConns = (): boolean => {
if (wFolderConn.ns === conn.ns) {
if (wFolderConn.server && conn.server) {
if (wFolderConn.server === conn.server) {
return true;
}
} else if (!wFolderConn.server && !conn.server) {
if (wFolderConn.host === conn.host && wFolderConn.port === conn.port) {
return true;
}
}
}
return false;
};
if (compareConns() && (!namespace || namespace === wFolderConn.ns)) {
// This folder is connected to the same server:ns combination as the original folder
const wFolderFile = this.getAsFile(name, wFolder.name);
if (wFolderFile) {
return vscode.Uri.file(wFolderFile);
}
}
}
}
}
}
const { active } = conn;
if (!active) {
Expand Down