diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 7a74b77fb33..59c2ac37328 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -5,7 +5,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import { CancellationToken, Command, Disposable, Event, EventEmitter, Memento, OutputChannel, ProgressLocation, ProgressOptions, scm, SourceControl, SourceControlInputBox, SourceControlInputBoxValidation, SourceControlInputBoxValidationType, SourceControlResourceDecorations, SourceControlResourceGroup, SourceControlResourceState, ThemeColor, Uri, window, workspace, WorkspaceEdit, FileDecoration, commands, Tab, TextDiffTabInput, NotebookDiffEditorTabInput } from 'vscode'; +import { CancellationToken, Command, Disposable, Event, EventEmitter, Memento, OutputChannel, ProgressLocation, ProgressOptions, scm, SourceControl, SourceControlInputBox, SourceControlInputBoxValidation, SourceControlInputBoxValidationType, SourceControlResourceDecorations, SourceControlResourceGroup, SourceControlResourceState, ThemeColor, Uri, window, workspace, WorkspaceEdit, FileDecoration, commands, Tab, TabKindTextDiff, TabKindNotebookDiff } from 'vscode'; import TelemetryReporter from '@vscode/extension-telemetry'; import * as nls from 'vscode-nls'; import { Branch, Change, ForcePushMode, GitErrorCodes, LogOptions, Ref, RefType, Remote, Status, CommitOptions, BranchQuery, FetchOptions } from './api/git'; @@ -1273,13 +1273,13 @@ export class Repository implements Disposable { const diffEditorTabsToClose: Tab[] = []; for (const tab of window.tabGroups.groups.map(g => g.tabs).flat()) { - const { input } = tab; - if (input instanceof TextDiffTabInput || input instanceof NotebookDiffEditorTabInput) { - if (input.modified.scheme === 'git' && indexResources.some(r => pathEquals(r, input.modified.fsPath))) { + const { kind } = tab; + if (kind instanceof TabKindTextDiff || kind instanceof TabKindNotebookDiff) { + if (kind.modified.scheme === 'git' && indexResources.some(r => pathEquals(r, kind.modified.fsPath))) { // Index diffEditorTabsToClose.push(tab); } - if (input.modified.scheme === 'file' && input.original.scheme === 'git' && workingTreeResources.some(r => pathEquals(r, input.modified.fsPath))) { + if (kind.modified.scheme === 'file' && kind.original.scheme === 'git' && workingTreeResources.some(r => pathEquals(r, kind.modified.fsPath))) { // Working Tree diffEditorTabsToClose.push(tab); } diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts index e2f5619e063..dc839863d67 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts @@ -112,15 +112,15 @@ suite('vscode API - commands', () => { await commands.executeCommand('vscode.open', uri); assert.strictEqual(window.activeTextEditor?.viewColumn, ViewColumn.One); - assert.strictEqual(window.tabGroups.groups[0].activeTab?.parentGroup.viewColumn, ViewColumn.One); + assert.strictEqual(window.tabGroups.groups[0].activeTab?.group.viewColumn, ViewColumn.One); await commands.executeCommand('vscode.open', uri, ViewColumn.Two); assert.strictEqual(window.activeTextEditor?.viewColumn, ViewColumn.Two); - assert.strictEqual(window.tabGroups.groups[1].activeTab?.parentGroup.viewColumn, ViewColumn.Two); + assert.strictEqual(window.tabGroups.groups[1].activeTab?.group.viewColumn, ViewColumn.Two); await commands.executeCommand('vscode.open', uri, ViewColumn.One); assert.strictEqual(window.activeTextEditor?.viewColumn, ViewColumn.One); - assert.strictEqual(window.tabGroups.groups[0].activeTab?.parentGroup.viewColumn, ViewColumn.One); + assert.strictEqual(window.tabGroups.groups[0].activeTab?.group.viewColumn, ViewColumn.One); let e1: Error | undefined = undefined; try { diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts index e58f295a475..2d7bad45d42 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; import { join } from 'path'; -import { CancellationTokenSource, commands, MarkdownString, NotebookEditorTabInput, Position, QuickPickItem, Selection, StatusBarAlignment, TextDiffTabInput, TextEditor, TextEditorSelectionChangeKind, TextEditorViewColumnChangeEvent, TextTabInput, Uri, ViewColumn, window, workspace } from 'vscode'; +import { CancellationTokenSource, commands, MarkdownString, TabKindNotebook, Position, QuickPickItem, Selection, StatusBarAlignment, TabKindTextDiff, TextEditor, TextEditorSelectionChangeKind, TextEditorViewColumnChangeEvent, TabKindText, Uri, ViewColumn, window, workspace } from 'vscode'; import { assertNoRpc, closeAllEditors, createRandomFile, pathEquals } from '../utils'; @@ -414,23 +414,23 @@ suite('vscode API - window', () => { const commandFile = await createRandomFile(); await commands.executeCommand('vscode.open', commandFile, ViewColumn.Three); // Ensure active tab is correct after calling vscode.opn - assert.strictEqual(getActiveTab()?.parentGroup.viewColumn, ViewColumn.Three); + assert.strictEqual(getActiveTab()?.group.viewColumn, ViewColumn.Three); const leftDiff = await createRandomFile(); const rightDiff = await createRandomFile(); await commands.executeCommand('vscode.diff', leftDiff, rightDiff, 'Diff', { viewColumn: ViewColumn.Four, preview: false }); - assert.strictEqual(getActiveTab()?.parentGroup.viewColumn, ViewColumn.Four); + assert.strictEqual(getActiveTab()?.group.viewColumn, ViewColumn.Four); const tabs = window.tabGroups.groups.map(g => g.tabs).flat(1); assert.strictEqual(tabs.length, 5); - assert.ok(tabs[0].input instanceof TextTabInput); - assert.strictEqual(tabs[0].input.uri.toString(), docA.uri.toString()); - assert.ok(tabs[1].input instanceof TextTabInput); - assert.strictEqual(tabs[1].input.uri.toString(), docB.uri.toString()); - assert.ok(tabs[2].input instanceof TextTabInput); - assert.strictEqual(tabs[2].input.uri.toString(), docC.uri.toString()); - assert.ok(tabs[3].input instanceof TextTabInput); - assert.strictEqual(tabs[3].input.uri.toString(), commandFile.toString()); + assert.ok(tabs[0].kind instanceof TabKindText); + assert.strictEqual(tabs[0].kind.uri.toString(), docA.uri.toString()); + assert.ok(tabs[1].kind instanceof TabKindText); + assert.strictEqual(tabs[1].kind.uri.toString(), docB.uri.toString()); + assert.ok(tabs[2].kind instanceof TabKindText); + assert.strictEqual(tabs[2].kind.uri.toString(), docC.uri.toString()); + assert.ok(tabs[3].kind instanceof TabKindText); + assert.strictEqual(tabs[3].kind.uri.toString(), commandFile.toString()); }); test('Tabs - Ensure tabs getter is correct', async function () { @@ -459,23 +459,23 @@ suite('vscode API - window', () => { assert.strictEqual(tabs.length, 5); // All resources should match the text documents as they're the only tabs currently open - assert.ok(tabs[0].input instanceof TextTabInput); - assert.strictEqual(tabs[0].input.uri.toString(), docA.uri.toString()); - assert.ok(tabs[1].input instanceof NotebookEditorTabInput); - assert.strictEqual(tabs[1].input.uri.toString(), notebookDoc.uri.toString()); - assert.ok(tabs[2].input instanceof TextTabInput); - assert.strictEqual(tabs[2].input.uri.toString(), docB.uri.toString()); - assert.ok(tabs[3].input instanceof TextTabInput); - assert.strictEqual(tabs[3].input.uri.toString(), docC.uri.toString()); + assert.ok(tabs[0].kind instanceof TabKindText); + assert.strictEqual(tabs[0].kind.uri.toString(), docA.uri.toString()); + assert.ok(tabs[1].kind instanceof TabKindNotebook); + assert.strictEqual(tabs[1].kind.uri.toString(), notebookDoc.uri.toString()); + assert.ok(tabs[2].kind instanceof TabKindText); + assert.strictEqual(tabs[2].kind.uri.toString(), docB.uri.toString()); + assert.ok(tabs[3].kind instanceof TabKindText); + assert.strictEqual(tabs[3].kind.uri.toString(), docC.uri.toString()); // Diff editor and side by side editor report the right side as the resource - assert.ok(tabs[4].input instanceof TextDiffTabInput); - assert.strictEqual(tabs[4].input.modified.toString(), rightDiff.toString()); + assert.ok(tabs[4].kind instanceof TabKindTextDiff); + assert.strictEqual(tabs[4].kind.modified.toString(), rightDiff.toString()); - assert.strictEqual(tabs[0].parentGroup.viewColumn, ViewColumn.One); - assert.strictEqual(tabs[1].parentGroup.viewColumn, ViewColumn.One); - assert.strictEqual(tabs[2].parentGroup.viewColumn, ViewColumn.Two); - assert.strictEqual(tabs[3].parentGroup.viewColumn, ViewColumn.Three); - assert.strictEqual(tabs[4].parentGroup.viewColumn, ViewColumn.Three); + assert.strictEqual(tabs[0].group.viewColumn, ViewColumn.One); + assert.strictEqual(tabs[1].group.viewColumn, ViewColumn.One); + assert.strictEqual(tabs[2].group.viewColumn, ViewColumn.Two); + assert.strictEqual(tabs[3].group.viewColumn, ViewColumn.Three); + assert.strictEqual(tabs[4].group.viewColumn, ViewColumn.Three); }); test('Tabs - ensure active tab is correct', async () => { @@ -495,20 +495,20 @@ suite('vscode API - window', () => { await window.showTextDocument(docA, { viewColumn: ViewColumn.One, preview: false }); let activeTab = getActiveTabInActiveGroup(); assert.ok(activeTab); - assert.ok(activeTab.input instanceof TextTabInput); - assert.strictEqual(activeTab.input.uri.toString(), docA.uri.toString()); + assert.ok(activeTab.kind instanceof TabKindText); + assert.strictEqual(activeTab.kind.uri.toString(), docA.uri.toString()); await window.showTextDocument(docB, { viewColumn: ViewColumn.Two, preview: false }); activeTab = getActiveTabInActiveGroup(); assert.ok(activeTab); - assert.ok(activeTab.input instanceof TextTabInput); - assert.strictEqual(activeTab.input.uri.toString(), docB.uri.toString()); + assert.ok(activeTab.kind instanceof TabKindText); + assert.strictEqual(activeTab.kind.uri.toString(), docB.uri.toString()); await window.showTextDocument(docC, { viewColumn: ViewColumn.Three, preview: false }); activeTab = getActiveTabInActiveGroup(); assert.ok(activeTab); - assert.ok(activeTab.input instanceof TextTabInput); - assert.strictEqual(activeTab.input.uri.toString(), docC.uri.toString()); + assert.ok(activeTab.kind instanceof TabKindText); + assert.strictEqual(activeTab.kind.uri.toString(), docC.uri.toString()); await commands.executeCommand('workbench.action.closeActiveEditor'); await commands.executeCommand('workbench.action.closeActiveEditor'); diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 76ee48e81f1..fc2bcb95e81 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1333,11 +1333,11 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I LanguageStatusSeverity: extHostTypes.LanguageStatusSeverity, QuickPickItemKind: extHostTypes.QuickPickItemKind, InputBoxValidationSeverity: extHostTypes.InputBoxValidationSeverity, - TextTabInput: extHostTypes.TextTabInput, - TextDiffTabInput: extHostTypes.TextDiffTabInput, - CustomEditorTabInput: extHostTypes.CustomEditorTabInput, - NotebookEditorTabInput: extHostTypes.NotebookEditorTabInput, - NotebookDiffEditorTabInput: extHostTypes.NotebookDiffEditorTabInput + TabKindText: extHostTypes.TextTabInput, + TabKindTextDiff: extHostTypes.TextDiffTabInput, + TabKindCustom: extHostTypes.CustomEditorTabInput, + TabKindNotebook: extHostTypes.NotebookEditorTabInput, + TabKindNotebookDiff: extHostTypes.NotebookDiffEditorTabInput }; }; } diff --git a/src/vs/workbench/api/common/extHostDebugService.ts b/src/vs/workbench/api/common/extHostDebugService.ts index 2b1854dbe8a..228920010ae 100644 --- a/src/vs/workbench/api/common/extHostDebugService.ts +++ b/src/vs/workbench/api/common/extHostDebugService.ts @@ -956,10 +956,10 @@ export class ExtHostVariableResolverService extends AbstractVariableResolverServ const activeTab = editorTabs.tabGroups.groups.find(group => group.isActive)?.activeTab; if (activeTab !== undefined) { // Resolve a resource from the tab - if (activeTab.input instanceof TextDiffTabInput || activeTab.input instanceof NotebookDiffEditorTabInput) { - return activeTab.input.modified; - } else if (activeTab.input instanceof TextTabInput || activeTab.input instanceof NotebookEditorTabInput || activeTab.input instanceof CustomEditorTabInput) { - return activeTab.input.uri; + if (activeTab.kind instanceof TextDiffTabInput || activeTab.kind instanceof NotebookDiffEditorTabInput) { + return activeTab.kind.modified; + } else if (activeTab.kind instanceof TextTabInput || activeTab.kind instanceof NotebookEditorTabInput || activeTab.kind instanceof CustomEditorTabInput) { + return activeTab.kind.uri; } } } diff --git a/src/vs/workbench/api/common/extHostEditorTabs.ts b/src/vs/workbench/api/common/extHostEditorTabs.ts index f94c1479fac..40ce153fc78 100644 --- a/src/vs/workbench/api/common/extHostEditorTabs.ts +++ b/src/vs/workbench/api/common/extHostEditorTabs.ts @@ -46,7 +46,7 @@ class ExtHostEditorTab { get label() { return that._dto.label; }, - get input() { + get kind() { return that._input; }, get isDirty() { @@ -58,7 +58,7 @@ class ExtHostEditorTab { get isPreview() { return that._dto.isPreview; }, - get parentGroup() { + get group() { return that._parentGroup.apiObject; } }; diff --git a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts index 3391405de52..69b515e77e4 100644 --- a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts +++ b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts @@ -238,10 +238,10 @@ suite('ExtHostEditorTabs', function () { let all = extHostEditorTabs.tabGroups.groups.map(group => group.tabs).flat(); assert.strictEqual(all.length, 1); const apiTab1 = all[0]; - assert.ok(apiTab1.input instanceof TextTabInput); + assert.ok(apiTab1.kind instanceof TextTabInput); assert.strictEqual(tabDto.input.kind, TabInputKind.TextInput); const dtoResource = (tabDto.input as TextInputDto).uri; - assert.strictEqual(apiTab1.input.uri.toString(), URI.revive(dtoResource).toString()); + assert.strictEqual(apiTab1.kind.uri.toString(), URI.revive(dtoResource).toString()); assert.strictEqual(apiTab1.isDirty, true); @@ -254,8 +254,8 @@ suite('ExtHostEditorTabs', function () { all = extHostEditorTabs.tabGroups.groups.map(group => group.tabs).flat(); assert.strictEqual(all.length, 1); const apiTab2 = all[0]; - assert.ok(apiTab1.input instanceof TextTabInput); - assert.strictEqual(apiTab1.input.uri.toString(), URI.revive(dtoResource).toString()); + assert.ok(apiTab1.kind instanceof TextTabInput); + assert.strictEqual(apiTab1.kind.uri.toString(), URI.revive(dtoResource).toString()); assert.strictEqual(apiTab2.isDirty, false); assert.strictEqual(apiTab1 === apiTab2, true); @@ -301,19 +301,19 @@ suite('ExtHostEditorTabs', function () { assert.strictEqual(all.length, 2); const activeTab1 = extHostEditorTabs.tabGroups.activeTabGroup?.activeTab; - assert.ok(activeTab1?.input instanceof TextTabInput); + assert.ok(activeTab1?.kind instanceof TextTabInput); assert.strictEqual(tabDtoAAA.input.kind, TabInputKind.TextInput); const dtoAAAResource = (tabDtoAAA.input as TextInputDto).uri; - assert.strictEqual(activeTab1?.input?.uri.toString(), URI.revive(dtoAAAResource)?.toString()); + assert.strictEqual(activeTab1?.kind?.uri.toString(), URI.revive(dtoAAAResource)?.toString()); assert.strictEqual(activeTab1?.isActive, true); extHostEditorTabs.$acceptTabUpdate(12, { ...tabDtoBBB, isActive: true }); /// BBB is now active const activeTab2 = extHostEditorTabs.tabGroups.activeTabGroup?.activeTab; - assert.ok(activeTab2?.input instanceof TextTabInput); + assert.ok(activeTab2?.kind instanceof TextTabInput); assert.strictEqual(tabDtoBBB.input.kind, TabInputKind.TextInput); const dtoBBBResource = (tabDtoBBB.input as TextInputDto).uri; - assert.strictEqual(activeTab2?.input?.uri.toString(), URI.revive(dtoBBBResource)?.toString()); + assert.strictEqual(activeTab2?.kind?.uri.toString(), URI.revive(dtoBBBResource)?.toString()); assert.strictEqual(activeTab2?.isActive, true); assert.strictEqual(activeTab1?.isActive, false); }); diff --git a/src/vscode-dts/vscode.proposed.tabs.d.ts b/src/vscode-dts/vscode.proposed.tabs.d.ts index 510d9c9fcc7..13f9651291c 100644 --- a/src/vscode-dts/vscode.proposed.tabs.d.ts +++ b/src/vscode-dts/vscode.proposed.tabs.d.ts @@ -7,33 +7,30 @@ declare module 'vscode' { // https://github.com/Microsoft/vscode/issues/15178 - export class TextTabInput { + export class TabKindText { readonly uri: Uri; constructor(uri: Uri); } - export class TextDiffTabInput { + export class TabKindTextDiff { readonly original: Uri; readonly modified: Uri; constructor(original: Uri, modified: Uri); } - // TODO@API remove `Editor` - export class CustomEditorTabInput { + export class TabKindCustom { readonly uri: Uri; readonly viewType: string; constructor(uri: Uri, viewType: string); } - // TODO@API remove `Editor` - export class NotebookEditorTabInput { + export class TabKindNotebook { readonly uri: Uri; readonly notebookType: string; constructor(uri: Uri, notebookType: string); } - // TODO@API remove `Editor` - export class NotebookDiffEditorTabInput { + export class TabKindNotebookDiff { readonly original: Uri; readonly modified: Uri; readonly notebookType: string; @@ -52,13 +49,13 @@ declare module 'vscode' { /** * The group which the tab belongs to */ - // TODO@API names?: `tabGroup`, `group` - readonly parentGroup: TabGroup; + readonly group: TabGroup; - // TODO@API NAME: xyzOptions, xyzType - // TabTypeText, TabTypeTextDiff, TabTypeNotebook, TabTypeNotebookDiff, TabTypeCustom - // TabKindText, TabKindTextDiff, TabKindNotebook, TabKindNotebookDiff, TabKindCustom - readonly input: TextTabInput | TextDiffTabInput | CustomEditorTabInput | NotebookEditorTabInput | NotebookDiffEditorTabInput | unknown; + /** + * Defines the structure of the tab i.e. text, notebook, custom, etc. + * Resource and other useful properties are defined on the tab kind. + */ + readonly kind: TabKindText | TabKindTextDiff | TabKindCustom | TabKindNotebook | TabKindNotebookDiff | unknown; /** * Whether or not the tab is currently active