1
- function init ( modules : { typescript : typeof import ( "typescript/lib/tsserverlibrary" ) } ) {
1
+ import { parseErrors } from '@total-typescript/error-translation-engine' ;
2
+
3
+ export default function init ( modules : { typescript : typeof import ( "typescript/lib/tsserverlibrary" ) } ) {
2
4
const ts = modules . typescript ;
3
5
6
+ function withParsedError ( messageText : string ) : string {
7
+ const parsed = parseErrors ( messageText ) ;
8
+ const allMessages = parsed . map ( err => err . error ) . join ( '\n\n' ) ;
9
+ return `${ messageText } \n\nIn other words,\n${ allMessages } \n` ;
10
+ }
11
+
4
12
function enrichDiagnostic ( diagnostic : ts . Diagnostic ) : ts . Diagnostic {
5
- // diagnostic.code: number
6
- // diagnostic.category === ts.DiagnosticCategory (Error, Message, Suggestion, Warning)
7
- diagnostic . messageText = `${ diagnostic . messageText } \n\nHello from plugin!\n`
13
+ if ( typeof diagnostic . messageText === 'string' ) {
14
+ diagnostic . messageText = withParsedError ( diagnostic . messageText ) ;
15
+ return diagnostic ;
16
+ }
17
+ if ( diagnostic . messageText . category === ts . DiagnosticCategory . Error ) {
18
+ const msg = withParsedError ( diagnostic . messageText . messageText ) ;
19
+ diagnostic . messageText . messageText = msg ;
20
+
21
+ const nextMesgs = diagnostic . messageText . next ;
22
+ if ( nextMesgs ) {
23
+ for ( let i = 0 ; i < nextMesgs . length ; i ++ ) {
24
+ let nextMsg = nextMesgs [ i ] ;
25
+ nextMesgs [ i ] . messageText = withParsedError ( nextMsg . messageText ) ;
26
+ }
27
+ }
28
+ }
8
29
return diagnostic ;
9
30
}
10
31
@@ -29,4 +50,4 @@ function init(modules: { typescript: typeof import("typescript/lib/tsserverlibra
29
50
30
51
}
31
52
32
- export = init ;
53
+ // export = init;
0 commit comments