简体   繁体   中英

How to open folder picker dialog in vscode with a pre-selected file?

vscode.window.showOpenDialog accepts a defaultUri option, but it only seems to apply at the folder level.

Anyone knows how can I open a dialog where a file is already pre-selected for the user if the file exists?

Im'currently doing this:

const d = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, 'okteto.yml');
return vscode.window.showOpenDialog({
        defaultUri: d,
        openLabel: label,
        canSelectMany: false,
        canSelectFiles: true,
        canSelectFolders: false,
        filters: {
            'Okteto Manifest': ['yml', 'yaml']
        }
    });

When the dialog is opened, I'd like the okteto.yml file to be pre-selected if it exists. With the code above, the folder is selected, but not the specific file I want.

Change this:

const d = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, 'okteto.yml');

to

const d = vscode.Uri.joinPath(vscode.workspace.workspaceFolders[0].uri, 'okteto.yml');

defaultUri takes a Uri so vscode.Uri.joinPath() is a good choice here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM