How to get currently opened file's project folder path in visual studio code extension.js

我与影子孤独终老i 提交于 2020-01-16 14:29:29

问题


I am trying to get currently opened file's project folder path in visual studio code extension but not working for Multi-root Workspaces.

Now i am getting path value is empty.

Currently i opened project-ws folder files app.component.html then press ctrl+shift+p on the files tab then box will open. if i click "Get project folder path" from extension box path value should be like C:\xampp\htdocs\projects\project-ws.

If i opened project-bh folder any files then press ctrl+shift+p on the files tab then box will open. if i click "Get project folder path" from extension box path value should be like C:\xampp\htdocs\projects\project-bh.

I could not find the mistake from my code.Anyone can resolve this issue?

Check this url then you can test in your vs code extension you can easily understand : https://github.com/jasonnutter/vscode-search-node-modules same concept i have used from this for my extension.

.

Press Ctrl+Shift+p = to see extension and click "Get project folder path" then path message should be come.

C:/Users/ADMIN/.vscode/extensions/getprojectpath/extension.js:

  const vscode = require('vscode');
  const path = require('path');
  exports.activate = context => {

  const searchMyModules = vscode.commands.registerCommand('extension.search', () => {

  const preferences = vscode.workspace.getConfiguration('files.exclude');

  const getCurrentlyopenedtabprojectfolderpath = async() => {

  const editor = vscode.window.activeTextEditor;
  if (!editor || !vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length < 2) {
    return null;
  }
  let path;
  const resource = editor.document.uri;
  if (resource.scheme === 'file') {
    const folder = vscode.workspace.getWorkspaceFolder(resource);
    if (!folder) {
      path = `$(alert) <outside workspace> → ${basename(resource.fsPath)}`;
    } else {
      path = `$(file-submodule) ${basename(folder.uri.fsPath)} (${folder.index + 1} of ${vscode.workspace.workspaceFolders.length}) → $(file-code) ${basename(resource.fsPath)}`;

    }
  }
  return {
    path
  };
}

 getCurrentlyopenedprojectpath().then(result => {
  vscode.window.showInformationMessage(result.path)
 })
 })
 }

 exports.deactivate = () => {};

来源:https://stackoverflow.com/questions/57811209/how-to-get-currently-opened-files-project-folder-path-in-visual-studio-code-ext

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