|
7 | 7 |
|
8 | 8 | import * as Net from "net"; |
9 | 9 | import * as vscode from "vscode"; |
| 10 | +import { join } from "path"; |
| 11 | +import { platform } from "process"; |
| 12 | +import { randomBytes } from "crypto"; |
10 | 13 | import { Socket } from "net"; |
| 14 | +import { tmpdir } from "os"; |
11 | 15 |
|
12 | 16 | import { CancellationToken, DebugConfiguration, ProviderResult, TextEditor, WorkspaceFolder } from "vscode"; |
13 | 17 |
|
@@ -54,24 +58,27 @@ class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory |
54 | 58 | } |
55 | 59 | } |
56 | 60 |
|
57 | | -class MQueryNodeDebugAdapterServerDescriptorFactory implements vscode.DebugAdapterDescriptorFactory { |
| 61 | +class MQueryNodeDebugAdapterNamedPipeServerDescriptorFactory implements vscode.DebugAdapterDescriptorFactory { |
58 | 62 | private server?: Net.Server; |
59 | 63 |
|
60 | 64 | createDebugAdapterDescriptor( |
61 | 65 | _session: vscode.DebugSession, |
62 | 66 | _executable: vscode.DebugAdapterExecutable | undefined, |
63 | 67 | ): vscode.ProviderResult<vscode.DebugAdapterDescriptor> { |
64 | 68 | if (!this.server) { |
65 | | - // start listening on a random port |
| 69 | + // start listening on a random named pipe path |
| 70 | + const pipeName: string = randomBytes(10).toString("utf8"); |
| 71 | + const pipePath: string = platform === "win32" ? join("\\\\.\\pipe\\", pipeName) : join(tmpdir(), pipeName); |
| 72 | + |
66 | 73 | this.server = Net.createServer((socket: Socket) => { |
67 | 74 | const session: MQueryDebugSession = new MQueryDebugSession(); |
68 | 75 | session.setRunAsServer(true); |
69 | 76 | session.start(socket as NodeJS.ReadableStream, socket); |
70 | | - }).listen(0); |
| 77 | + }).listen(pipePath); |
71 | 78 | } |
72 | 79 |
|
73 | 80 | // make VS Code connect to debug server |
74 | | - return new vscode.DebugAdapterServer((this.server.address() as Net.AddressInfo).port); |
| 81 | + return new vscode.DebugAdapterNamedPipeServer(this.server.address() as string); |
75 | 82 | } |
76 | 83 |
|
77 | 84 | dispose(): void { |
@@ -106,7 +113,9 @@ export function activateMQueryDebug(vscExtCtx: vscode.ExtensionContext, mode: "i |
106 | 113 | ); |
107 | 114 |
|
108 | 115 | const factory: vscode.DebugAdapterDescriptorFactory = |
109 | | - mode === "server" ? new MQueryNodeDebugAdapterServerDescriptorFactory() : new InlineDebugAdapterFactory(); |
| 116 | + mode === "server" |
| 117 | + ? new MQueryNodeDebugAdapterNamedPipeServerDescriptorFactory() |
| 118 | + : new InlineDebugAdapterFactory(); |
110 | 119 |
|
111 | 120 | vscExtCtx.subscriptions.push( |
112 | 121 | vscode.debug.registerDebugAdapterDescriptorFactory(ExtensionConstants.PQDebugType, factory), |
|
0 commit comments