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

Test debug API for adding removing breakpoints #42321

Closed
1 task done
weinand opened this issue Jan 29, 2018 · 0 comments
Closed
1 task done

Test debug API for adding removing breakpoints #42321

weinand opened this issue Jan 29, 2018 · 0 comments
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues testplan-item
Milestone

Comments

@weinand
Copy link
Contributor

weinand commented Jan 29, 2018

Test for #42173:

Complexity: 3

In the last milestone we've added API to make the set of breakpoints registered with VS Code available to extensions. In this milestone we've added more API for adding and removing breakpoints programmatically.

Here is the new API (available only in vscode.proposed.d.ts):

export namespace debug {

	/**
	 * Add breakpoints.
	 * @param breakpoints The breakpoints to add.
	*/
	export function addBreakpoints(breakpoints: Breakpoint[]): void;

	/**
	 * Remove breakpoints.
	 * @param breakpoints The breakpoints to remove.
	 */
	export function removeBreakpoints(breakpoints: Breakpoint[]): void;
}

/**
 * A breakpoint specified by a source location.
 */
export class SourceBreakpoint extends Breakpoint {

	//...

	/**
	 * Create a new breakpoint for a source location.
	 */
	constructor(location: Location, enabled?: boolean, condition?: string, hitCondition?: string);
}

/**
 * A breakpoint specified by a function name.
 */
export class FunctionBreakpoint extends Breakpoint {

	//...

	/**
	 * Create a new function breakpoint.
	 */
	constructor(functionName: string, enabled?: boolean, condition?: string, hitCondition?: string);
}

Verify that this API works as expected.

Here is some starter code that adds two context menu actions for adding and removing breakpoints for multiple lines:

'use strict';

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

	vscode.debug.onDidChangeBreakpoints(e => {
		console.log(`Event: a: ${e.added.length} r: ${e.removed.length} c: ${e.changed.length}`);
		/*
		if (e.added.length) console.log('added: ', JSON.stringify(e.added));
		if (e.removed.length) console.log('removed: ', JSON.stringify(e.removed));
		if (e.changed.length) console.log('changed: ', JSON.stringify(e.changed));
		console.log('breakpoints after event: ', JSON.stringify(vscode.debug.breakpoints));
		*/
	});

	context.subscriptions.push(vscode.commands.registerCommand('extension.addBreakpoint', () => {

		let editor = vscode.window.activeTextEditor;
		if (editor) {
			let document = editor.document;
			let selections = editor.selections;

			const column = selections[0].end.character;
			const bps: vscode.Breakpoint[] = [];
			for (let line = selections[0].start.line; line <= selections[0].end.line; line++) {
				bps.push(new vscode.SourceBreakpoint(new vscode.Location(document.uri, new vscode.Position(line, column))));
			}

			vscode.debug.addBreakpoints(bps);
		} else {
			vscode.window.showInformationMessage('Open a file first to manipulate text selections');
		}
	}));

context.subscriptions.push(vscode.commands.registerCommand('extension.removeBreakpoint', () => {

		let editor = vscode.window.activeTextEditor;
		if (editor) {

			let document = editor.document;
			let selection = editor.selections[0];

			const found = vscode.debug.breakpoints.filter(bp => {
				if (bp instanceof vscode.SourceBreakpoint) {
					const bpline = bp.location.range.start.line;
					return bp.location.uri.toString() === document.uri.toString()
						&& bpline >= selection.start.line && bpline <= selection.end.line;
				}
				return false;
			});

			vscode.debug.removeBreakpoints(found);
		} else {
			vscode.window.showInformationMessage('Open a file first to manipulate text selections');
		}
	}));
}

export function deactivate() {
}

and the corresponding sections from the package.json:

	"enableProposedApi": true,
	"activationEvents": [
		"onCommand:extension.addBreakpoint",
		"onCommand:extension.removeBreakpoint"
	],
	"contributes": {
		"menus": {
			"editor/context": [
				{
					"command": "extension.addBreakpoint",
					"group": "extension"
				},
				{
					"command": "extension.removeBreakpoint",
					"group": "extension"
				}
			]
		},
		"commands": [
			{
				"command": "extension.addBreakpoint",
				"title": "Add Breakpoint"
			},
			{
				"command": "extension.removeBreakpoint",
				"title": "Remove Breakpoint"
			}
		]
	},
@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues testplan-item labels Jan 29, 2018
@weinand weinand added this to the January 2018 milestone Jan 29, 2018
@weinand weinand assigned weinand and jrieken and unassigned weinand Jan 29, 2018
@jrieken jrieken removed their assignment Jan 30, 2018
@jrieken jrieken closed this as completed Jan 30, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues testplan-item
Projects
None yet
Development

No branches or pull requests

2 participants