Skip to content

refactor: Stop using the 'vscode.workspace.rootPath' API #443

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
Oct 2, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function testSolution(uri?: vscode.Uri): Promise<void> {
}
break;
case ":file":
const testFile: vscode.Uri[] | undefined = await showFileSelectDialog();
const testFile: vscode.Uri[] | undefined = await showFileSelectDialog(filePath);
if (testFile && testFile.length) {
const input: string = (await fse.readFile(testFile[0].fsPath, "utf-8")).trim();
if (input) {
Expand Down
19 changes: 15 additions & 4 deletions src/utils/uiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export async function openKeybindingsEditor(query?: string): Promise<void> {
await vscode.commands.executeCommand("workbench.action.openGlobalKeybindings", query);
}

export async function showFileSelectDialog(): Promise<vscode.Uri[] | undefined> {
const defaultUri: vscode.Uri | undefined = vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined;
export async function showFileSelectDialog(fsPath?: string): Promise<vscode.Uri[] | undefined> {
const defaultUri: vscode.Uri | undefined = getBelongingWorkspaceFolderUri(fsPath);
const options: vscode.OpenDialogOptions = {
defaultUri,
canSelectFiles: true,
Expand All @@ -92,8 +92,19 @@ export async function showFileSelectDialog(): Promise<vscode.Uri[] | undefined>
return await vscode.window.showOpenDialog(options);
}

export async function showDirectorySelectDialog(): Promise<vscode.Uri[] | undefined> {
const defaultUri: vscode.Uri | undefined = vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined;
function getBelongingWorkspaceFolderUri(fsPath: string | undefined): vscode.Uri | undefined {
let defaultUri: vscode.Uri | undefined;
if (fsPath) {
const workspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(fsPath));
if (workspaceFolder) {
defaultUri = workspaceFolder.uri;
}
}
return defaultUri;
}

export async function showDirectorySelectDialog(fsPath?: string): Promise<vscode.Uri[] | undefined> {
const defaultUri: vscode.Uri | undefined = getBelongingWorkspaceFolderUri(fsPath);
const options: vscode.OpenDialogOptions = {
defaultUri,
canSelectFiles: false,
Expand Down