vscode插件开发----获得当前打开文档对应的工作区根目录
代码如下:
export function activate(context:any) {
// 注册一个命令
let disposable = vscode.commands.registerCommand('codeStat.countCurFile', function () {
let editor = vscode.window.activeTextEditor;
if (editor) {
const currentDocumentUri = editor.document.uri;
const selectedWorkspaceFolder = vscode.workspace.getWorkspaceFolder(currentDocumentUri);
if (selectedWorkspaceFolder) {
vscode.window.showInformationMessage(selectedWorkspaceFolder.uri.fsPath);
}
}
});
context.subscriptions.push(disposable); // 插件退出时释放资源
}