Reputation: 21
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
Upvotes: 1
Views: 853
Reputation: 4265
If you are looking to get the installed extension path, context api can help here
export function activate(context: vscode.ExtensionContext) {
const disposable = vscode.commands.registerCommand('jenkins-snippet.jenkins-snippet', async () => {
const extensionPath = context.extensionPath; // extension installed path
more info - https://code.visualstudio.com/api/references/vscode-api#ExtensionContext
Upvotes: 0
Reputation: 103
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);
});
Upvotes: 0
Reputation: 63173
You get the extension context object from activate
method, and then call ExtensionContext.extensioinPath
,
https://code.visualstudio.com/api/references/vscode-api#ExtensionContext
Upvotes: 2