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

Commit

Permalink
Show loaded scripts: Fix #182
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Mar 10, 2017
1 parent a96399b commit 417eaac
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"noice-json-rpc": "^1.0.0",
"request-light": "^0.1.0",
"source-map": "^0.5.6",
"vscode-debugadapter": "^1.18.0-pre.1",
"vscode-debugprotocol": "^1.17.0-pre.2",
"vscode-debugadapter": "^1.18.0-pre.3",
"vscode-debugprotocol": "^1.18.0-pre.1",
"ws": "^1.1.1"
},
"devDependencies": {
Expand Down
56 changes: 46 additions & 10 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {StoppedEvent, InitializedEvent, TerminatedEvent, Handles, ContinuedEvent
import {ICommonRequestArgs, ILaunchRequestArgs, ISetBreakpointsArgs, ISetBreakpointsResponseBody, IStackTraceResponseBody,
IAttachRequestArgs, IScopesResponseBody, IVariablesResponseBody,
ISourceResponseBody, IThreadsResponseBody, IEvaluateResponseBody, ISetVariableResponseBody, IDebugAdapter,
ICompletionsResponseBody, IToggleSkipFileStatusArgs, IInternalStackTraceResponseBody} from '../debugAdapterInterfaces';
ICompletionsResponseBody, IToggleSkipFileStatusArgs, IInternalStackTraceResponseBody, ILoadedScript, IAllLoadedScriptsResponseBody} from '../debugAdapterInterfaces';
import {IChromeDebugAdapterOpts, ChromeDebugSession} from './chromeDebugSession';
import {ChromeConnection} from './chromeConnection';
import * as ChromeUtils from './chromeUtils';
Expand Down Expand Up @@ -691,6 +691,26 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
}).catch(() => this.warnNoSkipFiles());
}

public async getLoadScripts(): Promise<IAllLoadedScriptsResponseBody> {
const loadedScripts = Array.from(this._scriptsByUrl.keys())
.map(scriptPath => {
const basename = path.basename(scriptPath);
const script = this._scriptsByUrl.get(scriptPath);
return <ILoadedScript>{
label: basename,
description: scriptPath === basename ? '' : scriptPath,
source: {
name: basename,
path: scriptPath,
sourceReference: this.getSourceReferenceForScriptId(script.scriptId)
}
};
})
.sort((a, b) => a.label.localeCompare(b.label));

return { loadedScripts };
}

private resolvePendingBreakpoint(pendingBP: IPendingBreakpoint): Promise<void> {
return this.setBreakpoints(pendingBP.args, pendingBP.requestSeq, pendingBP.ids).then(response => {
response.breakpoints.forEach((bp, i) => {
Expand Down Expand Up @@ -1418,20 +1438,36 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
}

public source(args: DebugProtocol.SourceArguments): Promise<ISourceResponseBody> {
const handle = this._sourceHandles.get(args.sourceReference);
if (!handle) {
return Promise.reject(errors.sourceRequestIllegalHandle());
let scriptId: Crdp.Runtime.ScriptId;
if (args.sourceReference) {
const handle = this._sourceHandles.get(args.sourceReference);
if (!handle) {
return Promise.reject(errors.sourceRequestIllegalHandle());
}

// Have inlined content?
if (handle.contents) {
return Promise.resolve({
content: handle.contents
});
}

scriptId = handle.scriptId;
} else if (args.source && args.source.path) {
const script = this._scriptsByUrl.get(args.source.path);
if (!script) {
return Promise.reject(errors.sourceRequestCouldNotRetrieveContent());
}

scriptId = script.scriptId;
}

// Have inlined content?
if (handle.contents) {
return Promise.resolve({
content: handle.contents
});
if (!scriptId) {
return Promise.reject(errors.sourceRequestCouldNotRetrieveContent());
}

// If not, should have scriptId
return this.chrome.Debugger.getScriptSource({ scriptId: handle.scriptId }).then(response => {
return this.chrome.Debugger.getScriptSource({ scriptId }).then(response => {
return {
content: response.scriptSource,
mimeType: 'text/javascript'
Expand Down
10 changes: 10 additions & 0 deletions src/debugAdapterInterfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ export interface ICompletionsResponseBody {
targets: DebugProtocol.CompletionItem[];
}

export interface ILoadedScript {
label: string;
description: string;
source: DebugProtocol.Source;
}

export interface IAllLoadedScriptsResponseBody {
loadedScripts: ILoadedScript[];
}

declare type PromiseOrNot<T> = T | Promise<T>;

/**
Expand Down
7 changes: 7 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export function sourceRequestIllegalHandle(): DebugProtocol.Message {
};
}

export function sourceRequestCouldNotRetrieveContent(): DebugProtocol.Message {
return {
id: 2026,
format: localize('source.not.found', "Could not retrieve content.")
};
}

export function pathFormat(): DebugProtocol.Message {
return {
id: 2018,
Expand Down

0 comments on commit 417eaac

Please sign in to comment.