1

In visual studio code extension code we want path of extension where it is installed in system

as in windows it is "%USERPROFILE%.vscode\extensions"

but in extension code how can we get it

Sahil
  • 21
  • 4
  • on my linux system you can find the path to a program (for example an extension) by using the whereis command on the terminal. There is probably the same or a similar command in windows. – user3425506 Feb 19 '22 at 19:00

2 Answers2

2

You get the extension context object from activate method, and then call ExtensionContext.extensioinPath,

https://code.visualstudio.com/api/references/vscode-api#ExtensionContext

Lex Li
  • 60,503
  • 9
  • 116
  • 147
0

I also had this problem in making the extension.

First, in this file, make a command in explorer/context, like the code below:

 "contributes": {
 "commands": [
      {
        "command": "demo.pathFolder",
        "title": "Get Path folder"
      }],
    "menus": {
      "explorer/context": [
        {
          "when": "explorerResourceIsFolder == true",
          "command": "demo.pathFolder"
        }
  ]
 }
}

Then you have to change extension.ts code. Like the example below.

vscode.commands.registerCommand('demo.pathFolder', (p: { fsPath: string }) => {

   // p is an object whose path is fsPath.

   console.log(p.fsPath);

});

Maybe this link can help you.

Amir Kabir
  • 33
  • 5