Skip to content

Commit 11509be

Browse files
authored
Moving from debugProxy to AdapterExecutableCommand (#1387)
* Moving from debugProxy to AdapterExecutableCommand * Addressing PR issues Moving registerAdapterExecutableCommand to Debugger/extension.ts * Updating comment
1 parent aa4550c commit 11509be

File tree

6 files changed

+66
-242
lines changed

6 files changed

+66
-242
lines changed

Extension/package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@
307307
"cpp"
308308
]
309309
},
310-
"runtime": "node",
311-
"program": "./out/src/Debugger/Proxy/debugProxy.js",
310+
"adapterExecutableCommand": "extension.cppdbgAdapterExecutableCommand",
312311
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
313312
"variables": {
314313
"pickProcess": "extension.pickNativeProcess",
@@ -758,11 +757,7 @@
758757
"cpp"
759758
]
760759
},
761-
"runtime": "node",
762-
"program": "./out/src/Debugger/Proxy/debugProxy.js",
763-
"args": [
764-
"--interpreter=vscode"
765-
],
760+
"adapterExecutableCommand": "extension.cppvsdbgAdapterExecutableCommand",
766761
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
767762
"variables": {
768763
"pickProcess": "extension.pickNativeProcess"
@@ -1213,4 +1208,4 @@
12131208
"binaries": []
12141209
}
12151210
]
1216-
}
1211+
}

Extension/src/Debugger/Proxy/debugProtocol.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

Extension/src/Debugger/Proxy/debugProxy.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

Extension/src/Debugger/Proxy/debugProxyUtils.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

Extension/src/Debugger/extension.ts

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as path from 'path';
1515
// The extension deactivate method is asynchronous, so we handle the disposables ourselves instead of using extensonContext.subscriptions.
1616
let disposables: vscode.Disposable[] = [];
1717

18-
export function activate() {
18+
export function initialize() {
1919
// Activate Process Picker Commands
2020
let attachItemsProvider = NativeAttachItemsProviderFactory.Get();
2121
let attacher = new AttachPicker(attachItemsProvider);
@@ -37,13 +37,69 @@ export function activate() {
3737

3838
disposables.push(vscode.window.onDidChangeActiveTextEditor(onDidChangeActiveTextEditor));
3939
onDidChangeActiveTextEditor(vscode.window.activeTextEditor);
40+
41+
// Activate Adapter Commands
42+
registerAdapterExecutableCommands();
4043
}
4144

42-
export function deactivate(): void {
45+
export function dispose(): void {
4346
disposables.forEach(d => d.dispose());
4447
}
4548

4649
function onDidChangeActiveTextEditor(editor: vscode.TextEditor): void {
4750
if (util.getShowReloadPromptOnce() && editor && editor.document.fileName.endsWith(path.sep + "launch.json"))
4851
util.showReloadOrWaitPromptOnce();
52+
}
53+
54+
// Registers adapterExecutableCommands for cppdbg and cppvsdbg. If it is not ready, it will prompt waiting for the download.
55+
//
56+
// Note: util.extensionContext.extensionPath is needed for the commands because VsCode does not support relative paths for adapterExecutableComand
57+
function registerAdapterExecutableCommands(): void {
58+
disposables.push(vscode.commands.registerCommand('extension.cppdbgAdapterExecutableCommand', () => {
59+
return util.checkInstallLockFile().then(ready => {
60+
if (ready)
61+
{
62+
let command: string = path.join(util.extensionContext.extensionPath, './debugAdapters/OpenDebugAD7');
63+
64+
// Windows has the exe in debugAdapters/bin.
65+
if (os.platform() === 'win32')
66+
{
67+
command = path.join(util.extensionContext.extensionPath, "./debugAdapters/bin/OpenDebugAD7.exe");
68+
}
69+
70+
return {
71+
command: command
72+
}
73+
}
74+
else {
75+
util.showReloadOrWaitPromptOnce();
76+
// TODO: VsCode displays null return as "Cannot find executable 'null'". Fix if they have a way to not display their prompt.
77+
return null;
78+
}
79+
});
80+
}));
81+
82+
disposables.push(vscode.commands.registerCommand('extension.cppvsdbgAdapterExecutableCommand', () => {
83+
if (os.platform() != 'win32')
84+
{
85+
vscode.window.showErrorMessage("Debugger type 'cppvsdbg' is not avaliable for non-Windows machines.");
86+
return null;
87+
}
88+
else {
89+
return util.checkInstallLockFile().then(ready => {
90+
if (ready)
91+
{
92+
return {
93+
command: path.join(util.extensionContext.extensionPath,'./debugAdapters/vsdbg/bin/vsdbg.exe'),
94+
args: ['--interpreter=vscode']
95+
}
96+
}
97+
else {
98+
util.showReloadOrWaitPromptOnce();
99+
// TODO: VsCode displays null return as "Cannot find executable 'null'". Fix if they have a way to not display their prompt.
100+
return null;
101+
}
102+
});
103+
}
104+
}));
49105
}

Extension/src/main.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ export function activate(context: vscode.ExtensionContext) {
107107
Telemetry.activate();
108108
util.setProgress(0);
109109

110-
// Activate Configuration Provider and Process Picker Commands.
111-
DebuggerExtension.activate();
110+
// Initialize the DebuggerExtension and register the related commands and providers.
111+
DebuggerExtension.initialize();
112112

113113
if (context.globalState.get<number>(userBucketString, -1) == -1) {
114114
let bucket = Math.floor(Math.random() * userBucketMax) + 1; // Range is [1, userBucketMax].
@@ -165,7 +165,7 @@ export function activate(context: vscode.ExtensionContext) {
165165
}
166166

167167
export function deactivate(): Thenable<void> {
168-
DebuggerExtension.deactivate();
168+
DebuggerExtension.dispose();
169169

170170
tempCommands.forEach((command) => {
171171
command.dispose();
@@ -427,7 +427,7 @@ function checkDistro(channel: vscode.OutputChannel, platformInfo: PlatformInform
427427
}
428428
}
429429

430-
function rewriteManifest(installBlob: InstallBlob): Promise<void> {
430+
function rewriteManifest(installBlob: InstallBlob): void {
431431
installBlob.stage = "rewriteManifest";
432432

433433
// Replace activationEvents with the events that the extension should be activated for subsequent sessions.
@@ -452,20 +452,4 @@ function rewriteManifest(installBlob: InstallBlob): Promise<void> {
452452
"onCommand:C_Cpp.TakeSurvey",
453453
"onDebug"
454454
];
455-
456-
// Remove the entry for cppdbg's proxy stub and replace it with the real debugger binary
457-
util.packageJson.contributes.debuggers[0].runtime = undefined;
458-
util.packageJson.contributes.debuggers[0].program = './debugAdapters/OpenDebugAD7';
459-
util.packageJson.contributes.debuggers[0].windows = { "program": "./debugAdapters/bin/OpenDebugAD7.exe" };
460-
461-
// Remove the entry for cppvsdbg's proxy stub and replace it with the real debugger binary for Windows only.
462-
if (os.platform() === 'win32') {
463-
util.packageJson.contributes.debuggers[1].runtime = undefined;
464-
util.packageJson.contributes.debuggers[1].program = './debugAdapters/vsdbg/bin/vsdbg.exe';
465-
}
466-
467-
if (util.packageJson.extensionFolderPath.includes(".vscode-insiders"))
468-
util.packageJson.contributes.configuration.properties["C_Cpp.intelliSenseEngine"].default = "Default";
469-
470-
return util.writeFileText(util.getPackageJsonPath(), util.getPackageJsonString());
471-
}
455+
}

0 commit comments

Comments
 (0)