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
3296 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 { DisposableStore } from '../../../../base/common/lifecycle.js';
7
import { isCodeEditor, isDiffEditor } from '../../../../editor/browser/editorBrowser.js';
8
import { localize, localize2 } from '../../../../nls.js';
9
import { ILocalizedString } from '../../../../platform/action/common/action.js';
10
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
11
import { ContextKeyExpr, IContextKey, IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
12
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
13
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
14
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
15
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
16
import { IOpenerService } from '../../../../platform/opener/common/opener.js';
17
import { Registry } from '../../../../platform/registry/common/platform.js';
18
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
19
import { IThemeService } from '../../../../platform/theme/common/themeService.js';
20
import { OpenFileAction, OpenFolderAction } from '../../../browser/actions/workspaceActions.js';
21
import { ViewPane } from '../../../browser/parts/views/viewPane.js';
22
import { IViewletViewOptions } from '../../../browser/parts/views/viewsViewlet.js';
23
import { WorkbenchStateContext } from '../../../common/contextkeys.js';
24
import { Extensions, IViewDescriptorService, IViewsRegistry, ViewContentGroups } from '../../../common/views.js';
25
import { IEditorService } from '../../../services/editor/common/editorService.js';
26
import { CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_DEBUG_EXTENSION_AVAILABLE, IDebugService } from '../common/debug.js';
27
import { DEBUG_CONFIGURE_COMMAND_ID, DEBUG_START_COMMAND_ID } from './debugCommands.js';
28
29
const debugStartLanguageKey = 'debugStartLanguage';
30
const CONTEXT_DEBUG_START_LANGUAGE = new RawContextKey<string>(debugStartLanguageKey, undefined);
31
const CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR = new RawContextKey<boolean>('debuggerInterestedInActiveEditor', false);
32
33
export class WelcomeView extends ViewPane {
34
35
static readonly ID = 'workbench.debug.welcome';
36
static readonly LABEL: ILocalizedString = localize2('run', "Run");
37
38
private debugStartLanguageContext: IContextKey<string | undefined>;
39
private debuggerInterestedContext: IContextKey<boolean>;
40
41
constructor(
42
options: 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
) {
56
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService);
57
58
this.debugStartLanguageContext = CONTEXT_DEBUG_START_LANGUAGE.bindTo(contextKeyService);
59
this.debuggerInterestedContext = CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR.bindTo(contextKeyService);
60
const lastSetLanguage = storageSevice.get(debugStartLanguageKey, StorageScope.WORKSPACE);
61
this.debugStartLanguageContext.set(lastSetLanguage);
62
63
const setContextKey = () => {
64
let editorControl = this.editorService.activeTextEditorControl;
65
if (isDiffEditor(editorControl)) {
66
editorControl = editorControl.getModifiedEditor();
67
}
68
69
if (isCodeEditor(editorControl)) {
70
const model = editorControl.getModel();
71
const language = model ? model.getLanguageId() : undefined;
72
if (language && this.debugService.getAdapterManager().someDebuggerInterestedInLanguage(language)) {
73
this.debugStartLanguageContext.set(language);
74
this.debuggerInterestedContext.set(true);
75
storageSevice.store(debugStartLanguageKey, language, StorageScope.WORKSPACE, StorageTarget.MACHINE);
76
return;
77
}
78
}
79
this.debuggerInterestedContext.set(false);
80
};
81
82
const disposables = new DisposableStore();
83
this._register(disposables);
84
85
this._register(editorService.onDidActiveEditorChange(() => {
86
disposables.clear();
87
88
let editorControl = this.editorService.activeTextEditorControl;
89
if (isDiffEditor(editorControl)) {
90
editorControl = editorControl.getModifiedEditor();
91
}
92
93
if (isCodeEditor(editorControl)) {
94
disposables.add(editorControl.onDidChangeModelLanguage(setContextKey));
95
}
96
97
setContextKey();
98
}));
99
this._register(this.debugService.getAdapterManager().onDidRegisterDebugger(setContextKey));
100
this._register(this.onDidChangeBodyVisibility(visible => {
101
if (visible) {
102
setContextKey();
103
}
104
}));
105
setContextKey();
106
107
const debugKeybinding = this.keybindingService.lookupKeybinding(DEBUG_START_COMMAND_ID);
108
debugKeybindingLabel = debugKeybinding ? ` (${debugKeybinding.getLabel()})` : '';
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(
143
{
144
key: 'customizeRunAndDebug',
145
comment: [
146
'Please do not translate the word "command", it is part of our internal syntax which must not change',
147
'{Locked="](command:{0})"}'
148
]
149
},
150
"To customize Run and Debug [create a launch.json file](command:{0}).", `${DEBUG_CONFIGURE_COMMAND_ID}?${encodeURIComponent(JSON.stringify([{ addNew: true }]))}`),
151
when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, WorkbenchStateContext.notEqualsTo('empty')),
152
group: ViewContentGroups.Debug
153
});
154
155
viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {
156
content: localize(
157
{
158
key: 'customizeRunAndDebugOpenFolder',
159
comment: [
160
'Please do not translate the word "command", it is part of our internal syntax which must not change',
161
'Please do not translate "launch.json", it is the specific configuration file name',
162
'{Locked="](command:{0})"}',
163
]
164
},
165
"To customize Run and Debug, [open a folder](command:{0}) and create a launch.json file.", OpenFolderAction.ID),
166
when: ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, WorkbenchStateContext.isEqualTo('empty')),
167
group: ViewContentGroups.Debug
168
});
169
170
viewsRegistry.registerViewWelcomeContent(WelcomeView.ID, {
171
content: localize('allDebuggersDisabled', "All debug extensions are disabled. Enable a debug extension or install a new one from the Marketplace."),
172
when: CONTEXT_DEBUG_EXTENSION_AVAILABLE.toNegated(),
173
group: ViewContentGroups.Debug
174
});
175
176