Path: blob/main/src/vs/workbench/services/outline/browser/outlineService.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CancellationToken } from '../../../../base/common/cancellation.js';6import { IDisposable, toDisposable } from '../../../../base/common/lifecycle.js';7import { LinkedList } from '../../../../base/common/linkedList.js';8import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';9import { IEditorPane } from '../../../common/editor.js';10import { IOutline, IOutlineCreator, IOutlineService, OutlineTarget } from './outline.js';11import { Event, Emitter } from '../../../../base/common/event.js';1213class OutlineService implements IOutlineService {1415declare _serviceBrand: undefined;1617private readonly _factories = new LinkedList<IOutlineCreator<any, any>>();1819private readonly _onDidChange = new Emitter<void>();20readonly onDidChange: Event<void> = this._onDidChange.event;2122canCreateOutline(pane: IEditorPane): boolean {23for (const factory of this._factories) {24if (factory.matches(pane)) {25return true;26}27}28return false;29}3031async createOutline(pane: IEditorPane, target: OutlineTarget, token: CancellationToken): Promise<IOutline<any> | undefined> {32for (const factory of this._factories) {33if (factory.matches(pane)) {34return await factory.createOutline(pane, target, token);35}36}37return undefined;38}3940registerOutlineCreator(creator: IOutlineCreator<any, any>): IDisposable {41const rm = this._factories.push(creator);42this._onDidChange.fire();43return toDisposable(() => {44rm();45this._onDidChange.fire();46});47}48}495051registerSingleton(IOutlineService, OutlineService, InstantiationType.Delayed);525354