Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

typescript - vscode api for file explorer

I am onto writing a VSCode extension and need to create files / remove files based in a folder / subfolder selected by the user.

Is there a way to find selected folder from the explorer tree through visual studio code api? One can track the opened file through active text editor or onDidOpenTextDocument(). I am interested in finding if user has selected a folder and if so the path to selected folder.

For example: workspace.rootPath provides a root of the opened project. Similarly, how do I identify which subfolder is selected by the user (if any).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I finally figured it out, I've been looking for a while and found that the documentation states that :

Note: When a command is invoked from a (context) menu, VS Code tries to infer the currently selected resource and passes that as a parameter when invoking the command. For instance, a menu item inside the Explorer is passed the URI of the selected resource and a menu item inside an editor is passed the URI of the document. vscode extension contribution points

That let me to this question/bug on github Get selected file folder, which in turn led me to the github repo of stef-levesque/vscode-hexdump from which I got the following:

let disposable = Commands.registerCommand('extension.superExtension', async (fileUri) => {
    console.log(fileUri);
})

Note: when the context menu is used in the editor this will be empty.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...