Skip to content

Commit 40df705

Browse files
committed
add API proposal for vscode.TabInputTextMerge
1 parent f6332bd commit 40df705

File tree

8 files changed

+89
-5
lines changed

8 files changed

+89
-5
lines changed

src/vs/workbench/api/browser/mainThreadEditorTabs.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEdit
2323
import { isEqual } from 'vs/base/common/resources';
2424
import { isGroupEditorMoveEvent } from 'vs/workbench/common/editor/editorGroupModel';
2525
import { InteractiveEditorInput } from 'vs/workbench/contrib/interactive/browser/interactiveEditorInput';
26+
import { MergeEditorInput } from 'vs/workbench/contrib/mergeEditor/browser/mergeEditorInput';
2627

2728
interface TabInfo {
2829
tab: IEditorTabDto;
@@ -91,6 +92,16 @@ export class MainThreadEditorTabs implements MainThreadEditorTabsShape {
9192

9293
private _editorInputToDto(editor: EditorInput): AnyInputDto {
9394

95+
if (editor instanceof MergeEditorInput) {
96+
return {
97+
kind: TabInputKind.TextMergeInput,
98+
base: editor.base,
99+
input1: editor.input1.uri,
100+
input2: editor.input2.uri,
101+
result: editor.resource
102+
};
103+
}
104+
94105
if (editor instanceof AbstractTextResourceEditorInput) {
95106
return {
96107
kind: TabInputKind.TextInput,

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
13421342
InputBoxValidationSeverity: extHostTypes.InputBoxValidationSeverity,
13431343
TabInputText: extHostTypes.TextTabInput,
13441344
TabInputTextDiff: extHostTypes.TextDiffTabInput,
1345+
TabInputTextMerge: extHostTypes.TextMergeTabInput,
13451346
TabInputCustom: extHostTypes.CustomEditorTabInput,
13461347
TabInputNotebook: extHostTypes.NotebookEditorTabInput,
13471348
TabInputNotebookDiff: extHostTypes.NotebookDiffEditorTabInput,

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ export const enum TabInputKind {
620620
UnknownInput,
621621
TextInput,
622622
TextDiffInput,
623+
TextMergeInput,
623624
NotebookInput,
624625
NotebookDiffInput,
625626
CustomEditorInput,
@@ -650,6 +651,14 @@ export interface TextDiffInputDto {
650651
modified: UriComponents;
651652
}
652653

654+
export interface TextMergeInputDto {
655+
kind: TabInputKind.TextMergeInput;
656+
base: UriComponents;
657+
input1: UriComponents;
658+
input2: UriComponents;
659+
result: UriComponents;
660+
}
661+
653662
export interface NotebookInputDto {
654663
kind: TabInputKind.NotebookInput;
655664
notebookType: string;
@@ -684,7 +693,7 @@ export interface TabInputDto {
684693
kind: TabInputKind.TerminalEditorInput;
685694
}
686695

687-
export type AnyInputDto = UnknownInputDto | TextInputDto | TextDiffInputDto | NotebookInputDto | NotebookDiffInputDto | CustomInputDto | WebviewInputDto | InteractiveEditorInputDto | TabInputDto;
696+
export type AnyInputDto = UnknownInputDto | TextInputDto | TextDiffInputDto | TextMergeInputDto | NotebookInputDto | NotebookDiffInputDto | CustomInputDto | WebviewInputDto | InteractiveEditorInputDto | TabInputDto;
688697

689698
export interface MainThreadEditorTabsShape extends IDisposable {
690699
// manage tabs: move, close, rearrange etc

src/vs/workbench/api/common/extHostEditorTabs.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IEditorTabDto, IEditorTabGroupDto, IExtHostEditorTabsShape, MainContext
99
import { URI } from 'vs/base/common/uri';
1010
import { Emitter } from 'vs/base/common/event';
1111
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
12-
import { CustomEditorTabInput, InteractiveWindowInput, NotebookDiffEditorTabInput, NotebookEditorTabInput, TerminalEditorTabInput, TextDiffTabInput, TextTabInput, WebviewEditorTabInput } from 'vs/workbench/api/common/extHostTypes';
12+
import { CustomEditorTabInput, InteractiveWindowInput, NotebookDiffEditorTabInput, NotebookEditorTabInput, TerminalEditorTabInput, TextDiffTabInput, TextMergeTabInput, TextTabInput, WebviewEditorTabInput } from 'vs/workbench/api/common/extHostTypes';
1313
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
1414
import { assertIsDefined } from 'vs/base/common/types';
1515
import { diffSets } from 'vs/base/common/collections';
@@ -84,6 +84,8 @@ class ExtHostEditorTab {
8484
return new TextTabInput(URI.revive(this._dto.input.uri));
8585
case TabInputKind.TextDiffInput:
8686
return new TextDiffTabInput(URI.revive(this._dto.input.original), URI.revive(this._dto.input.modified));
87+
case TabInputKind.TextMergeInput:
88+
return new TextMergeTabInput(URI.revive(this._dto.input.base), URI.revive(this._dto.input.input1), URI.revive(this._dto.input.input2), URI.revive(this._dto.input.result));
8789
case TabInputKind.CustomEditorInput:
8890
return new CustomEditorTabInput(URI.revive(this._dto.input.uri), this._dto.input.viewType);
8991
case TabInputKind.WebviewEditorInput:
@@ -110,7 +112,7 @@ class ExtHostEditorTabGroup {
110112
private _activeTabId: string = '';
111113
private _activeGroupIdGetter: () => number | undefined;
112114

113-
constructor(dto: IEditorTabGroupDto, proxy: MainThreadEditorTabsShape, activeGroupIdGetter: () => number | undefined) {
115+
constructor(dto: IEditorTabGroupDto, activeGroupIdGetter: () => number | undefined) {
114116
this._dto = dto;
115117
this._activeGroupIdGetter = activeGroupIdGetter;
116118
// Construct all tabs from the given dto
@@ -284,7 +286,7 @@ export class ExtHostEditorTabs implements IExtHostEditorTabs {
284286

285287

286288
this._extHostTabGroups = tabGroups.map(tabGroup => {
287-
const group = new ExtHostEditorTabGroup(tabGroup, this._proxy, () => this._activeGroupId);
289+
const group = new ExtHostEditorTabGroup(tabGroup, () => this._activeGroupId);
288290
if (diff.added.includes(group.groupId)) {
289291
opened.push(group.apiObject);
290292
} else {

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,10 @@ export class TextDiffTabInput {
37093709
constructor(readonly original: URI, readonly modified: URI) { }
37103710
}
37113711

3712+
export class TextMergeTabInput {
3713+
constructor(readonly base: URI, readonly input1: URI, readonly input2: URI, readonly result: URI) { }
3714+
}
3715+
37123716
export class CustomEditorTabInput {
37133717
constructor(readonly uri: URI, readonly viewType: string) { }
37143718
}

src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { mock } from 'vs/base/test/common/mock';
1010
import { IEditorTabDto, IEditorTabGroupDto, MainThreadEditorTabsShape, TabInputKind, TabModelOperationKind, TextInputDto } from 'vs/workbench/api/common/extHost.protocol';
1111
import { ExtHostEditorTabs } from 'vs/workbench/api/common/extHostEditorTabs';
1212
import { SingleProxyRPCProtocol } from 'vs/workbench/api/test/common/testRPCProtocol';
13-
import { TextTabInput } from 'vs/workbench/api/common/extHostTypes';
13+
import { TextMergeTabInput, TextTabInput } from 'vs/workbench/api/common/extHostTypes';
1414

1515
suite('ExtHostEditorTabs', function () {
1616

@@ -209,6 +209,37 @@ suite('ExtHostEditorTabs', function () {
209209
assert.strictEqual(extHostEditorTabs.tabGroups.activeTabGroup, first);
210210
});
211211

212+
test('TextMergeTabInput surfaces in the UI', function () {
213+
214+
const extHostEditorTabs = new ExtHostEditorTabs(
215+
SingleProxyRPCProtocol(new class extends mock<MainThreadEditorTabsShape>() {
216+
// override/implement $moveTab or $closeTab
217+
})
218+
);
219+
220+
const tab: IEditorTabDto = createTabDto({
221+
input: {
222+
kind: TabInputKind.TextMergeInput,
223+
base: URI.from({ scheme: 'test', path: 'base' }),
224+
input1: URI.from({ scheme: 'test', path: 'input1' }),
225+
input2: URI.from({ scheme: 'test', path: 'input2' }),
226+
result: URI.from({ scheme: 'test', path: 'result' }),
227+
}
228+
});
229+
230+
extHostEditorTabs.$acceptEditorTabModel([{
231+
isActive: true,
232+
viewColumn: 0,
233+
groupId: 12,
234+
tabs: [tab]
235+
}]);
236+
assert.strictEqual(extHostEditorTabs.tabGroups.all.length, 1);
237+
const [first] = extHostEditorTabs.tabGroups.all;
238+
assert.ok(first.activeTab);
239+
assert.strictEqual(first.tabs.indexOf(first.activeTab), 0);
240+
assert.ok(first.activeTab.input instanceof TextMergeTabInput);
241+
});
242+
212243
test('Ensure reference stability', function () {
213244

214245
const extHostEditorTabs = new ExtHostEditorTabs(

src/vs/workbench/services/extensions/common/extensionsApiProposals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const allApiProposals = Object.freeze({
5252
scmSelectedProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts',
5353
scmValidation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmValidation.d.ts',
5454
snippetWorkspaceEdit: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.snippetWorkspaceEdit.d.ts',
55+
tabInputTextMerge: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts',
5556
taskPresentationGroup: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.taskPresentationGroup.d.ts',
5657
telemetry: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.telemetry.d.ts',
5758
terminalDataWriteEvent: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalDataWriteEvent.d.ts',
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
// https://github.com/microsoft/vscode/issues/153213
7+
8+
declare module 'vscode' {
9+
10+
export class TabInputTextMerge {
11+
12+
readonly base: Uri;
13+
readonly input1: Uri;
14+
readonly input2: Uri;
15+
readonly result: Uri;
16+
17+
constructor(base: Uri, input1: Uri, input2: Uri, result: Uri);
18+
}
19+
20+
export interface Tab {
21+
22+
readonly input: TabInputText | TabInputTextDiff | TabInputTextMerge | TabInputCustom | TabInputWebview | TabInputNotebook | TabInputNotebookDiff | TabInputTerminal | unknown;
23+
24+
}
25+
}

0 commit comments

Comments
 (0)