Skip to content

Commit dcf7b7c

Browse files
authored
debt - adopt findEditors in more places (microsoft#250712)
1 parent 998fb69 commit dcf7b7c

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

src/vs/workbench/browser/parts/editor/editorGroupView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
10361036

10371037
findEditors(resource: URI, options?: IFindEditorOptions): EditorInput[] {
10381038
const canonicalResource = this.uriIdentityService.asCanonicalUri(resource);
1039-
return this.getEditors(EditorsOrder.SEQUENTIAL).filter(editor => {
1039+
return this.getEditors(options?.order ?? EditorsOrder.SEQUENTIAL).filter(editor => {
10401040
if (editor.resource && isEqual(editor.resource, canonicalResource)) {
10411041
return true;
10421042
}

src/vs/workbench/common/editor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,11 @@ export interface IFindEditorOptions {
12901290
* as matching, even if the editor is opened in one of the sides.
12911291
*/
12921292
supportSideBySide?: SideBySideEditor.PRIMARY | SideBySideEditor.SECONDARY | SideBySideEditor.ANY;
1293+
1294+
/**
1295+
* The order in which to consider editors for finding.
1296+
*/
1297+
order?: EditorsOrder;
12931298
}
12941299

12951300
export interface IMatchEditorOptions {

src/vs/workbench/contrib/interactive/browser/interactive.contribution.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ export class InteractiveDocumentContribution extends Disposable implements IWork
113113
},
114114
{
115115
createEditorInput: ({ resource }) => {
116-
const editorInput = editorService.getEditors(EditorsOrder.SEQUENTIAL).find(editor => editor.editor instanceof InteractiveEditorInput && editor.editor.inputResource.toString() === resource.toString());
116+
const editorInput = editorService.findEditors({
117+
resource,
118+
editorId: 'interactive',
119+
typeId: InteractiveEditorInput.ID
120+
}, { order: EditorsOrder.SEQUENTIAL }).at(0);
117121
return editorInput!;
118122
}
119123
}

src/vs/workbench/contrib/mcp/browser/mcpCommandsAddConfiguration.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { INotificationService } from '../../../../platform/notification/common/n
2424
import { IQuickInputService, IQuickPickItem, QuickPickInput } from '../../../../platform/quickinput/common/quickInput.js';
2525
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
2626
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
27-
import { EditorsOrder } from '../../../common/editor.js';
2827
import { IJSONEditingService } from '../../../services/configuration/common/jsonEditing.js';
2928
import { ConfiguredInput } from '../../../services/configurationResolver/common/configurationResolver.js';
3029
import { IEditorService } from '../../../services/editor/common/editorService.js';
@@ -489,8 +488,7 @@ export class McpAddConfigurationCommand {
489488
}
490489

491490
const pick = await this._quickInputService.pick(items, { placeHolder, ignoreFocusLost: true });
492-
const getEditors = () => this._editorService.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE)
493-
.filter(e => e.editor.resource?.toString() === resource.toString());
491+
const getEditors = () => this._editorService.findEditors(resource);
494492

495493
switch (pick?.id) {
496494
case 'show':

src/vs/workbench/contrib/notebook/browser/controller/executeActions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { MenuId, MenuRegistry, registerAction2 } from '../../../../../platform/a
1515
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
1616
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
1717
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
18-
import { EditorsOrder } from '../../../../common/editor.js';
1918
import { IDebugService } from '../../../debug/common/debug.js';
2019
import { CTX_INLINE_CHAT_FOCUSED } from '../../../inlineChat/common/inlineChat.js';
2120
import { insertCell } from './cellOperations.js';
@@ -243,8 +242,11 @@ registerAction2(class ExecuteNotebookAction extends NotebookAction {
243242
renderAllMarkdownCells(context);
244243

245244
const editorService = accessor.get(IEditorService);
246-
const editor = editorService.getEditors(EditorsOrder.MOST_RECENTLY_ACTIVE).find(
247-
editor => editor.editor instanceof NotebookEditorInput && editor.editor.viewType === context.notebookEditor.textModel.viewType && editor.editor.resource.toString() === context.notebookEditor.textModel.uri.toString());
245+
const editor = editorService.findEditors({
246+
resource: context.notebookEditor.textModel.uri,
247+
typeId: NotebookEditorInput.ID,
248+
editorId: context.notebookEditor.textModel.viewType
249+
}).at(0);
248250
const editorGroupService = accessor.get(IEditorGroupsService);
249251

250252
if (editor) {

src/vs/workbench/services/editor/browser/editorService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
861861
else {
862862
const result: IEditorIdentifier[] = [];
863863

864-
for (const group of this.editorGroupsContainer.getGroups(GroupsOrder.MOST_RECENTLY_ACTIVE)) {
864+
for (const group of this.editorGroupsContainer.getGroups(options?.order === EditorsOrder.SEQUENTIAL ? GroupsOrder.GRID_APPEARANCE : GroupsOrder.MOST_RECENTLY_ACTIVE)) {
865865
const editors: EditorInput[] = [];
866866

867867
// Resource provided: result is an array

src/vs/workbench/services/editor/common/editorService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export interface IEditorService {
341341
/**
342342
* Save the provided list of editors.
343343
*/
344-
save(editors: IEditorIdentifier | IEditorIdentifier[], options?: ISaveEditorsOptions): Promise<ISaveEditorsResult>;
344+
save(editors: IEditorIdentifier | readonly IEditorIdentifier[], options?: ISaveEditorsOptions): Promise<ISaveEditorsResult>;
345345

346346
/**
347347
* Save all editors.
@@ -353,7 +353,7 @@ export interface IEditorService {
353353
*
354354
* @returns `true` if all editors reverted and `false` otherwise.
355355
*/
356-
revert(editors: IEditorIdentifier | IEditorIdentifier[], options?: IRevertOptions): Promise<boolean>;
356+
revert(editors: IEditorIdentifier | readonly IEditorIdentifier[], options?: IRevertOptions): Promise<boolean>;
357357

358358
/**
359359
* Reverts all editors.

0 commit comments

Comments
 (0)