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!
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.
By default, VS Code is installed under C:\Users\{Username}\AppData\Local\Programs\Microsoft VS Code .
Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder: Windows %USERPROFILE%\. vscode\extensions.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With