diff --git a/src/vs/workbench/parts/debug/browser/debugActions.ts b/src/vs/workbench/parts/debug/browser/debugActions.ts index 04fd4058642849c3a89c905da3e5d4de2c76cac4..6191db0921cccbe809f82ad1bec41d222a904f1d 100644 --- a/src/vs/workbench/parts/debug/browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/browser/debugActions.ts @@ -14,7 +14,7 @@ import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/ import { IFileService } from 'vs/platform/files/common/files'; import { IDebugService, State, ISession, IThread, IEnablement, IBreakpoint, IStackFrame, REPL_ID, SessionState } from 'vs/workbench/parts/debug/common/debug'; -import { Variable, Expression, Thread, Breakpoint, Session } from 'vs/workbench/parts/debug/common/debugModel'; +import { Variable, Expression, Thread, Breakpoint } from 'vs/workbench/parts/debug/common/debugModel'; import { IPartService } from 'vs/workbench/services/part/common/partService'; import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -230,7 +230,7 @@ export class RestartAction extends AbstractDebugAction { } public run(session: ISession): TPromise { - if (!(session instanceof Session)) { + if (!session || !session.getId) { session = this.debugService.getViewModel().focusedSession; } @@ -325,7 +325,7 @@ export class StopAction extends AbstractDebugAction { } public run(session: ISession): TPromise { - if (!(session instanceof Session)) { + if (!session || !session.getId) { session = this.debugService.getViewModel().focusedSession; } diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index 6af33b36e60bc4ed9fd12760518ea3ad7586a202..d527aef5481db4a83d3113bef74d502e859ac509 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -146,16 +146,20 @@ export enum SessionState { } export interface ISession extends ITreeElement { - getName(includeRoot: boolean): string; readonly configuration: IConfig; readonly raw: IRawSession; readonly state: SessionState; + + getName(includeRoot: boolean): string; getSourceForUri(modelUri: uri): Source; getThread(threadId: number): IThread; getAllThreads(): ReadonlyArray; getSource(raw: DebugProtocol.Source): Source; getLoadedSources(): TPromise; completions(frameId: number, text: string, position: Position, overwriteBefore: number): TPromise; + clearThreads(removeThreads: boolean, reference?: number): void; + + rawUpdate(data: IRawModelUpdate): void; } export interface IThread extends ITreeElement { diff --git a/src/vs/workbench/parts/debug/common/debugModel.ts b/src/vs/workbench/parts/debug/common/debugModel.ts index 3a58268ec72266a669641d6f7022f0816eff2d1e..6b8a4ef7cff1f40245ccce2b8ed7abc1a18452d6 100644 --- a/src/vs/workbench/parts/debug/common/debugModel.ts +++ b/src/vs/workbench/parts/debug/common/debugModel.ts @@ -16,14 +16,11 @@ import severity from 'vs/base/common/severity'; import { isObject, isString, isUndefinedOrNull } from 'vs/base/common/types'; import { distinct } from 'vs/base/common/arrays'; import { Range, IRange } from 'vs/editor/common/core/range'; -import { ISuggestion } from 'vs/editor/common/modes'; -import { Position } from 'vs/editor/common/core/position'; import { ITreeElement, IExpression, IExpressionContainer, ISession, IStackFrame, IExceptionBreakpoint, IBreakpoint, IFunctionBreakpoint, IModel, IReplElementSource, - IConfig, IRawSession, IThread, IRawModelUpdate, IScope, IRawStoppedDetails, IEnablement, IBreakpointData, IExceptionInfo, IReplElement, SessionState, IBreakpointsChangeEvent, IBreakpointUpdateData, IBaseBreakpoint + IThread, IRawModelUpdate, IScope, IRawStoppedDetails, IEnablement, IBreakpointData, IExceptionInfo, IReplElement, IBreakpointsChangeEvent, IBreakpointUpdateData, IBaseBreakpoint } from 'vs/workbench/parts/debug/common/debug'; import { Source } from 'vs/workbench/parts/debug/common/debugSource'; -import { mixin } from 'vs/base/common/objects'; import { commonSuffixLength } from 'vs/base/common/strings'; import { sep } from 'vs/base/common/paths'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -552,175 +549,6 @@ export class Thread implements IThread { } } -export class Session implements ISession { - - private sources: Map; - private threads: Map; - - constructor(private _configuration: { resolved: IConfig, unresolved: IConfig }, private session: IRawSession & ITreeElement) { - this.threads = new Map(); - this.sources = new Map(); - } - - public get configuration(): IConfig { - return this._configuration.resolved; - } - - public get unresolvedConfiguration(): IConfig { - return this._configuration.unresolved; - } - - public get raw(): IRawSession & ITreeElement { - return this.session; - } - - public set raw(value: IRawSession & ITreeElement) { - this.session = value; - } - - public getName(includeRoot: boolean): string { - return includeRoot && this.raw.root ? `${this.configuration.name} (${resources.basenameOrAuthority(this.raw.root.uri)})` : this.configuration.name; - } - - public get state(): SessionState { - return this.configuration.type === 'attach' ? SessionState.ATTACH : SessionState.LAUNCH; - } - - public getSourceForUri(modelUri: uri): Source { - return this.sources.get(modelUri.toString()); - } - - public getSource(raw: DebugProtocol.Source): Source { - let source = new Source(raw, this.getId()); - if (this.sources.has(source.uri.toString())) { - source = this.sources.get(source.uri.toString()); - source.raw = mixin(source.raw, raw); - if (source.raw && raw) { - // Always take the latest presentation hint from adapter #42139 - source.raw.presentationHint = raw.presentationHint; - } - } else { - this.sources.set(source.uri.toString(), source); - } - - return source; - } - - public getThread(threadId: number): Thread { - return this.threads.get(threadId); - } - - public getAllThreads(): IThread[] { - const result: IThread[] = []; - this.threads.forEach(t => result.push(t)); - return result; - } - - public getLoadedSources(): TPromise { - return this.raw.loadedSources({}).then(response => { - return response.body.sources.map(src => this.getSource(src)); - }, error => { - return []; - }); - } - - public getId(): string { - return this.session.getId(); - } - - public rawUpdate(data: IRawModelUpdate): void { - - if (data.thread && !this.threads.has(data.threadId)) { - // A new thread came in, initialize it. - this.threads.set(data.threadId, new Thread(this, data.thread.name, data.thread.id)); - } else if (data.thread && data.thread.name) { - // Just the thread name got updated #18244 - this.threads.get(data.threadId).name = data.thread.name; - } - - if (data.stoppedDetails) { - // Set the availability of the threads' callstacks depending on - // whether the thread is stopped or not - if (data.stoppedDetails.allThreadsStopped) { - this.threads.forEach(thread => { - thread.stoppedDetails = thread.threadId === data.threadId ? data.stoppedDetails : { reason: undefined }; - thread.stopped = true; - thread.clearCallStack(); - }); - } else if (this.threads.has(data.threadId)) { - // One thread is stopped, only update that thread. - const thread = this.threads.get(data.threadId); - thread.stoppedDetails = data.stoppedDetails; - thread.clearCallStack(); - thread.stopped = true; - } - } - } - - public clearThreads(removeThreads: boolean, reference: number = undefined): void { - if (reference !== undefined && reference !== null) { - if (this.threads.has(reference)) { - const thread = this.threads.get(reference); - thread.clearCallStack(); - thread.stoppedDetails = undefined; - thread.stopped = false; - - if (removeThreads) { - this.threads.delete(reference); - } - } - } else { - this.threads.forEach(thread => { - thread.clearCallStack(); - thread.stoppedDetails = undefined; - thread.stopped = false; - }); - - if (removeThreads) { - this.threads.clear(); - ExpressionContainer.allValues.clear(); - } - } - } - - public completions(frameId: number, text: string, position: Position, overwriteBefore: number): TPromise { - if (!this.raw.capabilities.supportsCompletionsRequest) { - return TPromise.as([]); - } - - return this.raw.completions({ - frameId, - text, - column: position.column, - line: position.lineNumber - }).then(response => { - const result: ISuggestion[] = []; - if (response && response.body && response.body.targets) { - response.body.targets.forEach(item => { - if (item && item.label) { - result.push({ - label: item.label, - insertText: item.text || item.label, - type: item.type, - filterText: item.start && item.length && text.substr(item.start, item.length).concat(item.label), - overwriteBefore: item.length || overwriteBefore - }); - } - }); - } - - return result; - }, () => []); - } - - setNotAvailable(modelUri: uri) { - const source = this.sources.get(modelUri.toString()); - if (source) { - source.available = false; - } - } -} - export class Enablement implements IEnablement { constructor( public enabled: boolean, @@ -905,7 +733,7 @@ export class ThreadAndSessionIds implements ITreeElement { export class Model implements IModel { - private sessions: Session[]; + private sessions: ISession[]; private toDispose: lifecycle.IDisposable[]; private replElements: IReplElement[]; private schedulers = new Map(); @@ -935,15 +763,12 @@ export class Model implements IModel { return 'root'; } - public getSessions(): Session[] { + public getSessions(): ISession[] { return this.sessions; } - public addSession(configuration: { resolved: IConfig, unresolved: IConfig }, raw: IRawSession & ITreeElement): Session { - const session = new Session(configuration, raw); + public addSession(session: ISession): void { this.sessions.push(session); - - return session; } public removeSession(id: string): void { @@ -1277,7 +1102,7 @@ export class Model implements IModel { } public sourceIsNotAvailable(uri: uri): void { - this.sessions.forEach(p => p.setNotAvailable(uri)); + this.sessions.forEach(p => p.getSourceForUri(uri).available = false); this._onDidChangeCallStack.fire(); } diff --git a/src/vs/workbench/parts/debug/electron-browser/callStackView.ts b/src/vs/workbench/parts/debug/electron-browser/callStackView.ts index 64e48d2f6d91b5c00c285021e03a3098744ca52a..0298950898c5879e489c37e11d10a31f6e7a4033 100644 --- a/src/vs/workbench/parts/debug/electron-browser/callStackView.ts +++ b/src/vs/workbench/parts/debug/electron-browser/callStackView.ts @@ -10,7 +10,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import * as errors from 'vs/base/common/errors'; import { TreeViewsViewletPanel, IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet'; import { IDebugService, State, IStackFrame, ISession, IThread, CONTEXT_CALLSTACK_ITEM_TYPE } from 'vs/workbench/parts/debug/common/debug'; -import { Thread, StackFrame, ThreadAndSessionIds, Session, Model } from 'vs/workbench/parts/debug/common/debugModel'; +import { Thread, StackFrame, ThreadAndSessionIds, Model } from 'vs/workbench/parts/debug/common/debugModel'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { MenuId } from 'vs/platform/actions/common/actions'; @@ -28,6 +28,7 @@ import { Separator } from 'vs/base/browser/ui/actionbar/actionbar'; import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { IViewletPanelOptions } from 'vs/workbench/browser/parts/views/panelViewlet'; import { IUriLabelService } from 'vs/platform/uriLabel/common/uriLabel'; +import { Session } from 'vs/workbench/parts/debug/electron-browser/debugSession'; const $ = dom.$; diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index a5e2dcee7a0eb14bc388d84c6c7cac591067b1b2..73c6353846b1011dde0849c946e43cfa4535f645 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -28,7 +28,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import * as debug from 'vs/workbench/parts/debug/common/debug'; import { RawDebugSession } from 'vs/workbench/parts/debug/electron-browser/rawDebugSession'; -import { Model, ExceptionBreakpoint, FunctionBreakpoint, Breakpoint, Expression, RawObjectReplElement, ExpressionContainer, Session, Thread } from 'vs/workbench/parts/debug/common/debugModel'; +import { Model, ExceptionBreakpoint, FunctionBreakpoint, Breakpoint, Expression, RawObjectReplElement, ExpressionContainer, Thread } from 'vs/workbench/parts/debug/common/debugModel'; import { ViewModel } from 'vs/workbench/parts/debug/common/debugViewModel'; import * as debugactions from 'vs/workbench/parts/debug/browser/debugActions'; import { ConfigurationManager } from 'vs/workbench/parts/debug/electron-browser/debugConfigurationManager'; @@ -55,6 +55,7 @@ import { normalizeDriveLetter } from 'vs/base/common/labels'; import { RunOnceScheduler } from 'vs/base/common/async'; import product from 'vs/platform/node/product'; import { deepClone, equals } from 'vs/base/common/objects'; +import { Session } from 'vs/workbench/parts/debug/electron-browser/debugSession'; const DEBUG_BREAKPOINTS_KEY = 'debug.breakpoint'; const DEBUG_BREAKPOINTS_ACTIVATED_KEY = 'debug.breakpointactivated'; @@ -895,7 +896,8 @@ export class DebugService implements debug.IDebugService { const raw = this.instantiationService.createInstance(RawDebugSession, sessionId, configuration.resolved.debugServer, dbg, customTelemetryService, root); if (!session) { - session = this.model.addSession(configuration, raw); + session = new Session(configuration, raw); + this.model.addSession(session); this.allSessions.set(session.getId(), session); } else { session.raw = raw; diff --git a/src/vs/workbench/parts/debug/electron-browser/debugSession.ts b/src/vs/workbench/parts/debug/electron-browser/debugSession.ts new file mode 100644 index 0000000000000000000000000000000000000000..75170c002388f79943a287c6c34b8df6b29595ce --- /dev/null +++ b/src/vs/workbench/parts/debug/electron-browser/debugSession.ts @@ -0,0 +1,176 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import uri from 'vs/base/common/uri'; +import * as resources from 'vs/base/common/resources'; +import { TPromise } from 'vs/base/common/winjs.base'; +import { ISuggestion } from 'vs/editor/common/modes'; +import { Position } from 'vs/editor/common/core/position'; +import { ITreeElement, ISession, IConfig, IRawSession, IThread, IRawModelUpdate, SessionState } from 'vs/workbench/parts/debug/common/debug'; +import { Source } from 'vs/workbench/parts/debug/common/debugSource'; +import { mixin } from 'vs/base/common/objects'; +import { Thread, ExpressionContainer } from 'vs/workbench/parts/debug/common/debugModel'; + +export class Session implements ISession { + + private sources: Map; + private threads: Map; + + constructor(private _configuration: { resolved: IConfig, unresolved: IConfig }, private session: IRawSession & ITreeElement) { + this.threads = new Map(); + this.sources = new Map(); + } + + public get configuration(): IConfig { + return this._configuration.resolved; + } + + public get unresolvedConfiguration(): IConfig { + return this._configuration.unresolved; + } + + public get raw(): IRawSession & ITreeElement { + return this.session; + } + + public set raw(value: IRawSession & ITreeElement) { + this.session = value; + } + + public getName(includeRoot: boolean): string { + return includeRoot && this.raw.root ? `${this.configuration.name} (${resources.basenameOrAuthority(this.raw.root.uri)})` : this.configuration.name; + } + + public get state(): SessionState { + return this.configuration.type === 'attach' ? SessionState.ATTACH : SessionState.LAUNCH; + } + + public getSourceForUri(modelUri: uri): Source { + return this.sources.get(modelUri.toString()); + } + + public getSource(raw: DebugProtocol.Source): Source { + let source = new Source(raw, this.getId()); + if (this.sources.has(source.uri.toString())) { + source = this.sources.get(source.uri.toString()); + source.raw = mixin(source.raw, raw); + if (source.raw && raw) { + // Always take the latest presentation hint from adapter #42139 + source.raw.presentationHint = raw.presentationHint; + } + } else { + this.sources.set(source.uri.toString(), source); + } + + return source; + } + + public getThread(threadId: number): Thread { + return this.threads.get(threadId); + } + + public getAllThreads(): IThread[] { + const result: IThread[] = []; + this.threads.forEach(t => result.push(t)); + return result; + } + + public getLoadedSources(): TPromise { + return this.raw.loadedSources({}).then(response => { + return response.body.sources.map(src => this.getSource(src)); + }, error => { + return []; + }); + } + + public getId(): string { + return this.session.getId(); + } + + public rawUpdate(data: IRawModelUpdate): void { + + if (data.thread && !this.threads.has(data.threadId)) { + // A new thread came in, initialize it. + this.threads.set(data.threadId, new Thread(this, data.thread.name, data.thread.id)); + } else if (data.thread && data.thread.name) { + // Just the thread name got updated #18244 + this.threads.get(data.threadId).name = data.thread.name; + } + + if (data.stoppedDetails) { + // Set the availability of the threads' callstacks depending on + // whether the thread is stopped or not + if (data.stoppedDetails.allThreadsStopped) { + this.threads.forEach(thread => { + thread.stoppedDetails = thread.threadId === data.threadId ? data.stoppedDetails : { reason: undefined }; + thread.stopped = true; + thread.clearCallStack(); + }); + } else if (this.threads.has(data.threadId)) { + // One thread is stopped, only update that thread. + const thread = this.threads.get(data.threadId); + thread.stoppedDetails = data.stoppedDetails; + thread.clearCallStack(); + thread.stopped = true; + } + } + } + + public clearThreads(removeThreads: boolean, reference: number = undefined): void { + if (reference !== undefined && reference !== null) { + if (this.threads.has(reference)) { + const thread = this.threads.get(reference); + thread.clearCallStack(); + thread.stoppedDetails = undefined; + thread.stopped = false; + + if (removeThreads) { + this.threads.delete(reference); + } + } + } else { + this.threads.forEach(thread => { + thread.clearCallStack(); + thread.stoppedDetails = undefined; + thread.stopped = false; + }); + + if (removeThreads) { + this.threads.clear(); + ExpressionContainer.allValues.clear(); + } + } + } + + public completions(frameId: number, text: string, position: Position, overwriteBefore: number): TPromise { + if (!this.raw.capabilities.supportsCompletionsRequest) { + return TPromise.as([]); + } + + return this.raw.completions({ + frameId, + text, + column: position.column, + line: position.lineNumber + }).then(response => { + const result: ISuggestion[] = []; + if (response && response.body && response.body.targets) { + response.body.targets.forEach(item => { + if (item && item.label) { + result.push({ + label: item.label, + insertText: item.text || item.label, + type: item.type, + filterText: item.start && item.length && text.substr(item.start, item.length).concat(item.label), + overwriteBefore: item.length || overwriteBefore + }); + } + }); + } + + return result; + }, () => []); + } +} diff --git a/src/vs/workbench/parts/debug/test/browser/baseDebugView.test.ts b/src/vs/workbench/parts/debug/test/browser/baseDebugView.test.ts index d52a69598b8a1f5e08f5c7645782a20b0d481e25..837cb46a9b6db15561aaad682611abc3d086e59f 100644 --- a/src/vs/workbench/parts/debug/test/browser/baseDebugView.test.ts +++ b/src/vs/workbench/parts/debug/test/browser/baseDebugView.test.ts @@ -6,7 +6,7 @@ import * as assert from 'assert'; import { replaceWhitespace, renderExpressionValue, renderVariable } from 'vs/workbench/parts/debug/browser/baseDebugView'; import * as dom from 'vs/base/browser/dom'; -import { Expression, Variable, Session, Scope, StackFrame, Thread } from 'vs/workbench/parts/debug/common/debugModel'; +import { Expression, Variable, Scope, StackFrame, Thread } from 'vs/workbench/parts/debug/common/debugModel'; import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug'; const $ = dom.$; @@ -52,8 +52,7 @@ suite('Debug - Base Debug View', () => { }); test('render variable', () => { - const rawSession = new MockSession(); - const session = new Session({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession); + const session = new MockSession(); const thread = new Thread(session, 'mockthread', 1); const stackFrame = new StackFrame(thread, 1, null, 'app.js', 'normal', { startLineNumber: 1, startColumn: 1, endLineNumber: undefined, endColumn: undefined }, 0); const scope = new Scope(stackFrame, 1, 'local', 1, false, 10, 10); diff --git a/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts b/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts index 733ae781c373e79a16e3e1d4fbe7b7e25f426aa4..a466b211fe43b21c8c1724b8fafc012111888116 100644 --- a/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts +++ b/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; import { ViewModel } from 'vs/workbench/parts/debug/common/debugViewModel'; -import { StackFrame, Expression, Thread, Session } from 'vs/workbench/parts/debug/common/debugModel'; +import { StackFrame, Expression, Thread } from 'vs/workbench/parts/debug/common/debugModel'; import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug'; import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService'; @@ -23,8 +23,7 @@ suite('Debug - View Model', () => { test('focused stack frame', () => { assert.equal(model.focusedStackFrame, null); assert.equal(model.focusedThread, null); - const mockSession = new MockSession(); - const session = new Session({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, mockSession); + const session = new MockSession(); const thread = new Thread(session, 'myThread', 1); const frame = new StackFrame(thread, 1, null, 'app.js', 'normal', { startColumn: 1, startLineNumber: 1, endColumn: undefined, endLineNumber: undefined }, 0); model.setFocus(frame, thread, session, false); diff --git a/src/vs/workbench/parts/debug/test/common/mockDebug.ts b/src/vs/workbench/parts/debug/test/common/mockDebug.ts index f92a322a3a036508e656bfcc26cb44dbda385b53..c9914760a19d3f5ad8a75e0e64b06e5f6867de94 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebug.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebug.ts @@ -7,7 +7,10 @@ import uri from 'vs/base/common/uri'; import { Event, Emitter } from 'vs/base/common/event'; import { TPromise } from 'vs/base/common/winjs.base'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; -import { ILaunch, IDebugService, State, DebugEvent, ISession, IConfigurationManager, IStackFrame, IBreakpointData, IBreakpointUpdateData, IConfig, IModel, IViewModel, IRawSession, IBreakpoint, LoadedSourceEvent } from 'vs/workbench/parts/debug/common/debug'; +import { Position } from 'vs/editor/common/core/position'; +import { ILaunch, IDebugService, State, DebugEvent, ISession, IConfigurationManager, IStackFrame, IBreakpointData, IBreakpointUpdateData, IConfig, IModel, IViewModel, IRawSession, IBreakpoint, LoadedSourceEvent, SessionState, IThread, IRawModelUpdate } from 'vs/workbench/parts/debug/common/debug'; +import { Source } from 'vs/workbench/parts/debug/common/debugSource'; +import { ISuggestion } from 'vs/editor/common/modes'; export class MockDebugService implements IDebugService { public _serviceBrand: any; @@ -114,7 +117,49 @@ export class MockDebugService implements IDebugService { public sourceIsNotAvailable(uri: uri): void { } } -export class MockSession implements IRawSession { +export class MockSession implements ISession { + configuration: IConfig = { type: 'mock', request: 'launch' }; + raw: IRawSession = new MockRawSession(); + state = SessionState.LAUNCH; + + getName(includeRoot: boolean): string { + return 'mockname'; + } + + getSourceForUri(modelUri: uri): Source { + return null; + } + + getThread(threadId: number): IThread { + return null; + } + + getAllThreads(): ReadonlyArray { + return []; + } + + getSource(raw: DebugProtocol.Source): Source { + return undefined; + } + + getLoadedSources(): TPromise { + return TPromise.as([]); + } + + completions(frameId: number, text: string, position: Position, overwriteBefore: number): TPromise { + return TPromise.as([]); + } + + clearThreads(removeThreads: boolean, reference?: number): void { } + + rawUpdate(data: IRawModelUpdate): void { } + + getId(): string { + return 'mock'; + } +} + +export class MockRawSession implements IRawSession { public readyForBreakpoints = true; public emittedStopped = true; diff --git a/src/vs/workbench/parts/debug/test/node/debugModel.test.ts b/src/vs/workbench/parts/debug/test/electron-browser/debugModel.test.ts similarity index 94% rename from src/vs/workbench/parts/debug/test/node/debugModel.test.ts rename to src/vs/workbench/parts/debug/test/electron-browser/debugModel.test.ts index e480fb71cb6591ab8358d6cb9124b4c1620249f4..3e448f864e7024ccdbcaf47035e05cf9453cda78 100644 --- a/src/vs/workbench/parts/debug/test/node/debugModel.test.ts +++ b/src/vs/workbench/parts/debug/test/electron-browser/debugModel.test.ts @@ -6,18 +6,19 @@ import * as assert from 'assert'; import uri from 'vs/base/common/uri'; import severity from 'vs/base/common/severity'; -import { SimpleReplElement, Model, Session, Expression, RawObjectReplElement, StackFrame, Thread } from 'vs/workbench/parts/debug/common/debugModel'; +import { SimpleReplElement, Model, Expression, RawObjectReplElement, StackFrame, Thread } from 'vs/workbench/parts/debug/common/debugModel'; import * as sinon from 'sinon'; -import { MockSession } from 'vs/workbench/parts/debug/test/common/mockDebug'; +import { MockRawSession } from 'vs/workbench/parts/debug/test/common/mockDebug'; import { Source } from 'vs/workbench/parts/debug/common/debugSource'; +import { Session } from 'vs/workbench/parts/debug/electron-browser/debugSession'; suite('Debug - Model', () => { let model: Model; - let rawSession: MockSession; + let rawSession: MockRawSession; setup(() => { model = new Model([], true, [], [], []); - rawSession = new MockSession(); + rawSession = new MockRawSession(); }); teardown(() => { @@ -108,8 +109,8 @@ suite('Debug - Model', () => { test('threads simple', () => { const threadId = 1; const threadName = 'firstThread'; - - model.addSession({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession); + const session = new Session({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession); + model.addSession(session); assert.equal(model.getSessions().length, 1); model.rawUpdate({ sessionId: rawSession.getId(), @@ -119,7 +120,6 @@ suite('Debug - Model', () => { name: threadName } }); - const session = model.getSessions().filter(p => p.getId() === rawSession.getId()).pop(); assert.equal(session.getThread(threadId).name, threadName); @@ -140,7 +140,8 @@ suite('Debug - Model', () => { const stoppedReason = 'breakpoint'; // Add the threads - model.addSession({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession); + const session = new Session({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession); + model.addSession(session); model.rawUpdate({ sessionId: rawSession.getId(), threadId: threadId1, @@ -169,7 +170,6 @@ suite('Debug - Model', () => { allThreadsStopped: true }, }); - const session = model.getSessions().filter(p => p.getId() === rawSession.getId()).pop(); const thread1 = session.getThread(threadId1); const thread2 = session.getThread(threadId2); @@ -230,7 +230,8 @@ suite('Debug - Model', () => { const runningThreadId = 2; const runningThreadName = 'runningThread'; const stoppedReason = 'breakpoint'; - model.addSession({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession); + const session = new Session({ resolved: { name: 'mockSession', type: 'node', request: 'launch' }, unresolved: undefined }, rawSession); + model.addSession(session); // Add the threads model.rawUpdate({ sessionId: rawSession.getId(), @@ -260,7 +261,6 @@ suite('Debug - Model', () => { allThreadsStopped: false } }); - const session = model.getSessions().filter(p => p.getId() === rawSession.getId()).pop(); const stoppedThread = session.getThread(stoppedThreadId); const runningThread = session.getThread(runningThreadId);