File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,11 @@ describe('Angular Ivy language server', () => {
99
99
expect ( diagnostics . length ) . toBe ( 1 ) ;
100
100
expect ( diagnostics [ 0 ] . message )
101
101
. toBe ( `Property 'doesnotexist' does not exist on type 'FooComponent'.` ) ;
102
+ expect ( diagnostics [ 0 ] . relatedInformation ) . toBeDefined ( ) ;
103
+ expect ( diagnostics [ 0 ] . relatedInformation ! . length ) . toBe ( 1 ) ;
104
+ expect ( diagnostics [ 0 ] . relatedInformation ! [ 0 ] . message )
105
+ . toBe ( `Error occurs in the template of component FooComponent.` ) ;
106
+ expect ( diagnostics [ 0 ] . relatedInformation ! [ 0 ] . location . uri ) . toBe ( FOO_COMPONENT_URI ) ;
102
107
} ) ;
103
108
104
109
it ( 'should support request cancellation' , async ( ) => {
Original file line number Diff line number Diff line change 8
8
9
9
import * as ts from 'typescript/lib/tsserverlibrary' ;
10
10
import * as lsp from 'vscode-languageserver' ;
11
- import { tsTextSpanToLspRange } from './utils' ;
11
+ import { tsRelatedInformationToLspRelatedInformation , tsTextSpanToLspRange } from './utils' ;
12
12
13
13
/**
14
14
* Convert ts.DiagnosticCategory to lsp.DiagnosticSeverity
@@ -45,5 +45,6 @@ export function tsDiagnosticToLspDiagnostic(
45
45
tsDiagnosticCategoryToLspDiagnosticSeverity ( tsDiag . category ) ,
46
46
tsDiag . code ,
47
47
tsDiag . source ,
48
+ tsRelatedInformationToLspRelatedInformation ( scriptInfo , tsDiag . relatedInformation ) ,
48
49
) ;
49
50
}
Original file line number Diff line number Diff line change @@ -77,6 +77,35 @@ export function lspRangeToTsPositions(
77
77
return [ start , end ] ;
78
78
}
79
79
80
+ /**
81
+ * Convert a ts.DiagnosticRelatedInformation array to a
82
+ * lsp.DiagnosticRelatedInformation array
83
+ * @param scriptInfo Used to determine the offsets.
84
+ * @param relatedInfo
85
+ */
86
+ export function tsRelatedInformationToLspRelatedInformation (
87
+ scriptInfo : ts . server . ScriptInfo ,
88
+ relatedInfo ?: ts . DiagnosticRelatedInformation [ ] ) : lsp . DiagnosticRelatedInformation [ ] | undefined {
89
+ if ( relatedInfo === undefined ) return ;
90
+ const lspRelatedInfo : lsp . DiagnosticRelatedInformation [ ] = [ ] ;
91
+ for ( const info of relatedInfo ) {
92
+ if ( info . file === undefined || info . start === undefined || info . length === undefined ) continue ;
93
+ const textSpan : ts . TextSpan = {
94
+ start : info . start ,
95
+ length : info . length ,
96
+ } ;
97
+ const location = lsp . Location . create (
98
+ filePathToUri ( info . file . fileName ) ,
99
+ tsTextSpanToLspRange ( scriptInfo , textSpan ) ,
100
+ ) ;
101
+ lspRelatedInfo . push ( lsp . DiagnosticRelatedInformation . create (
102
+ location ,
103
+ ts . flattenDiagnosticMessageText ( info . messageText , '\n' ) ,
104
+ ) ) ;
105
+ }
106
+ return lspRelatedInfo ;
107
+ }
108
+
80
109
export function isConfiguredProject ( project : ts . server . Project ) :
81
110
project is ts . server . ConfiguredProject {
82
111
return project . projectKind === ts . server . ProjectKind . Configured ;
You can’t perform that action at this time.
0 commit comments