Skip to content

Commit 50801b7

Browse files
committed
Auto merge of rust-lang#13853 - veber-alex:diag_fix, r=Veykril
Use diagnostic code as link to full message fixes rust-lang#13823 by adding a vscode setting that will keeping the existing diagnostic code and use it as a link to the full compiler error message. While I was there I also fixed `index` to fallback to `rendered.length` to make the previewRustcOutput feature work.
2 parents e75e2f8 + ddc0147 commit 50801b7

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

editors/code/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@
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\nfor enum variants.",

editors/code/src/client.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff 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(/^(note|help):/m)?.index || 0;
123+
const index =
124+
rendered.match(/^(note|help):/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
});

editors/code/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

246250
const VarRegex = new RegExp(/\$\{(.+?)\}/g);

0 commit comments

Comments
 (0)