How to get path for currently open tab file's root path

╄→гoц情女王★ 提交于 2019-12-13 03:07:50

问题


Tried to get project folder path in multi root workspace condition in visual studio code but facing very difficult to find the path. Below script only will work single root workspace But How to change for multi root workspace.

var vscode = require("vscode");
var path = require("path");
exports.activate = context => {
const searchoption = 
vscode.commands.registerCommand('extension.search', () => {

   let folderPath = vscode.workspace.rootPath; // get the open file's project folder path

});
}

回答1:


Instead of workspace.rootPath, use workspace.workspaceFolders to get all of the folders.

But the title of your question refers to the "currently open tab". That isn't a meaningful concept in the activate function, which only runs when the extension first initializes. You'll want to instead write, say, a command handler (see the extension tutorial), and within that handler, use window.activeTextEditor, and eventually call window.getWorkspaceFolder.



来源:https://stackoverflow.com/questions/57822840/how-to-get-path-for-currently-open-tab-files-root-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!