Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Fix #144 - basic cut of column BPs
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Apr 18, 2017
1 parent 5bf8ad6 commit 3494471
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
57 changes: 34 additions & 23 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
const setBreakpointsPFailOnError = this._setBreakpointsRequestQ
.then(() => this.clearAllBreakpoints(targetScriptUrl))
.then(() => this.addBreakpoints(targetScriptUrl, args.breakpoints))
.then(responses => ({ breakpoints: this.chromeBreakpointResponsesToODPBreakpoints(targetScriptUrl, responses, args.breakpoints, ids) }));
.then(responses => ({ breakpoints: this.targetBreakpointResponsesToClientBreakpoints(targetScriptUrl, responses, args.breakpoints, ids) }));

const setBreakpointsPTimeout = utils.promiseTimeout(setBreakpointsPFailOnError, ChromeDebugAdapter.SET_BREAKPOINTS_TIMEOUT, localize('setBPTimedOut', "Set breakpoints request timed out"));

Expand Down Expand Up @@ -963,30 +963,48 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
const script = this.getScriptByUrl(url);
const urlRegex = utils.pathToRegex(url);
responsePs = breakpoints.map(({ line, column = 0, condition }, i) => {
return this.chrome.Debugger.setBreakpointByUrl({ urlRegex, lineNumber: line, columnNumber: column, condition }).then(result => {
// Now convert the response to a SetBreakpointResponse so both response types can be handled the same
const locations = result.locations;
return <Crdp.Debugger.SetBreakpointResponse>{
breakpointId: result.breakpointId,
actualLocation: locations[0] && {
lineNumber: locations[0].lineNumber,
columnNumber: locations[0].columnNumber,
scriptId: script.scriptId
}
};
},
err => ({})); // Ignore errors, return an empty object
return this.addOneBreakpointByUrl(script.scriptId, urlRegex, line, column, condition)
.catch(() => null);
});
}

// Join all setBreakpoint requests to a single promise
return Promise.all(responsePs);
}

private chromeBreakpointResponsesToODPBreakpoints(url: string, responses: Crdp.Debugger.SetBreakpointResponse[], requestBps: DebugProtocol.SourceBreakpoint[], ids?: number[]): DebugProtocol.Breakpoint[] {
private async addOneBreakpointByUrl(scriptId: Crdp.Runtime.ScriptId, urlRegex: string, lineNumber: number, columnNumber: number, condition: string): Promise<Crdp.Debugger.SetBreakpointResponse> {
let bpLocation = { lineNumber, columnNumber };
try {
const possibleBpResponse = await this.chrome.Debugger.getPossibleBreakpoints({
start: { scriptId: scriptId, lineNumber: lineNumber, columnNumber: 0 },
end: { scriptId: scriptId, lineNumber: lineNumber + 1, columnNumber: 0 },
restrictToFunction: false });
if (possibleBpResponse.locations.length) {
const selectedLocation = ChromeUtils.selectBreakpointLocation(lineNumber, columnNumber, possibleBpResponse.locations);
bpLocation = { lineNumber: selectedLocation.lineNumber, columnNumber: selectedLocation.columnNumber || 0 };
}
} catch (e) {
// getPossibleBPs not supported
}

const result = await this.chrome.Debugger.setBreakpointByUrl({ urlRegex, lineNumber: bpLocation.lineNumber, columnNumber: bpLocation.columnNumber, condition });

// Now convert the response to a SetBreakpointResponse so both response types can be handled the same
const locations = result.locations;
return <Crdp.Debugger.SetBreakpointResponse>{
breakpointId: result.breakpointId,
actualLocation: locations[0] && {
lineNumber: locations[0].lineNumber,
columnNumber: locations[0].columnNumber,
scriptId
}
};
}

private targetBreakpointResponsesToClientBreakpoints(url: string, responses: Crdp.Debugger.SetBreakpointResponse[], requestBps: DebugProtocol.SourceBreakpoint[], ids?: number[]): DebugProtocol.Breakpoint[] {
// Don't cache errored responses
const committedBpIds = responses
.filter(response => !!response.breakpointId)
.filter(response => response)
.map(response => response.breakpointId);

// Cache successfully set breakpoint ids from chrome in committedBreakpoints set
Expand All @@ -1012,13 +1030,6 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
this._breakpointIdHandles.create(response.breakpointId);
}

if (!response.actualLocation) {
return <DebugProtocol.Breakpoint>{
id: bpId,
verified: false
};
}

const thisBpRequest = requestBps[i];
if (thisBpRequest.hitCondition) {
if (!this.addHitConditionBreakpoint(thisBpRequest, response)) {
Expand Down
10 changes: 10 additions & 0 deletions src/chrome/chromeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,13 @@ export function getEvaluateName(parentEvaluateName: string, name: string): strin

return parentEvaluateName + nameAccessor;
}

export function selectBreakpointLocation(lineNumber: number, columnNumber: number, locations: Crdp.Debugger.BreakLocation[]): Crdp.Debugger.BreakLocation {
for (let i = locations.length - 1; i >= 0; i--) {
if (locations[i].columnNumber < columnNumber) {
return locations[i];
}
}

return locations[0];
}
2 changes: 0 additions & 2 deletions src/debugAdapterInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export interface IToggleSkipFileStatusArgs {
}

export interface ISetBreakpointsArgs extends DebugProtocol.SetBreakpointsArguments {
/** DebugProtocol does not send cols, maybe it will someday, but this is used internally when a location is sourcemapped */
cols?: number[];
authoredPath?: string;
}

Expand Down
3 changes: 0 additions & 3 deletions src/transformers/lineNumberTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ export class LineColTransformer implements IDebugTransformer {

public setBreakpoints(args: DebugProtocol.SetBreakpointsArguments): void {
args.breakpoints.forEach(bp => this.convertClientLocationToDebugger(bp));
args.breakpoints.forEach(bp => bp.column = undefined);
}

public setBreakpointsResponse(response: ISetBreakpointsResponseBody): void {
response.breakpoints.forEach(bp => this.convertDebuggerLocationToClient(bp));
response.breakpoints.forEach(bp => bp.column = undefined);
}

public stackTraceResponse(response: IStackTraceResponseBody): void {
Expand All @@ -30,7 +28,6 @@ export class LineColTransformer implements IDebugTransformer {

public breakpointResolved(bp: DebugProtocol.Breakpoint): void {
this.convertDebuggerLocationToClient(bp);
bp.column = undefined;
}

public scopeResponse(scopeResponse: IScopesResponseBody): void {
Expand Down

0 comments on commit 3494471

Please sign in to comment.