@@ -10,6 +10,12 @@ export enum SuggestionApplicability {
10
10
Unspecified = 'Unspecified' ,
11
11
}
12
12
13
+ export interface RustDiagnosticSpanMacroExpansion {
14
+ span : RustDiagnosticSpan ;
15
+ macro_decl_name : string ;
16
+ def_site_span ?: RustDiagnosticSpan ;
17
+ }
18
+
13
19
// Reference:
14
20
// https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs
15
21
export interface RustDiagnosticSpan {
@@ -20,6 +26,7 @@ export interface RustDiagnosticSpan {
20
26
is_primary : boolean ;
21
27
file_name : string ;
22
28
label ?: string ;
29
+ expansion ?: RustDiagnosticSpanMacroExpansion ;
23
30
suggested_replacement ?: string ;
24
31
suggestion_applicability ?: SuggestionApplicability ;
25
32
}
@@ -60,10 +67,41 @@ function mapLevelToSeverity(s: string): vscode.DiagnosticSeverity {
60
67
return vscode . DiagnosticSeverity . Information ;
61
68
}
62
69
70
+ /**
71
+ * Check whether a file name is from macro invocation
72
+ */
73
+ function isFromMacro ( fileName : string ) : boolean {
74
+ return fileName . startsWith ( '<' ) && fileName . endsWith ( '>' ) ;
75
+ }
76
+
77
+ /**
78
+ * Converts a Rust macro span to a VsCode location recursively
79
+ */
80
+ function mapMacroSpanToLocation (
81
+ spanMacro : RustDiagnosticSpanMacroExpansion ,
82
+ ) : vscode . Location | undefined {
83
+ if ( ! isFromMacro ( spanMacro . span . file_name ) ) {
84
+ return mapSpanToLocation ( spanMacro . span ) ;
85
+ }
86
+
87
+ if ( spanMacro . span . expansion ) {
88
+ return mapMacroSpanToLocation ( spanMacro . span . expansion ) ;
89
+ }
90
+
91
+ return ;
92
+ }
93
+
63
94
/**
64
95
* Converts a Rust span to a VsCode location
65
96
*/
66
97
function mapSpanToLocation ( span : RustDiagnosticSpan ) : vscode . Location {
98
+ if ( isFromMacro ( span . file_name ) && span . expansion ) {
99
+ const macroLoc = mapMacroSpanToLocation ( span . expansion ) ;
100
+ if ( macroLoc ) {
101
+ return macroLoc ;
102
+ }
103
+ }
104
+
67
105
const fileName = path . join ( vscode . workspace . rootPath || '' , span . file_name ) ;
68
106
const fileUri = vscode . Uri . file ( fileName ) ;
69
107
0 commit comments