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

Commit

Permalink
Fix #141, sourcemap scope locations
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Dec 7, 2016
1 parent 956244f commit c432c5f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,10 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {

public scopes(args: DebugProtocol.ScopesArguments): IScopesResponseBody {
const currentFrame = this._frameHandles.get(args.frameId);
const currentScript = this._scriptsById.get(currentFrame.location.scriptId);
const currentScriptUrl = currentScript && currentScript.url;
const currentScriptPath = currentScriptUrl && this._pathTransformer.getClientPathFromTargetPath(currentScriptUrl);

const scopes = currentFrame.scopeChain.map((scope: Crdp.Debugger.Scope, i: number) => {
// The first scope should include 'this'. Keep the RemoteObject reference for use by the variables request
const thisObj = i === 0 && currentFrame.this;
Expand Down Expand Up @@ -955,7 +959,13 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
});
}

return { scopes };
const scopesResponse = { scopes };
if (currentScriptPath) {
this._sourceMapTransformer.scopesResponse(currentScriptPath, scopesResponse);
this._lineColTransformer.scopeResponse(scopesResponse);
}

return scopesResponse;
}

public variables(args: DebugProtocol.VariablesArguments): Promise<IVariablesResponseBody> {
Expand Down Expand Up @@ -1216,7 +1226,6 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {

return result + mappedSourcesStr;
});

}

/**
Expand Down
27 changes: 26 additions & 1 deletion src/transformers/baseSourceMapTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'path';
import {DebugProtocol} from 'vscode-debugprotocol';

import {ISetBreakpointsArgs, ILaunchRequestArgs, IAttachRequestArgs,
ISetBreakpointsResponseBody, IStackTraceResponseBody} from '../debugAdapterInterfaces';
ISetBreakpointsResponseBody, IStackTraceResponseBody, IScopesResponseBody} from '../debugAdapterInterfaces';
import {MappedPosition, ISourcePathDetails} from '../sourceMaps/sourceMap';
import {SourceMaps} from '../sourceMaps/sourceMaps';
import * as utils from '../utils';
Expand Down Expand Up @@ -236,6 +236,31 @@ export class BaseSourceMapTransformer {
}
}

public scopesResponse(pathToGenerated: string, scopesResponse: IScopesResponseBody): void {
if (this._sourceMaps) {
scopesResponse.scopes.forEach(scope => this.mapScopeLocations(pathToGenerated, scope));
}
}

private mapScopeLocations(pathToGenerated: string, scope: DebugProtocol.Scope): void {
if (typeof scope.line !== 'number') {
return;
}

const mappedStart = this._sourceMaps.mapToAuthored(pathToGenerated, scope.line, scope.column);
if (mappedStart) {
// Only apply changes if both mappings are found
const mappedEnd = this._sourceMaps.mapToAuthored(pathToGenerated, scope.endLine, scope.endColumn);
if (mappedEnd) {
scope.line = mappedStart.line;
scope.column = mappedStart.column;

scope.endLine = mappedEnd.line;
scope.endColumn = mappedEnd.column;
}
}
}

public mapToGenerated(authoredPath: string, line: number, column: number): Promise<MappedPosition> {
return this._preLoad.then(() => this._sourceMaps.mapToGenerated(authoredPath, line, column));
}
Expand Down
27 changes: 24 additions & 3 deletions src/transformers/lineNumberTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {DebugProtocol} from 'vscode-debugprotocol';

import {ChromeDebugSession} from '../chrome/chromeDebugSession';
import {IDebugTransformer, ISetBreakpointsResponseBody, IStackTraceResponseBody} from '../debugAdapterInterfaces';
import {IDebugTransformer, ISetBreakpointsResponseBody, IStackTraceResponseBody, IScopesResponseBody} from '../debugAdapterInterfaces';

/**
* Converts from 1 based lines/cols on the client side to 0 based lines/cols on the target side
Expand All @@ -30,15 +30,36 @@ export class LineColTransformer implements IDebugTransformer {
this.convertDebuggerLocationToClient(bp);
}

public scopeResponse(scopeResponse: IScopesResponseBody): void {
scopeResponse.scopes.forEach(scope => this.mapScopeLocations(scope));
}

private mapScopeLocations(scope: DebugProtocol.Scope): void {
this.convertDebuggerLocationToClient(scope);

if (typeof scope.endLine === 'number') {
const endScope = { line: scope.endLine, column: scope.endColumn };
this.convertDebuggerLocationToClient(endScope);
scope.endLine = endScope.line;
scope.endColumn = endScope.column;
}
}

private convertClientLocationToDebugger(location: { line?: number; column?: number }): void {
location.line = this.convertClientLineToDebugger(location.line);
if (typeof location.line === 'number') {
location.line = this.convertClientLineToDebugger(location.line);
}

if (typeof location.column === 'number') {
location.column = this.convertClientColumnToDebugger(location.column);
}
}

private convertDebuggerLocationToClient(location: { line?: number; column?: number }): void {
location.line = this.convertDebuggerLineToClient(location.line);
if (typeof location.line === 'number') {
location.line = this.convertDebuggerLineToClient(location.line);
}

if (typeof location.column === 'number') {
location.column = this.convertDebuggerColumnToClient(location.column);
}
Expand Down

0 comments on commit c432c5f

Please sign in to comment.