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

Tab model API #133532

Closed
lramos15 opened this issue Sep 21, 2021 · 24 comments
Closed

Tab model API #133532

lramos15 opened this issue Sep 21, 2021 · 24 comments
Assignees
Labels
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders verification-needed Verification of issue is requested verified Verification succeeded workbench-tabs VS Code editor tab issues
Milestone

Comments

@lramos15
Copy link
Member

There are many cases where the user wants to be able to either get the state of opened editors / tabs or modify it. This has been conveyed in multiple issues such as #15178. This issue will serve to track the proposal and API development for an API which allows the reading and modification of the tabs.

The current proposal is:

//#region https://github.com/Microsoft/vscode/issues/15178
/**
* Represents a tab within the window
*/
export interface Tab {
/**
* The text displayed on the tab
*/
readonly label: string;
/**
* The index of the tab within the view column
*/
readonly index: number;
/**
* The column the tab belongs to
*/
readonly viewColumn: ViewColumn;
/**
* The resource represented by the tab if availble.
* Note: Not all tabs have a resource associated with them.
*/
readonly resource?: Uri;
/**
* The identifier of the view contained in the tab
* This is equivalent to `viewType` for custom editors and `notebookType` for notebooks.
* The built-in text editor has an id of 'default' for all configurations.
*/
readonly viewId?: string;
/**
* Whether or not the tab is currently active
* Dictated by being the selected tab in the active group
*/
readonly isActive: boolean;
/**
* Closes the tab object
*/
close(): void;
/**
* Sets the label of the tab
*/
setLabel(label: string): void;
/**
* Moves the tab to the new index and view column
* @param index The new index of the tab within the current group
* @param viewColumn The new view column of the tab.
*/
move(index: number, viewColumn: ViewColumn): void;
}
export namespace window {
/**
* A list of all opened tabs
* Ordered from left to right
*/
export const tabs: readonly Tab[];
/**
* The currently active tab
* Undefined if no tabs are currently opened
*/
export const activeTab: Tab | undefined;
/**
* An {@link Event} which fires when the array of {@link window.tabs tabs}
* has changed.
*/
export const onDidChangeTabs: Event<readonly Tab[]>;
/**
* An {@link Event} which fires when the {@link window.activeTab activeTab}
* has changed.
*/
export const onDidChangeActiveTab: Event<Tab | undefined>;
/**
* Opens a tab
* @param tab The object representing the tab you want to open
* @returns The opened tab
*/
export function openTab(tab: Exclude<Tab, Function>): Thenable<Tab>;
}
//#endregion

@lramos15 lramos15 added api workbench-editors Managing of editor widgets in workbench window api-proposal labels Sep 21, 2021
@lramos15 lramos15 added this to the September 2021 milestone Sep 21, 2021
@lramos15 lramos15 self-assigned this Sep 21, 2021
@JohnnyCrazy
Copy link
Contributor

Sounds very promising and seems like a good fit for #95266, which was stalled for quite some time because of a missing API to detect if all editors for a specific resource URI have been closed. onDidChangeTabs fits this usecase quite well.

I will try to get #95266 running within a week and report my findings :)

@msftwindowslinux
Copy link
Contributor

msftwindowslinux commented Sep 23, 2021

I mentioned this in #9498, but one thing that seems missing from the window api is a proper "positional" identifier. The currently available ViewColumn isn't enough since there's ambiguity wrt vertical / horizontal splits, let alone editor size (which I could live without since that's likely to be even more difficult).

This request may be out of scope of this exact discussion since the original issue mainly wanted the list of tabs within an editor. But lots of the comments in the thread was about restoring editor states, which I think would require something like what I described, and does seem to fit in the "window" part of this api.

@lramos15
Copy link
Member Author

@msftwindowslinux You are correct there is a gap with regards to the grid layout because we have always used ViewColumn due to it being a way to link the old and new layout world. I'll write this down and bring it up during the next team discussion to see if we would like to prioritize this layout restoring case. For now we have a command vscode.setEditorLayout which you can find more info about here https://code.visualstudio.com/api/references/commands

@msftwindowslinux
Copy link
Contributor

msftwindowslinux commented Sep 23, 2021

Thanks for the note! Is there a similar getEditorLayout, or would that be a possible addition? I think having an idempotent setEditorLayout(getEditorLayout()) would solve the "workspace saving" problem without being too intrusive.

@lramos15
Copy link
Member Author

Thanks for the note! Is there a similar getEditorLayout, or would that be a possible addition? I think having an idempotent setEditorLayout(getEditorLayout()) would solve the "workspace saving" problem without being too intrusive.

No there is currently not, and no plans to add one at this time

@Kaniee
Copy link

Kaniee commented Sep 28, 2021

Might be a silly question, because I don't know much about the vscode internals but I'll ask anyways:
How is the icon for a tab selected if it's a tab like Settings or the Jupyter Interactive Window? Currently I only see the default icon for those tabs. Would it make sense to provide a icon field in this API?

And what are your thought on a "isPinned" and "isSaved" property for a tab?

@lramos15
Copy link
Member Author

@Kaniee No worries always wiling to answer any questions. No plans to support customizable icons at this point in time. As for isPinned or isSaved / isDirty if you have a viable use case I would be happy to explore those but to avoid bloat we're trying to go with the minimal set of properties

@Kaniee
Copy link

Kaniee commented Sep 28, 2021

@lramos15 I don't have a specific use case in mind for 'isPinned' or 'isSaved'. It just crossed my mind.

I'm sure you have good reasons to not support customizable icons but would you mind sharing those?

@lramos15
Copy link
Member Author

I'm sure you have good reasons to not support customizable icons but would you mind sharing those?

It's just not on the radar at the moment since there's always additional complexity involved with serving user provided content in a secure manner. There are discussions around allowing the coloring of tabs, but that's in the early stages of development. This API is very powerful so we want to make careful decisions to provide a clean interface focused on enabling the most commonly asked for use cases

@martinmeinke
Copy link

martinmeinke commented Oct 5, 2021

@Kaniee No worries always wiling to answer any questions. No plans to support customizable icons at this point in time. As for isPinned or isSaved / isDirty if you have a viable use case I would be happy to explore those but to avoid bloat we're trying to go with the minimal set of properties

I'd also be interested in getting the isDirty property of the document that is potentially displayed in the tab.
Regarding a potential use-case: My extension automatically closes tabs that have not been accessed in some time - but I wouldn't want to close unsaved work :)

Generally speaking I am very happy with the proposed Tab api thoug :)

@lramos15
Copy link
Member Author

lramos15 commented Oct 6, 2021

I'd also be interested in getting the isDirty property of the document that is potentially displayed in the tab.
Regarding a potential use-case: My extension automatically closes tabs that have not been accessed in some time - but I wouldn't want to close unsaved work :)

Interesting use case. Close currently prompts the user if they'd like to save their work so your use case would still work currently, but I understand not wanting to disrupt the user and have a prompt randomly appear

@lramos15 lramos15 modified the milestones: October 2021, November 2021 Oct 13, 2021
@lramos15 lramos15 added workbench-tabs VS Code editor tab issues and removed workbench-editors Managing of editor widgets in workbench window labels Oct 13, 2021
@riccardoferretti
Copy link

I am wondering whether this API would actually be enough to support the case from #136162 which feels like a fairly common/userful use case?

In my specific case, I would like to open files in a specific editor (and/or column), based on some properties of the file (whether extension, or metadata I have associated to it). I am not sure this can be achieved with the currently proposed API, am I missing something?

@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
@lramos15 lramos15 modified the milestones: February 2022, March 2022 Feb 18, 2022
@tamuratak
Copy link
Contributor

The type of input is resolved to unknown, not to a union type, which makes it difficult to get helps from intellisense and others.

readonly input: TextTabInput | TextDiffTabInput | CustomEditorTabInput | NotebookEditorTabInput | NotebookDiffEditorTabInput | unknown;

inputtype

@jrieken
Copy link
Member

jrieken commented Mar 21, 2022

The type of input is resolved to unknown, not to a union type, which makes it difficult to get helps from intellisense and others.

That's unfortunate but looks like TypeScript issue to me. We need the unknown type here because we want to signal that this list of types isn't finite and can be extended with not yet known future types

@lramos15 lramos15 mentioned this issue Mar 21, 2022
3 tasks
@lramos15 lramos15 modified the milestones: March 2022, April 2022 Mar 21, 2022
@tamuratak
Copy link
Contributor

Thank you for your explanation. I see that, with the type unknown, you can guarantee the backward compatibility when you add a new type to the list.

@lramos15
Copy link
Member Author

\closedWith aa69f3d

@lramos15 lramos15 added the verification-needed Verification of issue is requested label Apr 21, 2022
@bpasero
Copy link
Member

bpasero commented Apr 21, 2022

🎸

@lramos15
Copy link
Member Author

To verify:
Please just look over the vscode.d.ts file and ensure starting at window.tabGroups it has the expected types

@jrieken
Copy link
Member

jrieken commented Apr 21, 2022

👯‍♂️

@joyceerhl joyceerhl added the verified Verification succeeded label Apr 27, 2022
@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
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders verification-needed Verification of issue is requested verified Verification succeeded workbench-tabs VS Code editor tab issues
Projects
None yet
Development

No branches or pull requests

12 participants