1

How to get my angular project folder path in VS code extension.js.I tried but not working. Example my angular project name "universe" and "bookworld" I opened in visual studio code.

universe - project folder name

-e2e
-node_modules
-src
-angular.json
-package.json
-package-lock.json
-README
-tsconfig.json
-tslint.json

bookworld - project folder name

-e2e
-node_modules
-src
-angular.json
-package.json
-package-lock.json
-README
-tsconfig.json
-tslint.json

extension.js:

const vscode = require('vscode');
const path =  require('path');

function activate(context) {

  const fullPath = path.dirname("c://mamp/htdocs/projects/ps/src/app/app.component.html");
const regexResp = /^(.*?)node_modules/.exec(fullPath);
const nodemodulesPath = regexResp ? regexResp[1] : fullPath;
console.log(nodemodulesPath );


//Example if i open package.json from universe in vs code project output should be like var currentprojectfolderpath =c://mamp/htdocs/main/universe

//Example if i open tslint.json from universe project in vs code output should be like var currentprojectfolderpath =c://mamp/htdocs/main/bookworld

}

How can I get currently opened file's project folder path?

Malli
  • 83
  • 1
  • 8
  • Might help: [project root in node](https://stackoverflow.com/a/18721515/6082280) – ambianBeing Aug 30 '19 at 10:53
  • Thai is only working for nodejs not working in VS code extension – Malli Aug 30 '19 at 11:01
  • Not working : showError(vscode.workspace.workspaceFolders[0].uri.paths[0].split('node_modules')[0].slice(0, -1)); – Malli Aug 30 '19 at 11:05
  • @ambianBeing: vscode.window.activeTextEditor.document.uri.fsPath If I use this I am getting current file path but I want current project folder path like var currentprojectfolderpath =c://mamp/htdocs/main/universe – Malli Aug 30 '19 at 11:52

0 Answers0