VS Code extension - get full path

JM. Benitez picture JM. Benitez · Sep 19, 2016 · Viewed 13k times · Source

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!

Answer

Bingoabs picture Bingoabs · Dec 25, 2018

If you open the folder, then you can get the workspace variable.

let folderName = vscode.workspace.name; // get the open folder name
let folderPath = vscode.workspace.rootPath; // get the open folder path

More detail can get from VS Code API