Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Access to "Open Editors" #15178

Closed
ChuckJonas opened this issue Nov 8, 2016 · 97 comments
Closed

API Access to "Open Editors" #15178

ChuckJonas opened this issue Nov 8, 2016 · 97 comments
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan workbench-editors Managing of editor widgets in workbench window
Milestone

Comments

@ChuckJonas
Copy link

I have a use case where I would like to be able to get a list of all the open editors (basically exactly what is shown here).

loginstructions_ts_-_vs-apex-debug

I understand that Editors are disposed but I just need a list of filenames.

Something like: workspace.openDocuments:Array<TextDocument> or even just workspace.openFiles:Array<string>.

Long term, it might be nice to have API access to operate on this list (EG: sort open editors pane by last opened, name, etc).

@ChuckJonas
Copy link
Author

Also, just wanted to add that this is blocking our vscode Salesforce IDE extension (mavensmate) from reaching feature parity with Sublime and Atom (and thus increasing the risk of it being abandoned by users).

Background: Salesforce requires that classes be compiled on their servers. In order to refactor multiple classes, you must send a single compilation request with all classes. Because compilation is slow, you typically only want to compile a subset of your project (IE only files related to a refactor).

The way existing salesforce IDE's handle this, is by allowing users to compile all open tabs.

@eamodio
Copy link
Contributor

eamodio commented Feb 28, 2017

@ChuckJonas I don't know if this is still blocking you, but I've used a hack here that might work for your depending on your use-case. You can see it in action in the Restore Editors extension.

@ChuckJonas
Copy link
Author

ChuckJonas commented Feb 28, 2017

@eamodio ahhh very nice! Never would have thought to use the workbench.action.nextEditor cmd to loop through all the editors.

Still seems like sort of a ridiculous hack for something that should obviously be accessible in the API.

@eamodio
Copy link
Contributor

eamodio commented Feb 28, 2017

@ChuckJonas totally agree, but it was the best I could figure out with the tools available ;)

@jrieken
Copy link
Member

jrieken commented Mar 24, 2017

fyi @dbaeumer

@lukebatchelor
Copy link

Cheers @eamodio, using your work around for something I'm working on too!

Also noticed I had to copy the way you wait in between executing commands because sometimes the activeEditor wont be set yet? Is that a separate issue worth reporting do you think?

@eamodio
Copy link
Contributor

eamodio commented Apr 28, 2017

@lukebatchelor getting an active editor of undefined is to be expected at this point. It gets set to undefined if there are really no editors, but also if the focus switches to a non-editor window

@lukebatchelor
Copy link

@eamodio, Im not getting undefined in these cases, but sometimes the same editor.

I assumed that was why have the 500ms pauses in your code?

@eamodio
Copy link
Contributor

eamodio commented Apr 29, 2017

@lukebatchelor sort of -- the timeout is because while the workbench.action.nextEditor will move to the next tab, if you have 2 non-text editors next to each other, the active editor becomes undefined when it switches to the first (and the active editor changed event will fire), but now when it switches to the next, it will still be undefined, but no event will fire, because it went from undefined to undefined -- so the timeout is a safety net for the event not firing

@lukebatchelor
Copy link

Oh okay. Thats different to what i was getting.

I'll try again but i was executing closeActiveEditor then logging the active editors document uri and would sometimes be the same still, until i added the pause. Same with nexrEditor.

Weird.

@loligans
Copy link

loligans commented May 19, 2017

This would be really nice to have!

I am working on an extension that takes encrypted files and decrypts them. The problem is I need the encrypted file path so that I can decrypt the file.

vscode doesn't let you access the file uri of a binary file because the active editor is undefined.

Alternatively it would be cool to allow the user to choose what encoding to display binary files. I would think the default would be UTF-8.

@jrieken
Copy link
Member

jrieken commented May 28, 2017

#11247 is about making the tab-model not only readable but also writeable, e.g. open a background-tab which we must consider when implementing this

@lramos15 lramos15 modified the milestones: November 2021, December 2021 Dec 1, 2021
mkhl added a commit to direnv/direnv-vscode that referenced this issue Dec 12, 2021
the lifecycle of a text document, which may map to a file,
is unrelated to whether that document is opened in an editor,
and closing an editor does not reliably close the document

(it _currently_ does for documents opened with the `vscode.open` command,
but apparently that's an implementation detail we cannot rely on)

there is currently no event in vscode for when a file is opened in an editor

this change ensures that our own commands notice
when we're opening a blocked .envrc file,
and documents the limitation

related upstream issues:
- microsoft/vscode#138924
- microsoft/vscode#114005
- microsoft/vscode#15178
- microsoft/vscode#133532
@lramos15 lramos15 modified the milestones: January 2022, February 2022 Jan 24, 2022
@martin-braun
Copy link

I would welcome this. The default open editors widget is not very convenient, this API could help to get a reliable extensions to replace it.

@GitMensch
Copy link
Contributor

Thank you for

the completion of one of our most upvoted issues

with April 2022.

As this feature request from November 2016 (issue no 15178) with 314 upvotes was done, is there now hope for #1012 (a feature request from December 2015 with 410 upvotes; not sure if the additional 10 hoorays, 35 hearts, 5 rockets and 11 eyes should be counted additional) to be re-inspected and at least get an up-to-date comment from the UX team?

@usama8800
Copy link

Is there a way to get a file uri or get to the TextEditor from a tab?

@ArturoDent
Copy link

ArturoDent commented May 9, 2022

tab.input.kind.uri for certain classes of tabs.

For example, see https://code.visualstudio.com/api/references/vscode-api#TabInputText

@github-actions github-actions bot locked and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan workbench-editors Managing of editor widgets in workbench window
Projects
None yet
Development

No branches or pull requests