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
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
You get the extension context object from activate
method, and then call ExtensionContext.extensioinPath
,
https://code.visualstudio.com/api/references/vscode-api#ExtensionContext
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);
});