Senasiko
Senasiko

Reputation: 109

get currently focus file via VSCode extension API?

There is the steps.

  1. select a file or directory in workspaces.
  2. exec command via keybindings.
  3. get the selected file or directory path in command handler.

Command handler

vscode.commands.registerCommand('extension.myExtension', function (event) {
  // event is undefined.
  // how to do in here?
})

Upvotes: 1

Views: 2013

Answers (1)

Prince Arora
Prince Arora

Reputation: 362

Here's how you can do it

 vscode.commands.registerCommand('extension.myExtension', function (event) {
  const activeEditor = vscode.window.activeTextEditor;
    if(activeEditor){
       //For Getting File Path
       let filePath = activeEditor.document.uri.path;
       
    }
})

Upvotes: 1

Related Questions