Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...