This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree 3 files changed +21
-2
lines changed
3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 411
411
"default" : false ,
412
412
"type" : " boolean"
413
413
},
414
+ "rust-analyzer.diagnostics.useRustcErrorCode" : {
415
+ "markdownDescription" : " Whether to use the rustc error code." ,
416
+ "default" : false ,
417
+ "type" : " boolean"
418
+ },
414
419
"$generated-start" : {},
415
420
"rust-analyzer.assist.emitMustUse" : {
416
421
"markdownDescription" : " Whether to insert #[must_use] when generating `as_` methods\n for enum variants." ,
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ export async function createClient(
106
106
next : lc . HandleDiagnosticsSignature
107
107
) {
108
108
const preview = config . previewRustcOutput ;
109
+ const errorCode = config . useRustcErrorCode ;
109
110
diagnostics . forEach ( ( diag , idx ) => {
110
111
// Abuse the fact that VSCode leaks the LSP diagnostics data field through the
111
112
// Diagnostic class, if they ever break this we are out of luck and have to go
@@ -119,19 +120,28 @@ export async function createClient(
119
120
?. rendered ;
120
121
if ( rendered ) {
121
122
if ( preview ) {
122
- const index = rendered . match ( / ^ ( n o t e | h e l p ) : / m) ?. index || 0 ;
123
+ const index =
124
+ rendered . match ( / ^ ( n o t e | h e l p ) : / m) ?. index || rendered . length ;
123
125
diag . message = rendered
124
126
. substring ( 0 , index )
125
127
. replace ( / ^ - - > [ ^ \n ] + \n / m, "" ) ;
126
128
}
129
+ let value ;
130
+ if ( errorCode ) {
131
+ if ( typeof diag . code === "string" || typeof diag . code === "number" ) {
132
+ value = diag . code ;
133
+ } else {
134
+ value = diag . code ?. value ;
135
+ }
136
+ }
127
137
diag . code = {
128
138
target : vscode . Uri . from ( {
129
139
scheme : "rust-analyzer-diagnostics-view" ,
130
140
path : "/diagnostic message" ,
131
141
fragment : uri . toString ( ) ,
132
142
query : idx . toString ( ) ,
133
143
} ) ,
134
- value : "Click for full compiler diagnostic" ,
144
+ value : value ?? "Click for full compiler diagnostic" ,
135
145
} ;
136
146
}
137
147
} ) ;
Original file line number Diff line number Diff line change @@ -241,6 +241,10 @@ export class Config {
241
241
get previewRustcOutput ( ) {
242
242
return this . get < boolean > ( "diagnostics.previewRustcOutput" ) ;
243
243
}
244
+
245
+ get useRustcErrorCode ( ) {
246
+ return this . get < boolean > ( "diagnostics.useRustcErrorCode" ) ;
247
+ }
244
248
}
245
249
246
250
const VarRegex = new RegExp ( / \$ \{ ( .+ ?) \} / g) ;
You can’t perform that action at this time.
0 commit comments