Skip to content

Commit 01f5a28

Browse files
authored
refactor: Stop using the 'vscode.workspace.rootPath' API (LeetCode-OpenSource#443)
1 parent 8d50a2f commit 01f5a28

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/commands/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export async function testSolution(uri?: vscode.Uri): Promise<void> {
6565
}
6666
break;
6767
case ":file":
68-
const testFile: vscode.Uri[] | undefined = await showFileSelectDialog();
68+
const testFile: vscode.Uri[] | undefined = await showFileSelectDialog(filePath);
6969
if (testFile && testFile.length) {
7070
const input: string = (await fse.readFile(testFile[0].fsPath, "utf-8")).trim();
7171
if (input) {

src/utils/uiUtils.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export async function openKeybindingsEditor(query?: string): Promise<void> {
8080
await vscode.commands.executeCommand("workbench.action.openGlobalKeybindings", query);
8181
}
8282

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

95-
export async function showDirectorySelectDialog(): Promise<vscode.Uri[] | undefined> {
96-
const defaultUri: vscode.Uri | undefined = vscode.workspace.rootPath ? vscode.Uri.file(vscode.workspace.rootPath) : undefined;
95+
function getBelongingWorkspaceFolderUri(fsPath: string | undefined): vscode.Uri | undefined {
96+
let defaultUri: vscode.Uri | undefined;
97+
if (fsPath) {
98+
const workspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(fsPath));
99+
if (workspaceFolder) {
100+
defaultUri = workspaceFolder.uri;
101+
}
102+
}
103+
return defaultUri;
104+
}
105+
106+
export async function showDirectorySelectDialog(fsPath?: string): Promise<vscode.Uri[] | undefined> {
107+
const defaultUri: vscode.Uri | undefined = getBelongingWorkspaceFolderUri(fsPath);
97108
const options: vscode.OpenDialogOptions = {
98109
defaultUri,
99110
canSelectFiles: false,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy