Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make attachment to debugger configurable #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ npm-debug.log
yarn.*
[Bb]in/
[Oo]bj/
lcov.info
lcov.info
.vscode-test
*.vsix
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"icon": "testexplorer_dark.png",
"engines": {
"vscode": "^1.25.1"
"vscode": "^1.45.1"
},
"categories": [
"Programming Languages"
Expand Down Expand Up @@ -253,6 +253,16 @@
"default": "",
"description": "Additional arguments that are added to the dotnet test command."
},
"dotnet-test-explorer.testhost.started.pattern": {
"type": "string",
"default": "Host debugging is enabled",
"description": "Pattern in stdout of testhost that triggers attachment of debugger"
},
"dotnet-test-explorer.testhost.processId.pattern": {
"type": "string",
"default": "Process Id: (\\d+),",
"description": "Pattern in stdout of testhost that matches its process id"
},
"dotnet-test-explorer.leftClickAction": {
"type": "string",
"default": "gotoTest",
Expand Down
9 changes: 4 additions & 5 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as vscode from "vscode";
import { TestCommands } from "./testCommands";
import { ITestResult, TestResult } from "./testResult";
import { Utility } from "./utility";

export interface IDebugRunnerInfo {
Expand All @@ -12,16 +10,17 @@ export interface IDebugRunnerInfo {
}

export class Debug {
private processIdRegexp = /Process Id: (.*),/gm;
private processIdRegexp = new RegExp(Utility.testhostProcessIdPattern, 'mi');
private debuggingEnabledRegexp = new RegExp(Utility.testhostStartedPattern, 'mi');

public onData(data: string, debugRunnerInfo?: IDebugRunnerInfo): IDebugRunnerInfo {

if (!debugRunnerInfo) {
debugRunnerInfo = {isRunning: false, isSettingUp: true, waitingForAttach: false, processId: ""};
}

if (!debugRunnerInfo.waitingForAttach) {
debugRunnerInfo.waitingForAttach = data.indexOf("Waiting for debugger attach...") > -1;
if (!debugRunnerInfo.waitingForAttach && this.debuggingEnabledRegexp.test(data)) {
debugRunnerInfo.waitingForAttach = true;
}

if (debugRunnerInfo.processId.length <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Executor {

if (this.debugRunnerInfo.config) {

Logger.Log(`Debugger process found, attaching`);
Logger.Log(`Debugger process found (pid: ${this.debugRunnerInfo.processId}), attaching`);

this.debugRunnerInfo.isRunning = true;

Expand Down
10 changes: 10 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export class Utility {
return (testArguments && testArguments.length > 0) ? ` ${testArguments}` : "";
}

public static get testhostStartedPattern(): string {
const pattern = Utility.getConfiguration().get<string>("testhost.started.pattern");
return (pattern && pattern.length > 0) ? pattern : "Host debugging is enabled";
}

public static get testhostProcessIdPattern(): string {
const pattern = Utility.getConfiguration().get<string>("testhost.processId.pattern");
return (pattern && pattern.length > 0) ? pattern : "Process Id: (\d+),";
}

public static getConfiguration(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration("dotnet-test-explorer");
}
Expand Down
6 changes: 3 additions & 3 deletions test/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ suite("Debug tests", () => {
assert.equal(results.isSettingUp, true);
});

test("Detects that debug is ready for attach har started", () => {
test("Detects that debug is ready for attach has started", () => {
const debug = new Debug();

let results = debug.onData("data");
results = debug.onData(`
This is output from vstest
Waiting for debugger attach...
Host debugging is enabled
Tra la lalala la
`, results);

Expand Down Expand Up @@ -44,7 +44,7 @@ suite("Debug tests", () => {

results = debug.onData(`
This is output from vstest
Waiting for debugger attach...
Host debugging is enabled
Tra la lalala la
`, results);

Expand Down