Path: blob/main/src/vs/workbench/contrib/debug/browser/welcomeView.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*--------------------------------------------------------------------------------------------*/45import { DisposableStore } from '../../../../base/common/lifecycle.js';6import { isCodeEditor, isDiffEditor } from '../../../../editor/browser/editorBrowser.js';7import { localize, localize2 } from '../../../../nls.js';8import { ILocalizedString } from '../../../../platform/action/common/action.js';9import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';10import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';11import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';12import { IHoverService } from '../../../../platform/hover/browser/hover.js';13import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';14import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';15import { IOpenerService } from '../../../../platform/opener/common/opener.js';16import { Registry } from '../../../../platform/registry/common/platform.js';17import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';18import { IThemeService } from '../../../../platform/theme/common/themeService.js';19import { OpenFileAction, OpenFolderAction } from '../../../browser/actions/workspaceActions.js';20import { ViewPane } from '../../../browser/parts/views/viewPane.js';21import { IViewletViewOptions } from '../../../browser/parts/views/viewsViewlet.js';22import { WorkbenchStateContext } from '../../../common/contextkeys.js';23import { Extensions, IViewDescriptorService, IViewsRegistry, ViewContentGroups } from '../../../common/views.js';24import { IEditorService } from '../../../services/editor/common/editorService.js';25import { CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_DEBUG_EXTENSION_AVAILABLE, IDebugService } from '../common/debug.js';26import { DEBUG_CONFIGURE_COMMAND_ID, DEBUG_START_COMMAND_ID } from './debugCommands.js';2728const debugStartLanguageKey = 'debugStartLanguage';29const CONTEXT_DEBUG_START_LANGUAGE = new RawContextKey<string>(debugStartLanguageKey, undefined);30const CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR = new RawContextKey<boolean>('debuggerInterestedInActiveEditor', false);3132export class WelcomeView extends ViewPane {3334static readonly ID = 'workbench.debug.welcome';35static readonly LABEL: ILocalizedString = localize2('run', "Run");3637private debugStartLanguageContext: IContextKey<string | undefined>;38private debuggerInterestedContext: IContextKey<boolean>;3940constructor(41options: IViewletViewOptions,42@IThemeService themeService: IThemeService,43@IKeybindingService keybindingService: IKeybindingService,44@IContextMenuService contextMenuService: IContextMenuService,45@IConfigurationService configurationService: IConfigurationService,46@IContextKeyService contextKeyService: IContextKeyService,47@IDebugService private readonly debugService: IDebugService,48@IEditorService private readonly editorService: IEditorService,49@IInstantiationService instantiationService: IInstantiationService,50@IViewDescriptorService viewDescriptorService: IViewDescriptorService,51@IOpenerService openerService: IOpenerService,52@IStorageService storageSevice: IStorageService,53@IHoverService hoverService: IHoverService,54) {55super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService);5657this.debugStartLanguageContext = CONTEXT_DEBUG_START_LANGUAGE.bindTo(contextKeyService);58this.debuggerInterestedContext = CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR.bindTo(contextKeyService);59const lastSetLanguage = storageSevice.get(debugStartLanguageKey, StorageScope.WORKSPACE);60this.debugStartLanguageContext.set(lastSetLanguage);6162const setContextKey = () => {63let editorControl = this.editorService.activeTextEditorControl;64if (isDiffEditor(editorControl)) {65editorControl = editorControl.getModifiedEditor();66}6768if (isCodeEditor(editorControl)) {69const model = editorControl.getModel();70const language = model ? model.getLanguageId() : undefined;71if (language && this.debugService.getAdapterManager().someDebuggerInterestedInLanguage(language)) {72this.debugStartLanguageContext.set(language);73this.debuggerInterestedContext.set(true);74storageSevice.store(debugStartLanguageKey, language, StorageScope.WORKSPACE, StorageTarget.MACHINE);75return;76}77}78this.debuggerInterestedContext.set(false);79};8081const disposables = new DisposableStore();82this._register(disposables);8384this._register(editorService.onDidActiveEditorChange(() => {85disposables.clear();8687let editorControl = this.editorService.activeTextEditorControl;88if (isDiffEditor(editorControl)) {89editorControl = editorControl.getModifiedEditor();90}9192if (isCodeEditor(editorControl)) {93disposables.add(editorControl.onDidChangeModelLanguage(setContextKey));94}9596setContextKey();97}));98this._register(this.debugService.getAdapterManager().onDidRegisterDebugger(setContextKey));99this._register(this.onDidChangeBodyVisibility(visible => {100if (visible) {101setContextKey();102}103}));104setContextKey();105106const debugKeybinding = this.keybindingService.lookupKeybinding(DEBUG_START_COMMAND_ID);107debugKeybindingLabel = debugKeybinding ? ` (${debugKeybinding.getLabel()})` : '';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(142{143key: 'customizeRunAndDebug',144comment: [145'Please do not translate the word "command", it is part of our internal syntax which must not change',146'{Locked="](command:{0})"}'147]148},149"To customize Run and Debug [create a launch.json file](command:{0}).", `${DEBUG_CONFIGURE_COMMAND_ID}?${encodeURIComponent(JSON.stringify([{ addNew: true }]))}`),150when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, WorkbenchStateContext.notEqualsTo('empty')),151group: ViewContentGroups.Debug152});153154viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {155content: localize(156{157key: 'customizeRunAndDebugOpenFolder',158comment: [159'Please do not translate the word "command", it is part of our internal syntax which must not change',160'Please do not translate "launch.json", it is the specific configuration file name',161'{Locked="](command:{0})"}',162]163},164"To customize Run and Debug, [open a folder](command:{0}) and create a launch.json file.", OpenFolderAction.ID),165when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, WorkbenchStateContext.isEqualTo('empty')),166group: ViewContentGroups.Debug167});168169viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {170content: localize('allDebuggersDisabled', "All debug extensions are disabled. Enable a debug extension or install a new one from the Marketplace."),171when: CONTEXT_DEBUG_EXTENSION_AVAILABLE.toNegated(),172group: ViewContentGroups.Debug173});174175176