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);   // 插件退出时释放资源
}
posted @ 2023-06-04 22:06  顺其自然,道法自然  阅读(740)  评论(0编辑  收藏  举报