File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments