Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code extension - get full path

Tags:

I am writing a plugin for VS Code and I need to know the path of the file which is calling the extension, either if it was called from the editor context menu or explorer context menu or the user simply typed the extension command.

function activate(context){     // get full path of the file somehow } 

Thanks in advance!

like image 478
JM. Benitez Avatar asked Sep 19 '16 09:09

JM. Benitez


People also ask

How do I get the path of a file in VS Code?

You can invoke the vscode window property to retrieve the file path or name depending on what you are looking for. This will give you the name of the file open in the current Tab when you execute the command.

How do I find my VS Code path?

By default, VS Code is installed under C:\Users\{Username}\AppData\Local\Programs\Microsoft VS Code .

Where is VS Code extensions folder?

Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder: Windows %USERPROFILE%\. vscode\extensions.


1 Answers

If you need the File use uri.fsPath If you need the Workspace Folder use uri.path

if(vscode.workspace.workspaceFolders !== undefined) {     let wf = vscode.workspace.workspaceFolders[0].uri.path ;     let f = vscode.workspace.workspaceFolders[0].uri.fsPath ;       message = `YOUR-EXTENSION: folder: ${wf} - ${f}` ;      vscode.window.showInformationMessage(message); }  else {     message = "YOUR-EXTENSION: Working folder not found, open a folder an try again" ;      vscode.window.showErrorMessage(message); } 

More detail can get from VS Code API

like image 62
Bingoabs Avatar answered Sep 23 '22 14:09

Bingoabs