aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/utils/diagnostics
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-18 03:03:51 +0000
committerGitHub <[email protected]>2019-12-18 03:03:51 +0000
commit46ca40ccfced6945e05a25979a2703ad967d2fe0 (patch)
treeda8702614f55f0511f92c41b6bf50c506aaac3a9 /editors/code/src/utils/diagnostics
parentee93fac7767d36ee91d5a0029bb58023765c72d5 (diff)
parentbb9c60d90863b21a0e981f00e354d02b0e9fb584 (diff)
Merge #2575
2575: [VS Code Extension] Remap error location if it extracted inside macros r=edwin0cheng a=edwin0cheng It should fix for #2569 Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'editors/code/src/utils/diagnostics')
-rw-r--r--editors/code/src/utils/diagnostics/rust.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/editors/code/src/utils/diagnostics/rust.ts b/editors/code/src/utils/diagnostics/rust.ts
index b6efc0f56..1f0c0d3e4 100644
--- a/editors/code/src/utils/diagnostics/rust.ts
+++ b/editors/code/src/utils/diagnostics/rust.ts
@@ -10,6 +10,12 @@ export enum SuggestionApplicability {
10 Unspecified = 'Unspecified', 10 Unspecified = 'Unspecified',
11} 11}
12 12
13export interface RustDiagnosticSpanMacroExpansion {
14 span: RustDiagnosticSpan;
15 macro_decl_name: string;
16 def_site_span?: RustDiagnosticSpan;
17}
18
13// Reference: 19// Reference:
14// https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs 20// https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs
15export interface RustDiagnosticSpan { 21export interface RustDiagnosticSpan {
@@ -20,6 +26,7 @@ export interface RustDiagnosticSpan {
20 is_primary: boolean; 26 is_primary: boolean;
21 file_name: string; 27 file_name: string;
22 label?: string; 28 label?: string;
29 expansion?: RustDiagnosticSpanMacroExpansion;
23 suggested_replacement?: string; 30 suggested_replacement?: string;
24 suggestion_applicability?: SuggestionApplicability; 31 suggestion_applicability?: SuggestionApplicability;
25} 32}
@@ -61,9 +68,40 @@ function mapLevelToSeverity(s: string): vscode.DiagnosticSeverity {
61} 68}
62 69
63/** 70/**
71 * Check whether a file name is from macro invocation
72 */
73function 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 */
80function 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
94/**
64 * Converts a Rust span to a VsCode location 95 * Converts a Rust span to a VsCode location
65 */ 96 */
66function mapSpanToLocation(span: RustDiagnosticSpan): vscode.Location { 97function 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 const fileName = path.join(vscode.workspace.rootPath || '', span.file_name); 105 const fileName = path.join(vscode.workspace.rootPath || '', span.file_name);
68 const fileUri = vscode.Uri.file(fileName); 106 const fileUri = vscode.Uri.file(fileName);
69 107