@@ -23,11 +23,11 @@ const colorOfType = {
2323 'Console' : '#457abb' ,
2424 'Error' : 'red' ,
2525}
26- // TODO: if Node's Version of VSCode >=9.9, use option `compact`
27- const inspectOptions = { maxArrayLength : null , depth : null } ;
26+ // TODO: if Node's Version of VSCode >=9.9, use default option
27+ const inspectOptions : NodeJS . InspectOptions = { depth : 20 } ;
2828
2929type Data = { line : number , type : 'Expression' | 'Terminal' , value : any } ;
30- type Result = { line : number , type : 'Value of Expression' | 'Console' | 'Error' , text : string , value : any } ;
30+ type Result = { line : number , type : 'Value of Expression' | 'Console' | 'Error' , text : string , value : string } ;
3131
3232export default class Decorator {
3333 private editor : TextEditor ;
@@ -63,18 +63,15 @@ export default class Decorator {
6363 renderOptions : { before : { margin : '0 0 0 1em' } } ,
6464 range : new Range ( pos , pos )
6565 } ;
66- this . lineToDecorator . set ( result . line , decorator ) ;
66+ this . lineToDecorator . set ( line , decorator ) ;
6767 this . decorators . push ( decorator ) ;
6868 }
6969
7070 decorator . renderOptions . before . color = colorOfType [ result . type ] ;
7171 decorator . renderOptions . before . contentText = ` ${ result . text } ` ;
7272
7373 decorator . hoverMessage = new MarkdownString ( result . type ) ;
74- decorator . hoverMessage . appendCodeblock (
75- result . type === 'Console' ? result . value . join ( '\n' ) : result . value || result . text ,
76- 'javascript'
77- ) ;
74+ decorator . hoverMessage . appendCodeblock ( result . value , result . type === 'Error' ? 'text' : 'javascript' ) ;
7875
7976 this . decorateAll ( ) ;
8077 }
@@ -87,14 +84,14 @@ export default class Decorator {
8784 case 'object' :
8885 if ( result . constructor && result . constructor . name === 'Promise' && result . then ) {
8986 try {
90- let value = await Promise . resolve ( result ) ;
91- return value ? this . formatExpressionValue ( Object . assign ( data , { value } ) ) : null ;
87+ data . value = await ( < Promise < any > > result ) ;
88+ return data . value ? this . formatExpressionValue ( data ) : null ;
9289 } catch ( error ) {
9390 return {
9491 line : data . line ,
9592 type : 'Error' ,
9693 text : `${ error . name } : ${ error . message } ` ,
97- value : error ,
94+ value : error . stack ,
9895 }
9996 }
10097 }
@@ -103,7 +100,7 @@ export default class Decorator {
103100 return {
104101 line : data . line ,
105102 type : 'Value of Expression' ,
106- text : string ,
103+ text : string . replace ( / \n / g , ' ' ) ,
107104 value : string ,
108105 }
109106
@@ -120,22 +117,22 @@ export default class Decorator {
120117 let out = data . value as string ;
121118 let match : RegExpExecArray ;
122119
123- if ( ( match = / ( \w * E r r o r : \ s .* ) (?: \n \s * a t \s ) ? / g . exec ( out ) ) != null ) {
124- this . outputChannel . appendLine ( ` ${ match [ 1 ] } \n\tat line ${ data . line } ` ) ;
120+ if ( ( match = / ^ ( \w * E r r o r (?: \[ [ ^ \] ] + \] ) ? : \ s .* ) (?: \n \s * a t \s ) ? / . exec ( out ) ) != null ) {
121+ this . outputChannel . appendLine ( ` ${ out } ` ) ;
125122
126- return { line : data . line , type : 'Error' , text : match [ 1 ] , value : match [ 1 ] } ;
123+ return { line : data . line , type : 'Error' , text : match [ 1 ] , value : out } ;
127124 }
128- else if ( ( match = / ^ ` \{ ( \d + ) \} ` ( [ \s \S ] * ) $ / g . exec ( out ) ) != null ) {
125+ else if ( ( match = / ^ ` \{ ( \d + ) \} ` ( [ \s \S ] * ) $ / . exec ( out ) ) != null ) {
129126 let line = + match [ 1 ] ;
130127 let msg = match [ 2 ] || '' ;
131128
132129 let output = this . lineToOutput . get ( line ) ;
133130 if ( output == null ) {
134- this . lineToOutput . set ( + match [ 1 ] , output = { line, type : 'Console' , text : '' , value : [ ] } ) ;
131+ this . lineToOutput . set ( line , output = { line, type : 'Console' , text : '' , value : '' } ) ;
135132 }
136133
137- output . text += ( output . text === '' ? '' : ', ' ) + msg . replace ( / \r ? \n / g, ' ' ) ;
138- output . value . push ( msg ) ;
134+ output . text += ( output . text && ', ' ) + msg . replace ( / \r ? \n / g, ' ' ) ;
135+ output . value += ( output . value && '\n' ) + msg ;
139136
140137 this . outputChannel . appendLine ( ` ${ msg } ` ) ;
141138 return output ;
0 commit comments