|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +import { inject, injectable } from 'inversify'; |
| 7 | +import { ConfigurationTarget } from 'vscode'; |
| 8 | +import { IApplicationShell, ICommandManager } from '../../common/application/types'; |
| 9 | +import { Commands } from '../../common/constants'; |
| 10 | +import { IConfigurationService, IDisposableRegistry } from '../../common/types'; |
| 11 | +import { Diagnostics } from '../../common/utils/localize'; |
| 12 | +import { ISourceMapSupportService } from './types'; |
| 13 | + |
| 14 | +@injectable() |
| 15 | +export class SourceMapSupportService implements ISourceMapSupportService { |
| 16 | + constructor(@inject(ICommandManager) private readonly commandManager: ICommandManager, |
| 17 | + @inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry, |
| 18 | + @inject(IConfigurationService) private readonly configurationService: IConfigurationService, |
| 19 | + @inject(IApplicationShell) private readonly shell: IApplicationShell) { |
| 20 | + |
| 21 | + } |
| 22 | + public register(): void { |
| 23 | + this.disposables.push(this.commandManager.registerCommand(Commands.Enable_SourceMap_Support, this.onEnable, this)); |
| 24 | + } |
| 25 | + public async enable(): Promise<void> { |
| 26 | + await this.configurationService.updateSetting('diagnostics.sourceMapsEnabled', true, undefined, ConfigurationTarget.Global); |
| 27 | + await this.commandManager.executeCommand('workbench.action.reloadWindow'); |
| 28 | + } |
| 29 | + protected async onEnable(): Promise<void> { |
| 30 | + const enableSourceMapsAndReloadVSC = Diagnostics.enableSourceMapsAndReloadVSC(); |
| 31 | + const selection = await this.shell.showWarningMessage(Diagnostics.warnBeforeEnablingSourceMaps(), enableSourceMapsAndReloadVSC); |
| 32 | + if (selection === enableSourceMapsAndReloadVSC) { |
| 33 | + await this.enable(); |
| 34 | + } |
| 35 | + } |
| 36 | +} |
0 commit comments