KEgg63
KEgg63

Reputation: 43

How do I search open editors for a file with a given extension?

I am writing a VSCode extension and I need to search the open editors for a .src file. Not the workspace. I can do vscode.workspace.findFiles() but I need something similar for the vscode.window.

Upvotes: 4

Views: 1351

Answers (1)

Gama11
Gama11

Reputation: 34138

Unfortunately, there's currently no API to list the open editors. There is however a pretty highly upvoted feature request for it - if this API is added, you could simply loop over the open editors and check the file paths for the extension.

API Access to "Open Editors" (#15178)

Note that there is a possible workaround suggested in one of the comments. The workbench.action.nextEditor command can be combined with the vscode.window.activeTextEditor API to loop over all open files and create a list along the way. However, this seems rather hacky.

Upvotes: 2

Related Questions