This repository was archived by the owner on Nov 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebugger.ts
More file actions
60 lines (51 loc) · 2.27 KB
/
debugger.ts
File metadata and controls
60 lines (51 loc) · 2.27 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
import * as vscode from 'vscode';
import { DebugProtocol } from '@vscode/debugprotocol';
import { RunspaceTreeItem } from '../platform-treeview';
import { Container } from '../container';
export const registerDebuggerCommands = (context: vscode.ExtensionContext) => {
vscode.commands.registerCommand('powershell-universal.attachRunspace', (item) => attachRunspace(item, context));
vscode.commands.registerCommand('powershell-universal.connectDebugger', _ => Container.universal.connectDebugger());
vscode.commands.registerCommand('powershell-universal.disconnectDebugger', _ => Container.universal.disconnectDebugger());
vscode.debug.registerDebugAdapterDescriptorFactory('powershelluniversal', {
createDebugAdapterDescriptor: (_session) => {
return new vscode.DebugAdapterInlineImplementation(new UniversalDebugAdapter());
}
});
}
export const attachRunspace = async (runspace: RunspaceTreeItem, context: vscode.ExtensionContext) => {
await vscode.debug.startDebugging(undefined, {
name: "PowerShell Universal",
type: "powershelluniversal",
request: "attach",
processId: runspace.process.processId,
runspaceId: runspace.runspace.runspaceId
});
};
export class UniversalDebugAdapter implements vscode.DebugAdapter {
constructor() {
Container.universal.registerDebugAdapter(this);
}
private sendMessage = new vscode.EventEmitter<DebugProtocol.ProtocolMessage>();
readonly onDidSendMessage: vscode.Event<DebugProtocol.ProtocolMessage> = this.sendMessage.event;
handleMessage(message: DebugProtocol.ProtocolMessage): void {
switch (message.type) {
case 'request':
var request = message as DebugProtocol.Request;
if (request.command === 'disconnect') {
Container.universal.unregisterDebugAdapter();
} else {
Container.universal.sendDebuggerMessage(request);
}
break;
case 'response':
this.sendMessage.fire(message);
break;
case 'event':
this.sendMessage.fire(message);
break;
}
}
dispose() {
Container.universal.unregisterDebugAdapter();
}
}