Skip to content

Commit f37896e

Browse files
committed
Allow running "pub get" for folders outside of the workspace
This allows running "pub get" for a Pub Workspace that is an ancestor of open folders. Fixes #5563
1 parent f049b10 commit f37896e

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎src/extension/commands/sdk.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,13 @@ export class BaseSdkCommands implements IAmDisposable {
4848
return;
4949

5050
const containingWorkspace = vs.workspace.getWorkspaceFolder(vs.Uri.file(folderToRunCommandIn));
51-
if (!containingWorkspace) {
52-
this.logger.error(`Failed to get workspace folder for ${folderToRunCommandIn}`);
53-
throw new Error(`Failed to get workspace folder for ${folderToRunCommandIn}`);
54-
}
55-
const containingWorkspacePath = fsPath(containingWorkspace.uri);
51+
const containingWorkspacePath = containingWorkspace ? fsPath(containingWorkspace.uri) : undefined;
5652

5753
// Display the relative path from the workspace root to the folder we're running, or if they're
5854
// the same then the folder name we're running in.
59-
const shortPath = path.relative(containingWorkspacePath, folderToRunCommandIn)
60-
|| path.basename(folderToRunCommandIn);
55+
const shortPath = containingWorkspacePath
56+
? path.relative(containingWorkspacePath, folderToRunCommandIn) || path.basename(folderToRunCommandIn)
57+
: path.basename(folderToRunCommandIn);
6158

6259
return handler(folderToRunCommandIn, args, shortPath, alwaysShowOutput);
6360
}

‎src/extension/project.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { isWithinWorkspace } from "./utils";
66
export const UPGRADE_TO_WORKSPACE_FOLDERS = "Mark Projects as Workspace Folders";
77

88
export function locateBestProjectRoot(folder: string, allowOutsideWorkspace = false): string | undefined {
9+
// TODO(dantup): Review places where allowOutsideWorkspace is effectively false, because opening sub-folders
10+
// of Pub Workspaces is probably not uncommon.
911
if (!folder)
1012
return undefined;
1113

‎src/extension/utils/vscode/projects.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function getFolderToRunCommandIn(logger: Logger, placeHolder: strin
1818
if (editor)
1919
file = fsPath(editor.document.uri);
2020
}
21-
const folder = file && locateBestProjectRoot(file);
21+
const folder = file && locateBestProjectRoot(file, !!selection);
2222

2323
if (folder)
2424
return folder;

0 commit comments

Comments
 (0)