Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/outline/browser/outlineService.ts
3296 views
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
import { CancellationToken } from '../../../../base/common/cancellation.js';
7
import { IDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
8
import { LinkedList } from '../../../../base/common/linkedList.js';
9
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
10
import { IEditorPane } from '../../../common/editor.js';
11
import { IOutline, IOutlineCreator, IOutlineService, OutlineTarget } from './outline.js';
12
import { Event, Emitter } from '../../../../base/common/event.js';
13
14
class OutlineService implements IOutlineService {
15
16
declare _serviceBrand: undefined;
17
18
private readonly _factories = new LinkedList<IOutlineCreator<any, any>>();
19
20
private readonly _onDidChange = new Emitter<void>();
21
readonly onDidChange: Event<void> = this._onDidChange.event;
22
23
canCreateOutline(pane: IEditorPane): boolean {
24
for (const factory of this._factories) {
25
if (factory.matches(pane)) {
26
return true;
27
}
28
}
29
return false;
30
}
31
32
async createOutline(pane: IEditorPane, target: OutlineTarget, token: CancellationToken): Promise<IOutline<any> | undefined> {
33
for (const factory of this._factories) {
34
if (factory.matches(pane)) {
35
return await factory.createOutline(pane, target, token);
36
}
37
}
38
return undefined;
39
}
40
41
registerOutlineCreator(creator: IOutlineCreator<any, any>): IDisposable {
42
const rm = this._factories.push(creator);
43
this._onDidChange.fire();
44
return toDisposable(() => {
45
rm();
46
this._onDidChange.fire();
47
});
48
}
49
}
50
51
52
registerSingleton(IOutlineService, OutlineService, InstantiationType.Delayed);
53
54