Path: blob/main/extensions/merge-conflict/src/services.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*--------------------------------------------------------------------------------------------*/4import * as vscode from 'vscode';5import DocumentTracker from './documentTracker';6import CodeLensProvider from './codelensProvider';7import CommandHandler from './commandHandler';8import ContentProvider from './contentProvider';9import Decorator from './mergeDecorator';10import * as interfaces from './interfaces';11import TelemetryReporter from '@vscode/extension-telemetry';1213const ConfigurationSectionName = 'merge-conflict';1415export default class ServiceWrapper implements vscode.Disposable {1617private services: vscode.Disposable[] = [];18private telemetryReporter: TelemetryReporter;1920constructor(private context: vscode.ExtensionContext) {21const { aiKey } = context.extension.packageJSON as { aiKey: string };22this.telemetryReporter = new TelemetryReporter(aiKey);23context.subscriptions.push(this.telemetryReporter);24}2526begin() {2728const configuration = this.createExtensionConfiguration();29const documentTracker = new DocumentTracker(this.telemetryReporter);3031this.services.push(32documentTracker,33new CommandHandler(documentTracker),34new CodeLensProvider(documentTracker),35new ContentProvider(this.context),36new Decorator(this.context, documentTracker),37);3839this.services.forEach((service: any) => {40if (service.begin && service.begin instanceof Function) {41service.begin(configuration);42}43});4445vscode.workspace.onDidChangeConfiguration(() => {46this.services.forEach((service: any) => {47if (service.configurationUpdated && service.configurationUpdated instanceof Function) {48service.configurationUpdated(this.createExtensionConfiguration());49}50});51});52}5354createExtensionConfiguration(): interfaces.IExtensionConfiguration {55const workspaceConfiguration = vscode.workspace.getConfiguration(ConfigurationSectionName);56const codeLensEnabled: boolean = workspaceConfiguration.get('codeLens.enabled', true);57const decoratorsEnabled: boolean = workspaceConfiguration.get('decorators.enabled', true);5859return {60enableCodeLens: codeLensEnabled,61enableDecorations: decoratorsEnabled,62enableEditorOverview: decoratorsEnabled63};64}6566dispose() {67this.services.forEach(disposable => disposable.dispose());68this.services = [];69}70}717273