@@ -33,17 +33,21 @@ use std::borrow::Cow;
33
33
use std:: collections:: HashSet ;
34
34
use std:: rc:: Rc ;
35
35
36
- #[ derive( Debug , Clone , PartialEq , Eq ) ]
36
+ #[ derive( Debug , Clone ) ]
37
37
pub enum DocDiagnosticKind {
38
38
MissingJsDoc ,
39
39
MissingExplicitType ,
40
40
MissingReturnType ,
41
- PrivateTypeRef {
42
- name : String ,
43
- reference : String ,
44
- /// The location of the reference.
45
- reference_location : Location ,
46
- } ,
41
+ PrivateTypeRef ( Box < PrivateTypeRefDiagnostic > ) ,
42
+ }
43
+
44
+ #[ derive( Debug , Clone ) ]
45
+ pub struct PrivateTypeRefDiagnostic {
46
+ pub name : String ,
47
+ pub reference : String ,
48
+ pub reference_text_info : SourceTextInfo ,
49
+ /// The location of the reference.
50
+ pub reference_location : Location ,
47
51
}
48
52
49
53
#[ derive( Clone ) ]
@@ -89,10 +93,9 @@ impl Diagnostic for DocDiagnostic {
89
93
DocDiagnosticKind :: MissingReturnType => Cow :: Borrowed (
90
94
"exported function is missing an explicit return type annotation" ,
91
95
) ,
92
- DocDiagnosticKind :: PrivateTypeRef {
93
- reference, name, ..
94
- } => Cow :: Owned ( format ! (
95
- "public type '{name}' references private type '{reference}'" ,
96
+ DocDiagnosticKind :: PrivateTypeRef ( diagnostic) => Cow :: Owned ( format ! (
97
+ "public type '{}' references private type '{}'" ,
98
+ diagnostic. name, diagnostic. reference,
96
99
) ) ,
97
100
}
98
101
}
@@ -130,23 +133,23 @@ impl Diagnostic for DocDiagnostic {
130
133
}
131
134
fn snippet_fixed ( & self ) -> Option < DiagnosticSnippet < ' _ > > {
132
135
match & self . kind {
133
- DocDiagnosticKind :: PrivateTypeRef {
134
- reference_location, ..
135
- } => Some ( DiagnosticSnippet {
136
- source : Cow :: Borrowed ( & self . text_info ) ,
137
- highlight : DiagnosticSnippetHighlight {
138
- style : DiagnosticSnippetHighlightStyle :: Hint ,
139
- range : DiagnosticSourceRange {
140
- start : DiagnosticSourcePos :: ByteIndex (
141
- reference_location. byte_index ,
142
- ) ,
143
- end : DiagnosticSourcePos :: ByteIndex (
144
- reference_location. byte_index + 1 ,
145
- ) ,
136
+ DocDiagnosticKind :: PrivateTypeRef ( diagnostic) => {
137
+ Some ( DiagnosticSnippet {
138
+ source : Cow :: Borrowed ( & diagnostic. reference_text_info ) ,
139
+ highlight : DiagnosticSnippetHighlight {
140
+ style : DiagnosticSnippetHighlightStyle :: Hint ,
141
+ range : DiagnosticSourceRange {
142
+ start : DiagnosticSourcePos :: ByteIndex (
143
+ diagnostic. reference_location . byte_index ,
144
+ ) ,
145
+ end : DiagnosticSourcePos :: ByteIndex (
146
+ diagnostic. reference_location . byte_index + 1 ,
147
+ ) ,
148
+ } ,
149
+ description : Some ( Cow :: Borrowed ( "this is the referenced type" ) ) ,
146
150
} ,
147
- description : Some ( Cow :: Borrowed ( "this is the referenced type" ) ) ,
148
- } ,
149
- } ) ,
151
+ } )
152
+ }
150
153
_ => None ,
151
154
}
152
155
}
@@ -222,28 +225,31 @@ impl<'a> DiagnosticsCollector<'a> {
222
225
decl_range. start ,
223
226
) ,
224
227
text_info : decl_module. text_info ( ) . clone ( ) ,
225
- kind : DocDiagnosticKind :: PrivateTypeRef {
226
- name : decl_name. to_string ( ) ,
227
- reference : reference. to_string ( ) ,
228
- reference_location : referenced_symbol
229
- . decls ( )
230
- . iter ( )
231
- . next ( )
232
- . map ( |d| {
233
- get_text_info_location (
234
- referenced_module. specifier ( ) . as_str ( ) ,
235
- referenced_module. text_info ( ) ,
236
- d. range . start ,
237
- )
238
- } )
239
- // should never happen, but just in case
240
- . unwrap_or_else ( || Location {
241
- filename : referenced_module. specifier ( ) . to_string ( ) ,
242
- line : 1 ,
243
- col : 0 ,
244
- byte_index : 0 ,
245
- } ) ,
246
- } ,
228
+ kind : DocDiagnosticKind :: PrivateTypeRef ( Box :: new (
229
+ PrivateTypeRefDiagnostic {
230
+ name : decl_name. to_string ( ) ,
231
+ reference : reference. to_string ( ) ,
232
+ reference_text_info : referenced_module. text_info ( ) . clone ( ) ,
233
+ reference_location : referenced_symbol
234
+ . decls ( )
235
+ . iter ( )
236
+ . next ( )
237
+ . map ( |d| {
238
+ get_text_info_location (
239
+ referenced_module. specifier ( ) . as_str ( ) ,
240
+ referenced_module. text_info ( ) ,
241
+ d. range . start ,
242
+ )
243
+ } )
244
+ // should never happen, but just in case
245
+ . unwrap_or_else ( || Location {
246
+ filename : referenced_module. specifier ( ) . to_string ( ) ,
247
+ line : 1 ,
248
+ col : 0 ,
249
+ byte_index : 0 ,
250
+ } ) ,
251
+ } ,
252
+ ) ) ,
247
253
} )
248
254
}
249
255
0 commit comments