Skip to content

Commit 8bada27

Browse files
authored
Merge pull request microsoft#155148 from microsoft/joh/double-barnacle
joh/double barnacle
2 parents f127c6c + 0f0101b commit 8bada27

File tree

11 files changed

+105
-15
lines changed

11 files changed

+105
-15
lines changed

extensions/git/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"scmActionButton",
1717
"scmSelectedProvider",
1818
"scmValidation",
19+
"tabInputTextMerge",
1920
"timeline"
2021
],
2122
"categories": [

extensions/git/src/commands.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as os from 'os';
77
import * as path from 'path';
8-
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText } from 'vscode';
8+
import { Command, commands, Disposable, LineChange, MessageOptions, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder, TimelineItem, env, Selection, TextDocumentContentProvider, InputBoxValidationSeverity, TabInputText, TabInputTextMerge } from 'vscode';
99
import TelemetryReporter from '@vscode/extension-telemetry';
1010
import * as nls from 'vscode-nls';
1111
import { uniqueNamesGenerator, adjectives, animals, colors, NumberDictionary } from '@joaomoreno/unique-names-generator';
@@ -1103,21 +1103,26 @@ export class CommandCenter {
11031103
return;
11041104
}
11051105

1106+
const { activeTab } = window.tabGroups.activeTabGroup;
1107+
if (!activeTab) {
1108+
return;
1109+
}
1110+
1111+
// make sure to save the merged document
11061112
const doc = workspace.textDocuments.find(doc => doc.uri.toString() === uri.toString());
11071113
if (!doc) {
11081114
console.log(`FAILED to accept merge because uri ${uri.toString()} doesn't match a document`);
11091115
return;
11101116
}
1117+
if (doc.isDirty) {
1118+
await doc.save();
1119+
}
11111120

1112-
await doc.save();
1113-
1114-
// TODO@jrieken there isn't a `TabInputTextMerge` instance yet, till now the merge editor
1115-
// uses the `TabInputText` for the out-resource and we use that to identify and CLOSE the tab
1116-
// see https://github.com/microsoft/vscode/issues/153213
1117-
const { activeTab } = window.tabGroups.activeTabGroup;
1121+
// find the merge editor tabs for the resource in question and close them all
11181122
let didCloseTab = false;
1119-
if (activeTab && activeTab?.input instanceof TabInputText && activeTab.input.uri.toString() === uri.toString()) {
1120-
didCloseTab = await window.tabGroups.close(activeTab, true);
1123+
const mergeEditorTabs = window.tabGroups.all.map(group => group.tabs.filter(tab => tab.input instanceof TabInputTextMerge && tab.input.result.toString() === uri.toString())).flat();
1124+
if (mergeEditorTabs.includes(activeTab)) {
1125+
didCloseTab = await window.tabGroups.close(mergeEditorTabs, true);
11211126
}
11221127

11231128
// Only stage if the merge editor has been successfully closed. That means all conflicts have been

extensions/git/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"../../src/vscode-dts/vscode.proposed.scmActionButton.d.ts",
1515
"../../src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts",
1616
"../../src/vscode-dts/vscode.proposed.scmValidation.d.ts",
17-
"../../src/vscode-dts/vscode.proposed.tabs.d.ts",
17+
"../../src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts",
1818
"../../src/vscode-dts/vscode.proposed.timeline.d.ts",
1919
"../types/lib.textEncoder.d.ts"
2020
]

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
@@ -3797,6 +3797,10 @@ export class TextDiffTabInput {
37973797
constructor(readonly original: URI, readonly modified: URI) { }
37983798
}
37993799

3800+
export class TextMergeTabInput {
3801+
constructor(readonly base: URI, readonly input1: URI, readonly input2: URI, readonly result: URI) { }
3802+
}
3803+
38003804
export class CustomEditorTabInput {
38013805
constructor(readonly uri: URI, readonly viewType: string) { }
38023806
}

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',

0 commit comments

Comments
 (0)