Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@
{
"type": "powerquery",
"request": "launch",
"name": "%extension.pqtest.initialConfigurations.name%",
"name": "Evaluate power query file.",
"program": "${workspaceFolder}/${command:AskForPowerQueryFileName}"
}
],
"configurationSnippets": [
{
"label": "powerquery Debug: Launch",
"description": "%extension.pqtest.configurationSnippets.description%",
"description": "A new configuration for testing power query file a user selected.",
"body": {
"type": "powerquery",
"request": "launch",
Expand Down
4 changes: 1 addition & 3 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@
"extension.pqtest.debugger.properties.operation.description": "PQTest operation string",
"extension.pqtest.debugger.properties.operation.info.description": "info: Returns all module information",
"extension.pqtest.debugger.properties.operation.runTest.description": "run-test: test connection",
"extension.pqtest.debugger.properties.operation.testConnection.description": "test-connection: test current connection",
"extension.pqtest.initialConfigurations.name": "Evaluate power query file.",
"extension.pqtest.configurationSnippets.description": "A new configuration for testing power query file a user selected."
"extension.pqtest.debugger.properties.operation.testConnection.description": "test-connection: test current connection"
}
19 changes: 14 additions & 5 deletions src/debugAdaptor/activateMQueryDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import * as Net from "net";
import * as vscode from "vscode";
import { join } from "path";
import { platform } from "process";
import { randomBytes } from "crypto";
import { Socket } from "net";
import { tmpdir } from "os";

import { CancellationToken, DebugConfiguration, ProviderResult, TextEditor, WorkspaceFolder } from "vscode";

Expand Down Expand Up @@ -54,24 +58,27 @@ class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory
}
}

class MQueryNodeDebugAdapterServerDescriptorFactory implements vscode.DebugAdapterDescriptorFactory {
class MQueryNodeDebugAdapterNamedPipeServerDescriptorFactory implements vscode.DebugAdapterDescriptorFactory {
private server?: Net.Server;

createDebugAdapterDescriptor(
_session: vscode.DebugSession,
_executable: vscode.DebugAdapterExecutable | undefined,
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
if (!this.server) {
// start listening on a random port
// start listening on a random named pipe path
const pipeName: string = randomBytes(10).toString("utf8");
const pipePath: string = platform === "win32" ? join("\\\\.\\pipe\\", pipeName) : join(tmpdir(), pipeName);

this.server = Net.createServer((socket: Socket) => {
const session: MQueryDebugSession = new MQueryDebugSession();
session.setRunAsServer(true);
session.start(socket as NodeJS.ReadableStream, socket);
}).listen(0);
}).listen(pipePath);
}

// make VS Code connect to debug server
return new vscode.DebugAdapterServer((this.server.address() as Net.AddressInfo).port);
return new vscode.DebugAdapterNamedPipeServer(this.server.address() as string);
}

dispose(): void {
Expand Down Expand Up @@ -106,7 +113,9 @@ export function activateMQueryDebug(vscExtCtx: vscode.ExtensionContext, mode: "i
);

const factory: vscode.DebugAdapterDescriptorFactory =
mode === "server" ? new MQueryNodeDebugAdapterServerDescriptorFactory() : new InlineDebugAdapterFactory();
mode === "server"
? new MQueryNodeDebugAdapterNamedPipeServerDescriptorFactory()
: new InlineDebugAdapterFactory();

vscExtCtx.subscriptions.push(
vscode.debug.registerDebugAdapterDescriptorFactory(ExtensionConstants.PQDebugType, factory),
Expand Down