如何获取当前打开的标签文件的根路径的路径 [英] How to get path for currently open tab file's root path

查看:29
本文介绍了如何获取当前打开的标签文件的根路径的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 Visual Studio 代码中获取多根工作区条件下的项目文件夹路径,但很难找到路径.以下脚本仅适用于单根工作区,但如何更改多根工作区.

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

});
}

推荐答案

代替 workspace.rootPath,使用 workspace.workspaceFolders 获取所有文件夹.

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

但是您的问题的标题是指当前打开的标签".这在 activate 函数中不是一个有意义的概念,它只在扩展首次初始化时运行.你会想要写一个命令处理程序(参见 扩展教程),并在该处理程序中,使用 window.activeTextEditor,并最终调用 window.getWorkspaceFolder.

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.

这篇关于如何获取当前打开的标签文件的根路径的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆