未验证 提交 b0d714d2 编写于 作者: I Isidor Nikolic 提交者: GitHub

Merge pull request #81392 from dgozman/on-did-change-repl-elements

Fire onDidChangeReplElements directly from ReplModel
...@@ -86,6 +86,7 @@ export class DebugSession implements IDebugSession { ...@@ -86,6 +86,7 @@ export class DebugSession implements IDebugSession {
} else { } else {
this.repl = (this.parentSession as DebugSession).repl; this.repl = (this.parentSession as DebugSession).repl;
} }
this.repl.onDidChangeElements(() => this._onDidChangeREPLElements.fire());
} }
getId(): string { getId(): string {
...@@ -967,25 +968,19 @@ export class DebugSession implements IDebugSession { ...@@ -967,25 +968,19 @@ export class DebugSession implements IDebugSession {
removeReplExpressions(): void { removeReplExpressions(): void {
this.repl.removeReplExpressions(); this.repl.removeReplExpressions();
this._onDidChangeREPLElements.fire();
} }
async addReplExpression(stackFrame: IStackFrame | undefined, name: string): Promise<void> { async addReplExpression(stackFrame: IStackFrame | undefined, name: string): Promise<void> {
const expressionEvaluated = this.repl.addReplExpression(this, stackFrame, name); await this.repl.addReplExpression(this, stackFrame, name);
this._onDidChangeREPLElements.fire();
await expressionEvaluated;
this._onDidChangeREPLElements.fire();
// Evaluate all watch expressions and fetch variables again since repl evaluation might have changed some. // Evaluate all watch expressions and fetch variables again since repl evaluation might have changed some.
variableSetEmitter.fire(); variableSetEmitter.fire();
} }
appendToRepl(data: string | IExpression, severity: severity, source?: IReplElementSource): void { appendToRepl(data: string | IExpression, severity: severity, source?: IReplElementSource): void {
this.repl.appendToRepl(this, data, severity, source); this.repl.appendToRepl(this, data, severity, source);
this._onDidChangeREPLElements.fire();
} }
logToRepl(sev: severity, args: any[], frame?: { uri: URI, line: number, column: number }) { logToRepl(sev: severity, args: any[], frame?: { uri: URI, line: number, column: number }) {
this.repl.logToRepl(this, sev, args, frame); this.repl.logToRepl(this, sev, args, frame);
this._onDidChangeREPLElements.fire();
} }
} }
...@@ -12,6 +12,7 @@ import { basenameOrAuthority } from 'vs/base/common/resources'; ...@@ -12,6 +12,7 @@ import { basenameOrAuthority } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { endsWith } from 'vs/base/common/strings'; import { endsWith } from 'vs/base/common/strings';
import { generateUuid } from 'vs/base/common/uuid'; import { generateUuid } from 'vs/base/common/uuid';
import { Emitter } from 'vs/base/common/event';
const MAX_REPL_LENGTH = 10000; const MAX_REPL_LENGTH = 10000;
let topReplElementCounter = 0; let topReplElementCounter = 0;
...@@ -108,6 +109,8 @@ export class ReplEvaluationResult extends ExpressionContainer implements IReplEl ...@@ -108,6 +109,8 @@ export class ReplEvaluationResult extends ExpressionContainer implements IReplEl
export class ReplModel { export class ReplModel {
private replElements: IReplElement[] = []; private replElements: IReplElement[] = [];
private readonly _onDidChangeElements = new Emitter<void>();
readonly onDidChangeElements = this._onDidChangeElements.event;
getReplElements(): IReplElement[] { getReplElements(): IReplElement[] {
return this.replElements; return this.replElements;
...@@ -150,6 +153,7 @@ export class ReplModel { ...@@ -150,6 +153,7 @@ export class ReplModel {
if (this.replElements.length > MAX_REPL_LENGTH) { if (this.replElements.length > MAX_REPL_LENGTH) {
this.replElements.splice(0, this.replElements.length - MAX_REPL_LENGTH); this.replElements.splice(0, this.replElements.length - MAX_REPL_LENGTH);
} }
this._onDidChangeElements.fire();
} }
logToRepl(session: IDebugSession, sev: severity, args: any[], frame?: { uri: URI, line: number, column: number }) { logToRepl(session: IDebugSession, sev: severity, args: any[], frame?: { uri: URI, line: number, column: number }) {
...@@ -228,6 +232,7 @@ export class ReplModel { ...@@ -228,6 +232,7 @@ export class ReplModel {
removeReplExpressions(): void { removeReplExpressions(): void {
if (this.replElements.length > 0) { if (this.replElements.length > 0) {
this.replElements = []; this.replElements = [];
this._onDidChangeElements.fire();
} }
} }
} }
...@@ -513,7 +513,11 @@ suite('Debug - Model', () => { ...@@ -513,7 +513,11 @@ suite('Debug - Model', () => {
const grandChild = createMockSession(model, 'grandChild', { parentSession: child2, repl: 'mergeWithParent' }); const grandChild = createMockSession(model, 'grandChild', { parentSession: child2, repl: 'mergeWithParent' });
const child3 = createMockSession(model, 'child3', { parentSession: parent }); const child3 = createMockSession(model, 'child3', { parentSession: parent });
let parentChanges = 0;
parent.onDidChangeReplElements(() => ++parentChanges);
parent.appendToRepl('1\n', severity.Info); parent.appendToRepl('1\n', severity.Info);
assert.equal(parentChanges, 1);
assert.equal(parent.getReplElements().length, 1); assert.equal(parent.getReplElements().length, 1);
assert.equal(child1.getReplElements().length, 0); assert.equal(child1.getReplElements().length, 0);
assert.equal(child2.getReplElements().length, 1); assert.equal(child2.getReplElements().length, 1);
...@@ -521,6 +525,7 @@ suite('Debug - Model', () => { ...@@ -521,6 +525,7 @@ suite('Debug - Model', () => {
assert.equal(child3.getReplElements().length, 0); assert.equal(child3.getReplElements().length, 0);
grandChild.appendToRepl('1\n', severity.Info); grandChild.appendToRepl('1\n', severity.Info);
assert.equal(parentChanges, 2);
assert.equal(parent.getReplElements().length, 2); assert.equal(parent.getReplElements().length, 2);
assert.equal(child1.getReplElements().length, 0); assert.equal(child1.getReplElements().length, 0);
assert.equal(child2.getReplElements().length, 2); assert.equal(child2.getReplElements().length, 2);
...@@ -528,6 +533,7 @@ suite('Debug - Model', () => { ...@@ -528,6 +533,7 @@ suite('Debug - Model', () => {
assert.equal(child3.getReplElements().length, 0); assert.equal(child3.getReplElements().length, 0);
child3.appendToRepl('1\n', severity.Info); child3.appendToRepl('1\n', severity.Info);
assert.equal(parentChanges, 2);
assert.equal(parent.getReplElements().length, 2); assert.equal(parent.getReplElements().length, 2);
assert.equal(child1.getReplElements().length, 0); assert.equal(child1.getReplElements().length, 0);
assert.equal(child2.getReplElements().length, 2); assert.equal(child2.getReplElements().length, 2);
...@@ -535,6 +541,7 @@ suite('Debug - Model', () => { ...@@ -535,6 +541,7 @@ suite('Debug - Model', () => {
assert.equal(child3.getReplElements().length, 1); assert.equal(child3.getReplElements().length, 1);
child1.appendToRepl('1\n', severity.Info); child1.appendToRepl('1\n', severity.Info);
assert.equal(parentChanges, 2);
assert.equal(parent.getReplElements().length, 2); assert.equal(parent.getReplElements().length, 2);
assert.equal(child1.getReplElements().length, 1); assert.equal(child1.getReplElements().length, 1);
assert.equal(child2.getReplElements().length, 2); assert.equal(child2.getReplElements().length, 2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册