提交 3ae62a8d 编写于 作者: I isidor

debug: introduce map for sources, remove reference from source uri in workbench

上级 3338bf2f
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import * as lifecycle from 'vs/base/common/lifecycle'; import * as lifecycle from 'vs/base/common/lifecycle';
import uri from 'vs/base/common/uri'; import uri from 'vs/base/common/uri';
import * as paths from 'vs/base/common/paths';
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { guessMimeTypes, MIME_TEXT } from 'vs/base/common/mime'; import { guessMimeTypes, MIME_TEXT } from 'vs/base/common/mime';
...@@ -14,7 +15,6 @@ import { IModeService } from 'vs/editor/common/services/modeService'; ...@@ -14,7 +15,6 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import { ITextModelResolverService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService'; import { ITextModelResolverService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { DEBUG_SCHEME, IDebugService, State } from 'vs/workbench/parts/debug/common/debug'; import { DEBUG_SCHEME, IDebugService, State } from 'vs/workbench/parts/debug/common/debug';
import { Source } from 'vs/workbench/parts/debug/common/debugSource';
export class DebugContentProvider implements IWorkbenchContribution, ITextModelContentProvider { export class DebugContentProvider implements IWorkbenchContribution, ITextModelContentProvider {
...@@ -45,8 +45,10 @@ export class DebugContentProvider implements IWorkbenchContribution, ITextModelC ...@@ -45,8 +45,10 @@ export class DebugContentProvider implements IWorkbenchContribution, ITextModelC
if (!process) { if (!process) {
return TPromise.wrapError(localize('unable', "Unable to resolve the resource without a debug session")); return TPromise.wrapError(localize('unable', "Unable to resolve the resource without a debug session"));
} }
const source = process.sources.get(resource);
const rawSource = source ? source.raw : { path: paths.normalize(resource.fsPath, true) };
return process.session.source({ sourceReference: Source.getSourceReference(resource) }).then(response => { return process.session.source({ sourceReference: source ? source.reference : undefined, source: rawSource }).then(response => {
const mime = response.body.mimeType || guessMimeTypes(resource.toString())[0]; const mime = response.body.mimeType || guessMimeTypes(resource.toString())[0];
const modePromise = this.modeService.getOrCreateMode(mime); const modePromise = this.modeService.getOrCreateMode(mime);
const model = this.modelService.createModel(response.body.content, modePromise, resource); const model = this.modelService.createModel(response.body.content, modePromise, resource);
......
...@@ -102,6 +102,7 @@ export interface IProcess extends ITreeElement { ...@@ -102,6 +102,7 @@ export interface IProcess extends ITreeElement {
name: string; name: string;
configuration: IConfig; configuration: IConfig;
session: ISession; session: ISession;
sources: Map<uri, Source>;
isAttach(): boolean; isAttach(): boolean;
getThread(threadId: number): IThread; getThread(threadId: number): IThread;
getAllThreads(): IThread[]; getAllThreads(): IThread[];
......
...@@ -448,8 +448,10 @@ export class Thread implements debug.IThread { ...@@ -448,8 +448,10 @@ export class Thread implements debug.IThread {
if (!rsf) { if (!rsf) {
return new StackFrame(this, 0, new Source({ name: UNKNOWN_SOURCE_LABEL }, true), nls.localize('unknownStack', "Unknown stack location"), null, null); return new StackFrame(this, 0, new Source({ name: UNKNOWN_SOURCE_LABEL }, true), nls.localize('unknownStack', "Unknown stack location"), null, null);
} }
const source = rsf.source ? new Source(rsf.source, rsf.source.presentationHint === 'deemphasize') : new Source({ name: UNKNOWN_SOURCE_LABEL }, true);
this.process.sources.set(source.uri, source);
return new StackFrame(this, rsf.id, rsf.source ? new Source(rsf.source, rsf.source.presentationHint === 'deemphasize') : new Source({ name: UNKNOWN_SOURCE_LABEL }, true), rsf.name, rsf.line, rsf.column); return new StackFrame(this, rsf.id, source, rsf.name, rsf.line, rsf.column);
}); });
}, (err: Error) => { }, (err: Error) => {
if (this.stoppedDetails) { if (this.stoppedDetails) {
...@@ -492,9 +494,11 @@ export class Thread implements debug.IThread { ...@@ -492,9 +494,11 @@ export class Thread implements debug.IThread {
export class Process implements debug.IProcess { export class Process implements debug.IProcess {
private threads: Map<number, Thread>; private threads: Map<number, Thread>;
public sources: Map<uri, Source>;
constructor(public configuration: debug.IConfig, private _session: debug.ISession & debug.ITreeElement) { constructor(public configuration: debug.IConfig, private _session: debug.ISession & debug.ITreeElement) {
this.threads = new Map<number, Thread>(); this.threads = new Map<number, Thread>();
this.sources = new Map<uri, Source>();
} }
public get session(): debug.ISession { public get session(): debug.ISession {
......
...@@ -12,7 +12,7 @@ export class Source { ...@@ -12,7 +12,7 @@ export class Source {
constructor(public raw: DebugProtocol.Source, public deemphasize: boolean) { constructor(public raw: DebugProtocol.Source, public deemphasize: boolean) {
const path = raw.path || raw.name; const path = raw.path || raw.name;
this.uri = raw.sourceReference > 0 ? uri.parse(`${DEBUG_SCHEME}:${path}?ref=${raw.sourceReference}`) : uri.file(path); this.uri = raw.sourceReference > 0 ? uri.parse(`${DEBUG_SCHEME}:${path}`) : uri.file(path);
} }
public get name() { public get name() {
...@@ -34,12 +34,4 @@ export class Source { ...@@ -34,12 +34,4 @@ export class Source {
public static isInMemory(uri: uri): boolean { public static isInMemory(uri: uri): boolean {
return uri.toString().indexOf(`${DEBUG_SCHEME}:`) === 0; return uri.toString().indexOf(`${DEBUG_SCHEME}:`) === 0;
} }
public static getSourceReference(uri: uri): number {
if (!Source.isInMemory(uri)) {
return 0;
}
return parseInt(uri.query.substr('ref='.length));
}
} }
...@@ -945,19 +945,8 @@ export class DebugService implements debug.IDebugService { ...@@ -945,19 +945,8 @@ export class DebugService implements debug.IDebugService {
const breakpointsToSend = distinct(this.model.getBreakpoints().filter(bp => this.model.areBreakpointsActivated() && bp.enabled && bp.uri.toString() === modelUri.toString()), const breakpointsToSend = distinct(this.model.getBreakpoints().filter(bp => this.model.areBreakpointsActivated() && bp.enabled && bp.uri.toString() === modelUri.toString()),
bp => bp.lineNumber.toString()); bp => bp.lineNumber.toString());
let rawSource: DebugProtocol.Source; const source = process.sources.get(modelUri);
for (let t of process.getAllThreads()) { const rawSource = source ? source.raw : { path: paths.normalize(modelUri.fsPath, true) };
const callStack = t.getCallStack();
if (callStack) {
for (let sf of callStack) {
if (sf.source.uri.toString() === modelUri.toString()) {
rawSource = sf.source.raw;
break;
}
}
}
}
rawSource = rawSource || { path: paths.normalize(modelUri.fsPath, true), name: paths.basename(modelUri.fsPath) };
return session.setBreakpoints({ return session.setBreakpoints({
source: rawSource, source: rawSource,
......
...@@ -22,7 +22,6 @@ suite('Debug - Source', () => { ...@@ -22,7 +22,6 @@ suite('Debug - Source', () => {
assert.equal(source.inMemory, false); assert.equal(source.inMemory, false);
assert.equal(source.reference, rawSource.sourceReference); assert.equal(source.reference, rawSource.sourceReference);
assert.equal(source.uri.toString(), uri.file(rawSource.path).toString()); assert.equal(source.uri.toString(), uri.file(rawSource.path).toString());
assert.equal(Source.getSourceReference(source.uri), 0);
}); });
test('from raw internal source', () => { test('from raw internal source', () => {
...@@ -36,6 +35,5 @@ suite('Debug - Source', () => { ...@@ -36,6 +35,5 @@ suite('Debug - Source', () => {
assert.equal(source.name, rawSource.name); assert.equal(source.name, rawSource.name);
assert.equal(source.inMemory, true); assert.equal(source.inMemory, true);
assert.equal(source.reference, rawSource.sourceReference); assert.equal(source.reference, rawSource.sourceReference);
assert.equal(Source.getSourceReference(source.uri), 11);
}); });
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册