Skip to content

Commit 38c5406

Browse files
committed
debug: polish appending to repl
1 parent 84ccb23 commit 38c5406

3 files changed

Lines changed: 23 additions & 22 deletions

File tree

src/vs/workbench/parts/debug/common/debugModel.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,19 +817,20 @@ export class Model implements debug.IModel {
817817
.then(() => this._onDidChangeREPLElements.fire());
818818
}
819819

820-
public appendReplOutput(output: OutputElement | debug.IExpression): void {
820+
public appendToRepl(output: string | debug.IExpression, severity: severity): void {
821821
const previousOutput = this.replElements.length && (this.replElements[this.replElements.length - 1] as OutputElement);
822-
const groupTogether = output instanceof OutputElement && previousOutput instanceof OutputElement && output.severity === previousOutput.severity;
822+
const groupTogether = typeof output === 'string' && previousOutput instanceof OutputElement && severity === previousOutput.severity;
823823
if (groupTogether) {
824-
if (strings.endsWith(previousOutput.value, '\n') && previousOutput.value === output.value && output.value.trim()) {
824+
if (strings.endsWith(previousOutput.value, '\n') && previousOutput.value === output && output.trim()) {
825825
// we got the same output (but not an empty string when trimmed) so we just increment the counter
826826
previousOutput.counter++;
827827
} else {
828828
// append to previous line if same group
829-
previousOutput.value += output.value;
829+
previousOutput.value += output;
830830
}
831831
} else {
832-
this.addReplElement(output);
832+
const newReplElement = typeof output === 'string' ? new OutputElement(output, severity) : output;
833+
this.addReplElement(newReplElement);
833834
}
834835

835836
this._onDidChangeREPLElements.fire();

src/vs/workbench/parts/debug/electron-browser/debugService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { IEditorGroupService } from 'vs/workbench/services/group/common/groupSer
3636
import { asFileEditorInput } from 'vs/workbench/common/editor';
3737
import * as debug from 'vs/workbench/parts/debug/common/debug';
3838
import { RawDebugSession } from 'vs/workbench/parts/debug/electron-browser/rawDebugSession';
39-
import { Model, ExceptionBreakpoint, FunctionBreakpoint, Breakpoint, Expression, OutputElement, OutputNameValueElement, ExpressionContainer, Process } from 'vs/workbench/parts/debug/common/debugModel';
39+
import { Model, ExceptionBreakpoint, FunctionBreakpoint, Breakpoint, Expression, OutputNameValueElement, ExpressionContainer, Process } from 'vs/workbench/parts/debug/common/debugModel';
4040
import { DebugStringEditorInput, DebugErrorEditorInput } from 'vs/workbench/parts/debug/browser/debugEditorInputs';
4141
import { ViewModel } from 'vs/workbench/parts/debug/common/debugViewModel';
4242
import * as debugactions from 'vs/workbench/parts/debug/browser/debugActions';
@@ -195,12 +195,12 @@ export class DebugService implements debug.IDebugService {
195195

196196
// flush any existing simple values logged
197197
if (simpleVals.length) {
198-
this.model.appendReplOutput(new OutputElement(simpleVals.join(' '), sev));
198+
this.model.appendToRepl(simpleVals.join(' '), sev);
199199
simpleVals = [];
200200
}
201201

202202
// show object
203-
this.model.appendReplOutput(new OutputNameValueElement((<any>a).prototype, a, nls.localize('snapshotObj', "Only primitive values are shown for this object.")));
203+
this.model.appendToRepl(new OutputNameValueElement((<any>a).prototype, a, nls.localize('snapshotObj', "Only primitive values are shown for this object.")), sev);
204204
}
205205

206206
// string: watch out for % replacement directive
@@ -229,7 +229,7 @@ export class DebugService implements debug.IDebugService {
229229

230230
// flush simple values
231231
if (simpleVals.length) {
232-
this.model.appendReplOutput(new OutputElement(simpleVals.join(' '), sev));
232+
this.model.appendToRepl(simpleVals.join(' '), sev);
233233
}
234234
}
235235
}
@@ -328,12 +328,12 @@ export class DebugService implements debug.IDebugService {
328328
children.forEach(child => {
329329
// Since we can not display multiple trees in a row, we are displaying these variables one after the other (ignoring their names)
330330
child.name = null;
331-
this.model.appendReplOutput(child);
331+
this.model.appendToRepl(child, null);
332332
});
333333
});
334334
} else {
335335
const outputSeverity = event.body.category === 'stderr' ? severity.Error : event.body.category === 'console' ? severity.Warning : severity.Info;
336-
this.model.appendReplOutput(new OutputElement(event.body.output, outputSeverity));
336+
this.model.appendToRepl(event.body.output, outputSeverity);
337337
}
338338
}
339339
}));

src/vs/workbench/parts/debug/test/node/debugModel.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ suite('Debug - Model', () => {
357357
// Repl output
358358

359359
test('repl output', () => {
360-
model.appendReplOutput(new OutputElement('first line\n', severity.Error));
361-
model.appendReplOutput(new OutputElement('second line\n', severity.Warning));
362-
model.appendReplOutput(new OutputElement('second line\n', severity.Warning));
363-
model.appendReplOutput(new OutputElement('second line\n', severity.Error));
360+
model.appendToRepl('first line\n', severity.Error);
361+
model.appendToRepl('second line\n', severity.Warning);
362+
model.appendToRepl('second line\n', severity.Warning);
363+
model.appendToRepl('second line\n', severity.Error);
364364

365365
let elements = <OutputElement[]>model.getReplElements();
366366
assert.equal(elements.length, 3);
@@ -371,28 +371,28 @@ suite('Debug - Model', () => {
371371
assert.equal(elements[1].counter, 2);
372372
assert.equal(elements[1].severity, severity.Warning);
373373

374-
model.appendReplOutput(new OutputElement('1', severity.Warning));
375-
model.appendReplOutput(new OutputElement('2', severity.Warning));
376-
model.appendReplOutput(new OutputElement('3', severity.Warning));
374+
model.appendToRepl('1', severity.Warning);
375+
model.appendToRepl('2', severity.Warning);
376+
model.appendToRepl('3', severity.Warning);
377377
elements = <OutputElement[]>model.getReplElements();
378378
assert.equal(elements.length, 4);
379379
assert.equal(elements[3].value, '123');
380380
assert.equal(elements[3].severity, severity.Warning);
381381

382382
const keyValueObject = { 'key1': 2, 'key2': 'value' };
383-
model.appendReplOutput(new OutputNameValueElement('fake', keyValueObject));
383+
model.appendToRepl(new OutputNameValueElement('fake', keyValueObject), null);
384384
const element = <OutputNameValueElement>model.getReplElements()[4];
385385
assert.equal(element.value, 'Object');
386386
assert.deepEqual(element.valueObj, keyValueObject);
387387

388388
const multiLineContent = 'multi line \n string \n last line';
389-
model.appendReplOutput(new OutputElement(multiLineContent, severity.Info));
389+
model.appendToRepl(multiLineContent, severity.Info);
390390
const multiLineElement = <OutputElement>model.getReplElements()[5];
391391
assert.equal(multiLineElement.value, multiLineContent);
392392
assert.equal(model.getReplElements().length, 6);
393393

394-
model.appendReplOutput(new OutputElement('second line', severity.Warning));
395-
model.appendReplOutput(new OutputElement('second line', severity.Warning));
394+
model.appendToRepl('second line', severity.Warning);
395+
model.appendToRepl('second line', severity.Warning);
396396

397397
assert.equal((<OutputElement>model.getReplElements()[6]).value, 'second linesecond line');
398398

0 commit comments

Comments
 (0)