Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/merge-conflict/src/services.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
import * as vscode from 'vscode';
6
import DocumentTracker from './documentTracker';
7
import CodeLensProvider from './codelensProvider';
8
import CommandHandler from './commandHandler';
9
import ContentProvider from './contentProvider';
10
import Decorator from './mergeDecorator';
11
import * as interfaces from './interfaces';
12
import TelemetryReporter from '@vscode/extension-telemetry';
13
14
const ConfigurationSectionName = 'merge-conflict';
15
16
export default class ServiceWrapper implements vscode.Disposable {
17
18
private services: vscode.Disposable[] = [];
19
private telemetryReporter: TelemetryReporter;
20
21
constructor(private context: vscode.ExtensionContext) {
22
const { aiKey } = context.extension.packageJSON as { aiKey: string };
23
this.telemetryReporter = new TelemetryReporter(aiKey);
24
context.subscriptions.push(this.telemetryReporter);
25
}
26
27
begin() {
28
29
const configuration = this.createExtensionConfiguration();
30
const documentTracker = new DocumentTracker(this.telemetryReporter);
31
32
this.services.push(
33
documentTracker,
34
new CommandHandler(documentTracker),
35
new CodeLensProvider(documentTracker),
36
new ContentProvider(this.context),
37
new Decorator(this.context, documentTracker),
38
);
39
40
this.services.forEach((service: any) => {
41
if (service.begin && service.begin instanceof Function) {
42
service.begin(configuration);
43
}
44
});
45
46
vscode.workspace.onDidChangeConfiguration(() => {
47
this.services.forEach((service: any) => {
48
if (service.configurationUpdated && service.configurationUpdated instanceof Function) {
49
service.configurationUpdated(this.createExtensionConfiguration());
50
}
51
});
52
});
53
}
54
55
createExtensionConfiguration(): interfaces.IExtensionConfiguration {
56
const workspaceConfiguration = vscode.workspace.getConfiguration(ConfigurationSectionName);
57
const codeLensEnabled: boolean = workspaceConfiguration.get('codeLens.enabled', true);
58
const decoratorsEnabled: boolean = workspaceConfiguration.get('decorators.enabled', true);
59
60
return {
61
enableCodeLens: codeLensEnabled,
62
enableDecorations: decoratorsEnabled,
63
enableEditorOverview: decoratorsEnabled
64
};
65
}
66
67
dispose() {
68
this.services.forEach(disposable => disposable.dispose());
69
this.services = [];
70
}
71
}
72
73