File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 411411 "default" : false ,
412412 "type" : " boolean"
413413 },
414+ "rust-analyzer.diagnostics.useRustcErrorCode" : {
415+ "markdownDescription" : " Whether to use the rustc error code." ,
416+ "default" : false ,
417+ "type" : " boolean"
418+ },
414419 "$generated-start" : {},
415420 "rust-analyzer.assist.emitMustUse" : {
416421 "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(
106106 next : lc . HandleDiagnosticsSignature
107107 ) {
108108 const preview = config . previewRustcOutput ;
109+ const errorCode = config . useRustcErrorCode ;
109110 diagnostics . forEach ( ( diag , idx ) => {
110111 // Abuse the fact that VSCode leaks the LSP diagnostics data field through the
111112 // Diagnostic class, if they ever break this we are out of luck and have to go
@@ -119,19 +120,28 @@ export async function createClient(
119120 ?. rendered ;
120121 if ( rendered ) {
121122 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 ;
123125 diag . message = rendered
124126 . substring ( 0 , index )
125127 . replace ( / ^ - - > [ ^ \n ] + \n / m, "" ) ;
126128 }
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+ }
127137 diag . code = {
128138 target : vscode . Uri . from ( {
129139 scheme : "rust-analyzer-diagnostics-view" ,
130140 path : "/diagnostic message" ,
131141 fragment : uri . toString ( ) ,
132142 query : idx . toString ( ) ,
133143 } ) ,
134- value : "Click for full compiler diagnostic" ,
144+ value : value ?? "Click for full compiler diagnostic" ,
135145 } ;
136146 }
137147 } ) ;
Original file line number Diff line number Diff line change @@ -241,6 +241,10 @@ export class Config {
241241 get previewRustcOutput ( ) {
242242 return this . get < boolean > ( "diagnostics.previewRustcOutput" ) ;
243243 }
244+
245+ get useRustcErrorCode ( ) {
246+ return this . get < boolean > ( "diagnostics.useRustcErrorCode" ) ;
247+ }
244248}
245249
246250const VarRegex = new RegExp ( / \$ \{ ( .+ ?) \} / g) ;
You can’t perform that action at this time.
0 commit comments