Path: blob/main/src/vs/workbench/contrib/debug/browser/welcomeView.ts
5251 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 { createCommandUri } from '../../../../base/common/htmlContent.js';6import { DisposableStore } from '../../../../base/common/lifecycle.js';7import { isCodeEditor, isDiffEditor } from '../../../../editor/browser/editorBrowser.js';8import { localize, localize2 } from '../../../../nls.js';9import { ILocalizedString } from '../../../../platform/action/common/action.js';10import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';11import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';12import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';13import { IHoverService } from '../../../../platform/hover/browser/hover.js';14import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';15import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';16import { IOpenerService } from '../../../../platform/opener/common/opener.js';17import { Registry } from '../../../../platform/registry/common/platform.js';18import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';19import { IThemeService } from '../../../../platform/theme/common/themeService.js';20import { OpenFileAction, OpenFolderAction } from '../../../browser/actions/workspaceActions.js';21import { ViewPane } from '../../../browser/parts/views/viewPane.js';22import { IViewletViewOptions } from '../../../browser/parts/views/viewsViewlet.js';23import { WorkbenchStateContext } from '../../../common/contextkeys.js';24import { Extensions, IViewDescriptorService, IViewsRegistry, ViewContentGroups } from '../../../common/views.js';25import { IEditorService } from '../../../services/editor/common/editorService.js';26import { CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_DEBUG_EXTENSION_AVAILABLE, IDebugService } from '../common/debug.js';27import { DEBUG_CONFIGURE_COMMAND_ID, DEBUG_START_COMMAND_ID } from './debugCommands.js';2829const debugStartLanguageKey = 'debugStartLanguage';30const CONTEXT_DEBUG_START_LANGUAGE = new RawContextKey<string>(debugStartLanguageKey, undefined);31const CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR = new RawContextKey<boolean>('debuggerInterestedInActiveEditor', false);3233export class WelcomeView extends ViewPane {3435static readonly ID = 'workbench.debug.welcome';36static readonly LABEL: ILocalizedString = localize2('run', "Run");3738private debugStartLanguageContext: IContextKey<string | undefined>;39private debuggerInterestedContext: IContextKey<boolean>;4041constructor(42options: IViewletViewOptions,43@IThemeService themeService: IThemeService,44@IKeybindingService keybindingService: IKeybindingService,45@IContextMenuService contextMenuService: IContextMenuService,46@IConfigurationService configurationService: IConfigurationService,47@IContextKeyService contextKeyService: IContextKeyService,48@IDebugService private readonly debugService: IDebugService,49@IEditorService private readonly editorService: IEditorService,50@IInstantiationService instantiationService: IInstantiationService,51@IViewDescriptorService viewDescriptorService: IViewDescriptorService,52@IOpenerService openerService: IOpenerService,53@IStorageService storageSevice: IStorageService,54@IHoverService hoverService: IHoverService,55) {56super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService);5758this.debugStartLanguageContext = CONTEXT_DEBUG_START_LANGUAGE.bindTo(contextKeyService);59this.debuggerInterestedContext = CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR.bindTo(contextKeyService);60const lastSetLanguage = storageSevice.get(debugStartLanguageKey, StorageScope.WORKSPACE);61this.debugStartLanguageContext.set(lastSetLanguage);6263const setContextKey = () => {64let editorControl = this.editorService.activeTextEditorControl;65if (isDiffEditor(editorControl)) {66editorControl = editorControl.getModifiedEditor();67}6869if (isCodeEditor(editorControl)) {70const model = editorControl.getModel();71const language = model ? model.getLanguageId() : undefined;72if (language && this.debugService.getAdapterManager().someDebuggerInterestedInLanguage(language)) {73this.debugStartLanguageContext.set(language);74this.debuggerInterestedContext.set(true);75storageSevice.store(debugStartLanguageKey, language, StorageScope.WORKSPACE, StorageTarget.MACHINE);76return;77}78}79this.debuggerInterestedContext.set(false);80};8182const disposables = new DisposableStore();83this._register(disposables);8485this._register(editorService.onDidActiveEditorChange(() => {86disposables.clear();8788let editorControl = this.editorService.activeTextEditorControl;89if (isDiffEditor(editorControl)) {90editorControl = editorControl.getModifiedEditor();91}9293if (isCodeEditor(editorControl)) {94disposables.add(editorControl.onDidChangeModelLanguage(setContextKey));95}9697setContextKey();98}));99this._register(this.debugService.getAdapterManager().onDidRegisterDebugger(setContextKey));100this._register(this.onDidChangeBodyVisibility(visible => {101if (visible) {102setContextKey();103}104}));105setContextKey();106107debugKeybindingLabel = this.keybindingService.appendKeybinding('', DEBUG_START_COMMAND_ID);108}109110override shouldShowWelcome(): boolean {111return true;112}113}114115const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);116viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {117content: localize(118{119key: 'openAFileWhichCanBeDebugged',120comment: [121'Please do not translate the word "command", it is part of our internal syntax which must not change',122'{Locked="](command:{0})"}'123]124},125"[Open a file](command:{0}) which can be debugged or run.", OpenFileAction.ID126),127when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR.toNegated()),128group: ViewContentGroups.Open,129});130131let debugKeybindingLabel = '';132viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {133content: `[${localize('runAndDebugAction', "Run and Debug")}${debugKeybindingLabel}](command:${DEBUG_START_COMMAND_ID})`,134when: CONTEXT_DEBUGGERS_AVAILABLE,135group: ViewContentGroups.Debug,136// Allow inserting more buttons directly after this one (by setting order to 1).137order: 1138});139140viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {141content: localize({ key: 'customizeRunAndDebug2', comment: ['{Locked="launch.json"}', '{Locked="["}', '{Locked="]({0})"}'] },142"To customize Run and Debug [create a launch.json file]({0}).", `${createCommandUri(DEBUG_CONFIGURE_COMMAND_ID, { addNew: true }).toString()}`),143when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, WorkbenchStateContext.notEqualsTo('empty')),144group: ViewContentGroups.Debug145});146147viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {148content: localize(149{150key: 'customizeRunAndDebugOpenFolder2',151comment: [152'{Locked="launch.json"}',153'{Locked="["}',154'{Locked="]({0})"}',155]156},157"To customize Run and Debug, [open a folder]({0}) and create a launch.json file.", createCommandUri(OpenFolderAction.ID).toString()),158when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, WorkbenchStateContext.isEqualTo('empty')),159group: ViewContentGroups.Debug160});161162viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {163content: localize('allDebuggersDisabled', "All debug extensions are disabled. Enable a debug extension or install a new one from the Marketplace."),164when: CONTEXT_DEBUG_EXTENSION_AVAILABLE.toNegated(),165group: ViewContentGroups.Debug166});167168169