forked from dotnet/vscode-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.ts
More file actions
124 lines (109 loc) · 5.28 KB
/
debugger.ts
File metadata and controls
124 lines (109 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { addAssetsIfNecessary, generateAssets } from '../../shared/assets';
import { DotnetWorkspaceConfigurationProvider } from '../../shared/workspaceConfigurationProvider';
import { IWorkspaceDebugInformationProvider } from '../../shared/IWorkspaceDebugInformationProvider';
import { RoslynLanguageServer } from '../server/roslynLanguageServer';
import { RoslynWorkspaceDebugInformationProvider } from '../debugger/roslynWorkspaceDebugConfigurationProvider';
import { PlatformInformation } from '../../shared/platform';
import { DotnetConfigurationResolver } from '../../shared/dotnetConfigurationProvider';
import { getCSharpDevKit } from '../../utils/getCSharpDevKit';
import { RoslynLanguageServerEvents, ServerState } from '../server/languageServerEvents';
export function registerDebugger(
context: vscode.ExtensionContext,
languageServer: RoslynLanguageServer,
languageServerEvents: RoslynLanguageServerEvents,
platformInfo: PlatformInformation,
csharpOutputChannel: vscode.LogOutputChannel
) {
const workspaceInformationProvider: IWorkspaceDebugInformationProvider =
new RoslynWorkspaceDebugInformationProvider(languageServer, csharpOutputChannel);
const disposable = languageServerEvents.onServerStateChange(async (e) => {
if (e.state === ServerState.ProjectInitializationComplete) {
const csharpDevkitExtension = getCSharpDevKit();
if (!csharpDevkitExtension) {
// Update or add tasks.json and launch.json
await addAssetsIfNecessary(context, workspaceInformationProvider);
}
}
});
context.subscriptions.push(disposable);
const dotnetWorkspaceConfigurationProvider = new DotnetWorkspaceConfigurationProvider(
workspaceInformationProvider,
platformInfo,
csharpOutputChannel
);
// Register ConfigurationProvider
context.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider(
'dotnet',
new DotnetConfigurationResolver(workspaceInformationProvider, dotnetWorkspaceConfigurationProvider)
)
);
context.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider('coreclr', dotnetWorkspaceConfigurationProvider)
);
context.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider('monovsdbg', dotnetWorkspaceConfigurationProvider)
);
context.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider('monovsdbg_wasm', dotnetWorkspaceConfigurationProvider)
);
context.subscriptions.push(
vscode.commands.registerCommand(
'dotnet.generateAssets',
async (selectedIndex: number, options: { skipPrompt?: boolean } = {}) => {
if (!(await promptForDevKitDebugConfigurations(options))) {
return;
}
await generateAssets(workspaceInformationProvider, selectedIndex);
}
)
);
}
async function promptForDevKitDebugConfigurations(options: { skipPrompt?: boolean }): Promise<boolean> {
if (getCSharpDevKit()) {
// If skipPrompt is true, proceed with generating assets without showing the dialog
if (options.skipPrompt) {
return true;
}
let result: boolean | undefined = undefined;
while (result === undefined) {
const labelYes = vscode.l10n.t('Yes');
const labelNo = vscode.l10n.t('No');
const labelMoreInfo = vscode.l10n.t('More Information');
const title: string = vscode.l10n.t('.NET: Generate Assets for Build and Debug');
const dialogResult = await vscode.window.showInformationMessage(
title,
{
modal: true,
detail: vscode.l10n.t(
`The '{0}' command is not recommended to be used when C# Dev Kit extension is installed. Would you like build and debug using a dynamic configuration instead?`,
title
),
},
labelYes,
labelNo,
labelMoreInfo
);
if (dialogResult === labelYes) {
await vscode.commands.executeCommand('workbench.action.debug.selectandstart', 'dotnet');
result = false;
} else if (dialogResult === labelNo) {
// User cancelled dialog and wishes to continue generating assets.
result = true;
} else if (dialogResult === labelMoreInfo) {
const launchjsonDescriptionURL = 'https://aka.ms/VSCode-CS-DynamicDebugConfig';
await vscode.env.openExternal(vscode.Uri.parse(launchjsonDescriptionURL));
} else if (dialogResult === undefined) {
// Do nothing, user closed the dialog.
result = false;
}
}
return result;
}
return true;
}