diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /editors/code/src/utils/diagnostics | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'editors/code/src/utils/diagnostics')
4 files changed, 54 insertions, 16 deletions
diff --git a/editors/code/src/utils/diagnostics/SuggestedFix.ts b/editors/code/src/utils/diagnostics/SuggestedFix.ts index b1be2a225..6e660bb61 100644 --- a/editors/code/src/utils/diagnostics/SuggestedFix.ts +++ b/editors/code/src/utils/diagnostics/SuggestedFix.ts | |||
@@ -24,7 +24,7 @@ export default class SuggestedFix { | |||
24 | title: string, | 24 | title: string, |
25 | location: vscode.Location, | 25 | location: vscode.Location, |
26 | replacement: string, | 26 | replacement: string, |
27 | applicability: SuggestionApplicability = SuggestionApplicability.Unspecified | 27 | applicability: SuggestionApplicability = SuggestionApplicability.Unspecified, |
28 | ) { | 28 | ) { |
29 | this.title = title; | 29 | this.title = title; |
30 | this.location = location; | 30 | this.location = location; |
@@ -51,7 +51,7 @@ export default class SuggestedFix { | |||
51 | public toCodeAction(): vscode.CodeAction { | 51 | public toCodeAction(): vscode.CodeAction { |
52 | const codeAction = new vscode.CodeAction( | 52 | const codeAction = new vscode.CodeAction( |
53 | this.title, | 53 | this.title, |
54 | vscode.CodeActionKind.QuickFix | 54 | vscode.CodeActionKind.QuickFix, |
55 | ); | 55 | ); |
56 | 56 | ||
57 | const edit = new vscode.WorkspaceEdit(); | 57 | const edit = new vscode.WorkspaceEdit(); |
diff --git a/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts b/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts index 132ce12f8..57c9856cf 100644 --- a/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts +++ b/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts | |||
@@ -38,13 +38,13 @@ export default class SuggestedFixCollection | |||
38 | */ | 38 | */ |
39 | public addSuggestedFixForDiagnostic( | 39 | public addSuggestedFixForDiagnostic( |
40 | suggestedFix: SuggestedFix, | 40 | suggestedFix: SuggestedFix, |
41 | diagnostic: vscode.Diagnostic | 41 | diagnostic: vscode.Diagnostic, |
42 | ): void { | 42 | ): void { |
43 | const fileUriString = suggestedFix.location.uri.toString(); | 43 | const fileUriString = suggestedFix.location.uri.toString(); |
44 | const fileSuggestions = this.suggestedFixes.get(fileUriString) || []; | 44 | const fileSuggestions = this.suggestedFixes.get(fileUriString) || []; |
45 | 45 | ||
46 | const existingSuggestion = fileSuggestions.find(s => | 46 | const existingSuggestion = fileSuggestions.find(s => |
47 | s.isEqual(suggestedFix) | 47 | s.isEqual(suggestedFix), |
48 | ); | 48 | ); |
49 | 49 | ||
50 | if (existingSuggestion) { | 50 | if (existingSuggestion) { |
@@ -65,7 +65,7 @@ export default class SuggestedFixCollection | |||
65 | */ | 65 | */ |
66 | public provideCodeActions( | 66 | public provideCodeActions( |
67 | document: vscode.TextDocument, | 67 | document: vscode.TextDocument, |
68 | range: vscode.Range | 68 | range: vscode.Range, |
69 | ): vscode.CodeAction[] { | 69 | ): vscode.CodeAction[] { |
70 | const documentUriString = document.uri.toString(); | 70 | const documentUriString = document.uri.toString(); |
71 | 71 | ||
diff --git a/editors/code/src/utils/diagnostics/rust.ts b/editors/code/src/utils/diagnostics/rust.ts index 0550d0372..1f0c0d3e4 100644 --- a/editors/code/src/utils/diagnostics/rust.ts +++ b/editors/code/src/utils/diagnostics/rust.ts | |||
@@ -7,7 +7,13 @@ export enum SuggestionApplicability { | |||
7 | MachineApplicable = 'MachineApplicable', | 7 | MachineApplicable = 'MachineApplicable', |
8 | HasPlaceholders = 'HasPlaceholders', | 8 | HasPlaceholders = 'HasPlaceholders', |
9 | MaybeIncorrect = 'MaybeIncorrect', | 9 | MaybeIncorrect = 'MaybeIncorrect', |
10 | Unspecified = 'Unspecified' | 10 | Unspecified = 'Unspecified', |
11 | } | ||
12 | |||
13 | export interface RustDiagnosticSpanMacroExpansion { | ||
14 | span: RustDiagnosticSpan; | ||
15 | macro_decl_name: string; | ||
16 | def_site_span?: RustDiagnosticSpan; | ||
11 | } | 17 | } |
12 | 18 | ||
13 | // Reference: | 19 | // Reference: |
@@ -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,15 +68,46 @@ function mapLevelToSeverity(s: string): vscode.DiagnosticSeverity { | |||
61 | } | 68 | } |
62 | 69 | ||
63 | /** | 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 | |||
94 | /** | ||
64 | * Converts a Rust span to a VsCode location | 95 | * Converts a Rust span to a VsCode location |
65 | */ | 96 | */ |
66 | function mapSpanToLocation(span: RustDiagnosticSpan): vscode.Location { | 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 | 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 | ||
70 | const range = new vscode.Range( | 108 | const range = new vscode.Range( |
71 | new vscode.Position(span.line_start - 1, span.column_start - 1), | 109 | new vscode.Position(span.line_start - 1, span.column_start - 1), |
72 | new vscode.Position(span.line_end - 1, span.column_end - 1) | 110 | new vscode.Position(span.line_end - 1, span.column_end - 1), |
73 | ); | 111 | ); |
74 | 112 | ||
75 | return new vscode.Location(fileUri, range); | 113 | return new vscode.Location(fileUri, range); |
@@ -81,7 +119,7 @@ function mapSpanToLocation(span: RustDiagnosticSpan): vscode.Location { | |||
81 | * If the span is unlabelled this will return `undefined`. | 119 | * If the span is unlabelled this will return `undefined`. |
82 | */ | 120 | */ |
83 | function mapSecondarySpanToRelated( | 121 | function mapSecondarySpanToRelated( |
84 | span: RustDiagnosticSpan | 122 | span: RustDiagnosticSpan, |
85 | ): vscode.DiagnosticRelatedInformation | undefined { | 123 | ): vscode.DiagnosticRelatedInformation | undefined { |
86 | if (!span.label) { | 124 | if (!span.label) { |
87 | // Nothing to label this with | 125 | // Nothing to label this with |
@@ -107,7 +145,7 @@ function isUnusedOrUnnecessary(rd: RustDiagnostic): boolean { | |||
107 | 'unused_attributes', | 145 | 'unused_attributes', |
108 | 'unused_imports', | 146 | 'unused_imports', |
109 | 'unused_macros', | 147 | 'unused_macros', |
110 | 'unused_variables' | 148 | 'unused_variables', |
111 | ].includes(rd.code.code); | 149 | ].includes(rd.code.code); |
112 | } | 150 | } |
113 | 151 | ||
@@ -157,13 +195,13 @@ function mapRustChildDiagnostic(rd: RustDiagnostic): MappedRustChildDiagnostic { | |||
157 | title, | 195 | title, |
158 | location, | 196 | location, |
159 | span.suggested_replacement, | 197 | span.suggested_replacement, |
160 | span.suggestion_applicability | 198 | span.suggestion_applicability, |
161 | ) | 199 | ), |
162 | }; | 200 | }; |
163 | } else { | 201 | } else { |
164 | const related = new vscode.DiagnosticRelatedInformation( | 202 | const related = new vscode.DiagnosticRelatedInformation( |
165 | location, | 203 | location, |
166 | rd.message | 204 | rd.message, |
167 | ); | 205 | ); |
168 | 206 | ||
169 | return { related }; | 207 | return { related }; |
@@ -183,7 +221,7 @@ function mapRustChildDiagnostic(rd: RustDiagnostic): MappedRustChildDiagnostic { | |||
183 | * If the diagnostic has no primary span this will return `undefined` | 221 | * If the diagnostic has no primary span this will return `undefined` |
184 | */ | 222 | */ |
185 | export function mapRustDiagnosticToVsCode( | 223 | export function mapRustDiagnosticToVsCode( |
186 | rd: RustDiagnostic | 224 | rd: RustDiagnostic, |
187 | ): MappedRustDiagnostic | undefined { | 225 | ): MappedRustDiagnostic | undefined { |
188 | const primarySpan = rd.spans.find(s => s.is_primary); | 226 | const primarySpan = rd.spans.find(s => s.is_primary); |
189 | if (!primarySpan) { | 227 | if (!primarySpan) { |
@@ -223,7 +261,7 @@ export function mapRustDiagnosticToVsCode( | |||
223 | const suggestedFixes = []; | 261 | const suggestedFixes = []; |
224 | for (const child of rd.children) { | 262 | for (const child of rd.children) { |
225 | const { related, suggestedFix, messageLine } = mapRustChildDiagnostic( | 263 | const { related, suggestedFix, messageLine } = mapRustChildDiagnostic( |
226 | child | 264 | child, |
227 | ); | 265 | ); |
228 | 266 | ||
229 | if (related) { | 267 | if (related) { |
@@ -256,6 +294,6 @@ export function mapRustDiagnosticToVsCode( | |||
256 | return { | 294 | return { |
257 | location, | 295 | location, |
258 | diagnostic: vd, | 296 | diagnostic: vd, |
259 | suggestedFixes | 297 | suggestedFixes, |
260 | }; | 298 | }; |
261 | } | 299 | } |
diff --git a/editors/code/src/utils/diagnostics/vscode.ts b/editors/code/src/utils/diagnostics/vscode.ts index d8b85b720..f4a5450e2 100644 --- a/editors/code/src/utils/diagnostics/vscode.ts +++ b/editors/code/src/utils/diagnostics/vscode.ts | |||
@@ -3,7 +3,7 @@ import * as vscode from 'vscode'; | |||
3 | /** Compares two `vscode.Diagnostic`s for equality */ | 3 | /** Compares two `vscode.Diagnostic`s for equality */ |
4 | export function areDiagnosticsEqual( | 4 | export function areDiagnosticsEqual( |
5 | left: vscode.Diagnostic, | 5 | left: vscode.Diagnostic, |
6 | right: vscode.Diagnostic | 6 | right: vscode.Diagnostic, |
7 | ): boolean { | 7 | ): boolean { |
8 | return ( | 8 | return ( |
9 | left.source === right.source && | 9 | left.source === right.source && |