Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the currently open file in VSCode

Is there a command in the vscode namespace that allows you to get the TextDocument instance for the currently open file? I found vscode.workspace.onDidOpenTextDocument, but it doesn't work for files that are open on launch

like image 913
watzon Avatar asked Apr 04 '16 23:04

watzon


1 Answers

A few options depending on your needs:

// Single active editor. Editors have a `.document` property
vscode.window.activeTextEditor

// All showing text editors. For a split view, there are two active editors 
vscode.window.visibleTextEditors

// All open documents that vscode knows about. Do not have to be showing
vscode.workspace.textDocuments

See the vscode API for more info: https://code.visualstudio.com/docs/extensionAPI/vscode-api

like image 157
Matt Bierner Avatar answered Oct 23 '22 22:10

Matt Bierner