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