6
6
7
7
'use strict' ;
8
8
9
+ import { isNumber } from 'lodash' ;
9
10
import { relative } from 'path' ;
10
- import type * as vscode from 'vscode' ;
11
+ import * as vscode from 'vscode' ;
11
12
import * as vscMockHtmlContent from './htmlContent' ;
12
13
import * as vscMockStrings from './strings' ;
13
14
import * as vscUri from './uri' ;
14
15
import { generateUuid } from './uuid' ;
15
16
16
17
export enum NotebookCellKind {
17
- Markdown = 1 ,
18
+ Markup = 1 ,
18
19
Code = 2 ,
19
20
}
20
21
@@ -237,6 +238,121 @@ export class Position {
237
238
}
238
239
}
239
240
241
+ export class NotebookCellOutputItem {
242
+ static text ( value : any , mime ?: string ) : NotebookCellOutputItem {
243
+ return mime ? new NotebookCellOutputItem ( value , mime ) : new NotebookCellOutputItem ( value , '' ) ;
244
+ }
245
+
246
+ static json ( value : any , mime ?: string ) : NotebookCellOutputItem {
247
+ return mime ? new NotebookCellOutputItem ( value , mime ) : new NotebookCellOutputItem ( value , '' ) ;
248
+ }
249
+
250
+ static stdout ( value : any ) : NotebookCellOutputItem {
251
+ return new NotebookCellOutputItem ( value , '' ) ;
252
+ }
253
+
254
+ static stderr ( value : any ) : NotebookCellOutputItem {
255
+ return new NotebookCellOutputItem ( value , '' ) ;
256
+ }
257
+
258
+ static error ( value : any ) : NotebookCellOutputItem {
259
+ return new NotebookCellOutputItem ( value , '' ) ;
260
+ }
261
+
262
+ mime : string ;
263
+
264
+ data : Uint8Array ;
265
+
266
+ constructor ( data : Uint8Array , mime : string ) {
267
+ this . data = data ;
268
+ this . mime = mime ;
269
+ }
270
+ }
271
+
272
+ export class NotebookCellOutput implements vscode . NotebookCellOutput {
273
+ items : NotebookCellOutputItem [ ] ;
274
+
275
+ metadata ?: { [ key : string ] : any } ;
276
+
277
+ constructor ( items : NotebookCellOutputItem [ ] , metadata ?: { [ key : string ] : any } ) {
278
+ this . items = items ;
279
+ this . metadata = metadata ;
280
+ }
281
+ }
282
+
283
+ export interface NotebookCellExecutionSummary {
284
+ readonly executionOrder ?: number ;
285
+ readonly success ?: boolean ;
286
+ readonly timing ?: { readonly startTime : number ; readonly endTime : number } ;
287
+ }
288
+
289
+ export class NotebookCellData implements vscode . NotebookCellData {
290
+ kind : NotebookCellKind ;
291
+
292
+ value : string ;
293
+
294
+ languageId : string ;
295
+
296
+ outputs ?: NotebookCellOutput [ ] ;
297
+
298
+ metadata ?: { [ key : string ] : any } ;
299
+
300
+ executionSummary ?: NotebookCellExecutionSummary ;
301
+
302
+ constructor ( kind : NotebookCellKind , value : string , languageId : string ) {
303
+ this . kind = kind ;
304
+ this . value = value ;
305
+ this . languageId = languageId ;
306
+ }
307
+ }
308
+
309
+ export class NotebookRange implements vscode . NotebookRange {
310
+ readonly start : number ;
311
+
312
+ readonly end : number ;
313
+
314
+ readonly isEmpty : boolean = false ;
315
+
316
+ constructor ( start : number , end : number ) {
317
+ this . start = start ;
318
+ this . end = end ;
319
+ if ( end === start ) {
320
+ this . isEmpty = true ;
321
+ }
322
+ }
323
+
324
+ with ( change : { start ?: number ; end ?: number } ) {
325
+ if ( change . start === null || change . end === null ) {
326
+ throw illegalArgument ( ) ;
327
+ }
328
+
329
+ let start : number ;
330
+
331
+ if ( ! change . start ) {
332
+ start = this . start ;
333
+ } else if ( isNumber ( change . start ) ) {
334
+ start = change . start ;
335
+ } else {
336
+ start = change . start || this . start ;
337
+ }
338
+
339
+ let end : number ;
340
+ if ( ! change . end ) {
341
+ end = this . end ;
342
+ } else if ( isNumber ( change . end ) ) {
343
+ end = change . end ;
344
+ } else {
345
+ end = change . end || this . end ;
346
+ }
347
+
348
+ if ( start === this . start && end === this . end ) {
349
+ return this ;
350
+ }
351
+
352
+ return new NotebookRange ( start , end ) ;
353
+ }
354
+ }
355
+
240
356
export class Range {
241
357
static isRange ( thing : unknown ) : thing is vscode . Range {
242
358
if ( thing instanceof Range ) {
@@ -464,6 +580,45 @@ export enum EndOfLine {
464
580
CRLF = 2 ,
465
581
}
466
582
583
+ // export class NotebookEdit implements vscode.NotebookEdit {
584
+ // static replaceCells(range: NotebookRange, newCells: NotebookCellData[]) {
585
+ // return new NotebookEdit(range, newCells);
586
+ // }
587
+
588
+ // static insertCells(index: number, newCells: NotebookCellData[]) {
589
+ // return NotebookEdit.replaceCells(new NotebookRange(index, index), newCells);
590
+ // }
591
+
592
+ // static deleteCells(range: NotebookRange) {
593
+ // return NotebookEdit.replaceCells(range, [new NotebookCellData(NotebookCellKind.Code, '', '')]);
594
+ // }
595
+
596
+ // static updateCellMetadata(index: number, newCellMetadata: { [key: string]: any }) {
597
+ // const notebookEdit = NotebookEdit.replaceCells(new NotebookRange(index, index), []);
598
+ // notebookEdit.newCellMetadata = newCellMetadata;
599
+ // return notebookEdit;
600
+ // }
601
+
602
+ // static updateNotebookMetadata(newNotebookMetadata: { [key: string]: any }) {
603
+ // const notebookEdit = NotebookEdit.replaceCells(new NotebookRange(0, 0), []);
604
+ // notebookEdit.newCellMetadata = newNotebookMetadata;
605
+ // return notebookEdit;
606
+ // }
607
+
608
+ // range: NotebookRange;
609
+
610
+ // newCells: NotebookCellData[];
611
+
612
+ // newCellMetadata?: { [key: string]: any };
613
+
614
+ // newNotebookMetadata?: { [key: string]: any };
615
+
616
+ // constructor(range: NotebookRange, newCells: NotebookCellData[]) {
617
+ // this.range = range;
618
+ // this.newCells = newCells;
619
+ // }
620
+ // }
621
+
467
622
export class TextEdit {
468
623
static isTextEdit ( thing : unknown ) : thing is TextEdit {
469
624
if ( thing instanceof TextEdit ) {
@@ -493,11 +648,11 @@ export class TextEdit {
493
648
return ret ;
494
649
}
495
650
496
- protected _range : Range = new Range ( new Position ( 0 , 0 ) , new Position ( 0 , 0 ) ) ;
651
+ _range : Range = new Range ( new Position ( 0 , 0 ) , new Position ( 0 , 0 ) ) ;
497
652
498
- protected _newText = '' ;
653
+ newText = '' ;
499
654
500
- protected _newEol : EndOfLine = EndOfLine . LF ;
655
+ _newEol : EndOfLine = EndOfLine . LF ;
501
656
502
657
get range ( ) : Range {
503
658
return this . _range ;
@@ -510,16 +665,16 @@ export class TextEdit {
510
665
this . _range = value ;
511
666
}
512
667
513
- get newText ( ) : string {
514
- return this . _newText || '' ;
515
- }
668
+ // get newText(): string {
669
+ // return this._newText || '';
670
+ // }
516
671
517
- set newText ( value : string ) {
518
- if ( value && typeof value !== 'string' ) {
519
- throw illegalArgument ( 'newText' ) ;
520
- }
521
- this . _newText = value ;
522
- }
672
+ // set newText(value: string) {
673
+ // if (value && typeof value !== 'string') {
674
+ // throw illegalArgument('newText');
675
+ // }
676
+ // this._newText = value;
677
+ // }
523
678
524
679
get newEol ( ) : EndOfLine {
525
680
return this . _newEol ;
@@ -537,13 +692,13 @@ export class TextEdit {
537
692
this . newText = newText ;
538
693
}
539
694
540
- toJSON ( ) : { range : Range ; newText : string ; newEol : EndOfLine } {
541
- return {
542
- range : this . range ,
543
- newText : this . newText ,
544
- newEol : this . _newEol ,
545
- } ;
546
- }
695
+ // toJSON(): { range: Range; newText: string; newEol: EndOfLine } {
696
+ // return {
697
+ // range: this.range,
698
+ // newText: this.newText,
699
+ // newEol: this.newEol ,
700
+ // };
701
+ // }
547
702
}
548
703
549
704
export class WorkspaceEdit implements vscode . WorkspaceEdit {
@@ -664,7 +819,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
664
819
return this . _textEdits . has ( uri . toString ( ) ) ;
665
820
}
666
821
667
- set ( uri : vscUri . URI , edits : TextEdit [ ] ) : void {
822
+ set ( uri : vscUri . URI , edits : unknown [ ] ) : void {
668
823
let data = this . _textEdits . get ( uri . toString ( ) ) ;
669
824
if ( ! data ) {
670
825
data = { seq : this . _seqPool += 1 , uri, edits : [ ] } ;
@@ -673,7 +828,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit {
673
828
if ( ! edits ) {
674
829
data . edits = [ ] ;
675
830
} else {
676
- data . edits = edits . slice ( 0 ) ;
831
+ data . edits = edits . slice ( 0 ) as TextEdit [ ] ;
677
832
}
678
833
}
679
834
0 commit comments