我正在为 VS Code 编写一个插件,我需要知道调用扩展的文件的路径,无论是从编辑器上下文菜单或资源管理器上下文菜单中调用,还是用户只是键入扩展命令。
function activate(context){
// get full path of the file somehow
}
提前致谢!
最佳答案
如果你需要文件使用uri.fsPath
如果您需要工作区文件夹,请使用 uri.path
if(vscode.workspace.workspaceFolders !== undefined) {
let wf = vscode.workspace.workspaceFolders[0].uri.path ;
let f = vscode.workspace.workspaceFolders[0].uri.fsPath ;
message = `YOUR-EXTENSION: folder: ${wf} - ${f}` ;
vscode.window.showInformationMessage(message);
}
else {
message = "YOUR-EXTENSION: Working folder not found, open a folder an try again" ;
vscode.window.showErrorMessage(message);
}
更多细节可以从VS Code API获得
关于javascript - VS 代码扩展 - 获取完整路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39569993/