Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #270 from jtpio/models-name
Browse files Browse the repository at this point in the history
Use more succint names for the sub-models
  • Loading branch information
afshin authored Dec 11, 2019
2 parents 045e33d + 816cfc1 commit 9162bfb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 59 deletions.
34 changes: 15 additions & 19 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ export namespace Debugger {

const { callstackCommands, editorServices, service } = options;

this.model = new Debugger.Model({});
this.model = new Debugger.Model();
this.service = service as DebugService;
this.service.model = this.model;

this.variables = new Variables({ model: this.model.variablesModel });
this.variables = new Variables({ model: this.model.variables });
this.callstack = new Callstack({
commands: callstackCommands,
model: this.model.callstackModel
model: this.model.callstack
});
this.breakpoints = new Breakpoints({
service,
model: this.model.breakpointsModel
model: this.model.breakpoints
});
this.sources = new Sources({
model: this.model.sourcesModel,
model: this.model.sources,
service,
editorServices
});
Expand Down Expand Up @@ -78,19 +78,19 @@ export namespace Debugger {
}

export class Model implements IDebugger.IModel {
constructor(options: Debugger.Model.IOptions) {
this.breakpointsModel = new Breakpoints.Model();
this.callstackModel = new Callstack.Model([]);
this.variablesModel = new Variables.Model([]);
this.sourcesModel = new Sources.Model({
currentFrameChanged: this.callstackModel.currentFrameChanged
constructor() {
this.breakpoints = new Breakpoints.Model();
this.callstack = new Callstack.Model([]);
this.variables = new Variables.Model([]);
this.sources = new Sources.Model({
currentFrameChanged: this.callstack.currentFrameChanged
});
}

readonly breakpointsModel: Breakpoints.Model;
readonly callstackModel: Callstack.Model;
readonly variablesModel: Variables.Model;
readonly sourcesModel: Sources.Model;
readonly breakpoints: Breakpoints.Model;
readonly callstack: Callstack.Model;
readonly variables: Variables.Model;
readonly sources: Sources.Model;

dispose(): void {
this._isDisposed = true;
Expand Down Expand Up @@ -134,8 +134,4 @@ export namespace Debugger {
editorServices: IEditorServices;
}
}

export namespace Model {
export interface IOptions {}
}
}
6 changes: 3 additions & 3 deletions src/handlers/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export class EditorHandler implements IDisposable {
if (!this._debuggerModel) {
return;
}
this.breakpointsModel = this._debuggerModel.breakpointsModel;
this.breakpointsModel = this._debuggerModel.breakpoints;

this._debuggerModel.callstackModel.currentFrameChanged.connect(() => {
this._debuggerModel.callstack.currentFrameChanged.connect(() => {
EditorHandler.clearHighlight(this._editor);
});

Expand Down Expand Up @@ -190,7 +190,7 @@ export class EditorHandler implements IDisposable {

private getBreakpoints(): IDebugger.IBreakpoint[] {
const code = this._editor.model.value.text;
return this._debuggerModel.breakpointsModel.getBreakpoints(
return this._debuggerModel.breakpoints.getBreakpoints(
this._path ?? this._debuggerService.getCodeId(code)
);
}
Expand Down
24 changes: 11 additions & 13 deletions src/handlers/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,24 @@ export class TrackerHandler implements IDisposable {
return;
}

this.debuggerModel.callstackModel.currentFrameChanged.connect(
this.debuggerModel.callstack.currentFrameChanged.connect(
this.onCurrentFrameChanged,
this
);

this.debuggerModel.sourcesModel.currentSourceOpened.connect(
this.debuggerModel.sources.currentSourceOpened.connect(
this.onCurrentSourceOpened,
this
);

this.debuggerModel.breakpointsModel.clicked.connect(
async (_, breakpoint) => {
const path = breakpoint.source.path;
let source = await this.debuggerService.getSource({
sourceReference: 0,
path
});
this.onCurrentSourceOpened(null, source);
}
);
this.debuggerModel.breakpoints.clicked.connect(async (_, breakpoint) => {
const path = breakpoint.source.path;
let source = await this.debuggerService.getSource({
sourceReference: 0,
path
});
this.onCurrentSourceOpened(null, source);
});
}

protected onCurrentFrameChanged(_: Callstack.Model, frame: Callstack.IFrame) {
Expand Down Expand Up @@ -153,7 +151,7 @@ export class TrackerHandler implements IDisposable {
this.shell.add(widget, 'main');
void this.readOnlyEditorTracker.add(widget);

const frame = this.debuggerModel?.callstackModel.frame;
const frame = this.debuggerModel?.callstack.frame;
if (frame) {
EditorHandler.showCurrentLine(editor, frame.line);
}
Expand Down
32 changes: 15 additions & 17 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class DebugService implements IDebugger, IDisposable {
* Precondition: isStarted().
*/
async restart(): Promise<void> {
const breakpoints = this._model.breakpointsModel.breakpoints;
const breakpoints = this._model.breakpoints.breakpoints;
await this.stop();
this.clearModel();
await this.start();
Expand Down Expand Up @@ -223,7 +223,7 @@ export class DebugService implements IDebugger, IDisposable {
);
});
}
this._model.breakpointsModel.restoreBreakpoints(bpMap);
this._model.breakpoints.restoreBreakpoints(bpMap);

const stoppedThreads = new Set(reply.body.stoppedThreads);
this._model.stoppedThreads = stoppedThreads;
Expand Down Expand Up @@ -327,7 +327,7 @@ export class DebugService implements IDebugger, IDisposable {
(breakpoint, i, arr) =>
arr.findIndex(el => el.line === breakpoint.line) === i
);
this._model.breakpointsModel.setBreakpoints(path, kernelBreakpoints);
this._model.breakpoints.setBreakpoints(path, kernelBreakpoints);
await this.session.sendRequest('configurationDone', {});
}

Expand All @@ -336,14 +336,14 @@ export class DebugService implements IDebugger, IDisposable {
return;
}

this._model.breakpointsModel.breakpoints.forEach(
this._model.breakpoints.breakpoints.forEach(
async (breakpoints, path, _) => {
await this.setBreakpoints([], path);
}
);

let bpMap = new Map<string, IDebugger.IBreakpoint[]>();
this._model.breakpointsModel.restoreBreakpoints(bpMap);
this._model.breakpoints.restoreBreakpoints(bpMap);
}

/**
Expand All @@ -359,11 +359,11 @@ export class DebugService implements IDebugger, IDisposable {
}

async getAllFrames() {
this._model.callstackModel.currentFrameChanged.connect(this.onChangeFrame);
this._model.variablesModel.variableExpanded.connect(this.getVariable);
this._model.callstack.currentFrameChanged.connect(this.onChangeFrame);
this._model.variables.variableExpanded.connect(this.getVariable);

const stackFrames = await this.getFrames(this.currentThread());
this._model.callstackModel.frames = stackFrames;
this._model.callstack.frames = stackFrames;
}

onChangeFrame = async (_: Callstack.Model, frame: Callstack.IFrame) => {
Expand All @@ -373,7 +373,7 @@ export class DebugService implements IDebugger, IDisposable {
const scopes = await this.getScopes(frame);
const variables = await this.getVariables(scopes);
const variableScopes = this.convertScope(scopes, variables);
this._model.variablesModel.scopes = variableScopes;
this._model.variables.scopes = variableScopes;
};

dumpCell = async (code: string) => {
Expand Down Expand Up @@ -409,15 +409,15 @@ export class DebugService implements IDebugger, IDisposable {
newVariable = { [variable.name]: variable, ...newVariable };
});

const newScopes = this._model.variablesModel.scopes.map(scope => {
const newScopes = this._model.variables.scopes.map(scope => {
const findIndex = scope.variables.findIndex(
ele => ele.variablesReference === variable.variablesReference
);
scope.variables[findIndex] = newVariable;
return { ...scope };
});

this._model.variablesModel.scopes = [...newScopes];
this._model.variables.scopes = [...newScopes];

return reply.body.variables;
};
Expand Down Expand Up @@ -468,15 +468,13 @@ export class DebugService implements IDebugger, IDisposable {
}

private clearModel() {
this._model.callstackModel.frames = [];
this._model.variablesModel.scopes = [];
this._model.callstack.frames = [];
this._model.variables.scopes = [];
}

private clearSignals() {
this._model.callstackModel.currentFrameChanged.disconnect(
this.onChangeFrame
);
this._model.variablesModel.variableExpanded.disconnect(this.getVariable);
this._model.callstack.currentFrameChanged.disconnect(this.onChangeFrame);
this._model.variables.variableExpanded.disconnect(this.getVariable);
}

private currentThread(): number {
Expand Down
14 changes: 7 additions & 7 deletions tests/src/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('DebugService', () => {
await (client as ClientSession).initialize();
await client.kernel.ready;
session = new DebugSession({ client });
model = new Debugger.Model({});
model = new Debugger.Model();
service = new DebugService();
});

Expand Down Expand Up @@ -173,32 +173,32 @@ describe('DebugService', () => {

describe('#updateBreakpoints', () => {
it('should update the breakpoints', () => {
const bpList = model.breakpointsModel.getBreakpoints(sourceId);
const bpList = model.breakpoints.getBreakpoints(sourceId);
expect(bpList).to.deep.eq(breakpoints);
});
});

describe('#restoreState', () => {
it('should restore the breakpoints', async () => {
model.breakpointsModel.restoreBreakpoints(
model.breakpoints.restoreBreakpoints(
new Map<string, IDebugger.IBreakpoint[]>()
);
const bpList1 = model.breakpointsModel.getBreakpoints(sourceId);
const bpList1 = model.breakpoints.getBreakpoints(sourceId);
expect(bpList1.length).to.equal(0);
await service.restoreState(true);
const bpList2 = model.breakpointsModel.getBreakpoints(sourceId);
const bpList2 = model.breakpoints.getBreakpoints(sourceId);
expect(bpList2).to.deep.eq(breakpoints);
});
});

describe('#restart', () => {
it('should restart the debugger and send the breakpoints again', async () => {
await service.restart();
model.breakpointsModel.restoreBreakpoints(
model.breakpoints.restoreBreakpoints(
new Map<string, IDebugger.IBreakpoint[]>()
);
await service.restoreState(true);
const bpList = model.breakpointsModel.getBreakpoints(sourceId);
const bpList = model.breakpoints.getBreakpoints(sourceId);
breakpoints[0].id = 2;
breakpoints[1].id = 3;
expect(bpList).to.deep.eq(breakpoints);
Expand Down

0 comments on commit 9162bfb

Please sign in to comment.