aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/test/rust_diagnostics.test.ts9
-rw-r--r--editors/code/src/test/vscode_diagnostics.test.ts18
-rw-r--r--editors/code/src/utils/rust_diagnostics.ts14
3 files changed, 35 insertions, 6 deletions
diff --git a/editors/code/src/test/rust_diagnostics.test.ts b/editors/code/src/test/rust_diagnostics.test.ts
index 5eb064b97..f27c58fe2 100644
--- a/editors/code/src/test/rust_diagnostics.test.ts
+++ b/editors/code/src/test/rust_diagnostics.test.ts
@@ -37,6 +37,7 @@ describe('mapRustDiagnosticToVsCode', () => {
37 diagnostic.severity, 37 diagnostic.severity,
38 vscode.DiagnosticSeverity.Error 38 vscode.DiagnosticSeverity.Error
39 ); 39 );
40 assert.strictEqual(diagnostic.source, 'rustc');
40 assert.strictEqual( 41 assert.strictEqual(
41 diagnostic.message, 42 diagnostic.message,
42 [ 43 [
@@ -72,6 +73,7 @@ describe('mapRustDiagnosticToVsCode', () => {
72 ].join('\n') 73 ].join('\n')
73 ); 74 );
74 assert.strictEqual(diagnostic.code, 'unused_variables'); 75 assert.strictEqual(diagnostic.code, 'unused_variables');
76 assert.strictEqual(diagnostic.source, 'rustc');
75 assert.deepStrictEqual(diagnostic.tags, [ 77 assert.deepStrictEqual(diagnostic.tags, [
76 vscode.DiagnosticTag.Unnecessary 78 vscode.DiagnosticTag.Unnecessary
77 ]); 79 ]);
@@ -101,6 +103,7 @@ describe('mapRustDiagnosticToVsCode', () => {
101 'this function takes 2 parameters but 3 parameters were supplied' 103 'this function takes 2 parameters but 3 parameters were supplied'
102 ); 104 );
103 assert.strictEqual(diagnostic.code, 'E0061'); 105 assert.strictEqual(diagnostic.code, 'E0061');
106 assert.strictEqual(diagnostic.source, 'rustc');
104 assert.strictEqual(diagnostic.tags, undefined); 107 assert.strictEqual(diagnostic.tags, undefined);
105 108
106 // One related information for the original definition 109 // One related information for the original definition
@@ -125,6 +128,7 @@ describe('mapRustDiagnosticToVsCode', () => {
125 diagnostic.severity, 128 diagnostic.severity,
126 vscode.DiagnosticSeverity.Warning 129 vscode.DiagnosticSeverity.Warning
127 ); 130 );
131 assert.strictEqual(diagnostic.source, 'clippy');
128 assert.strictEqual( 132 assert.strictEqual(
129 diagnostic.message, 133 diagnostic.message,
130 [ 134 [
@@ -133,10 +137,7 @@ describe('mapRustDiagnosticToVsCode', () => {
133 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref' 137 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref'
134 ].join('\n') 138 ].join('\n')
135 ); 139 );
136 assert.strictEqual( 140 assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref');
137 diagnostic.code,
138 'clippy::trivially_copy_pass_by_ref'
139 );
140 assert.strictEqual(diagnostic.tags, undefined); 141 assert.strictEqual(diagnostic.tags, undefined);
141 142
142 // One related information for the lint definition 143 // One related information for the lint definition
diff --git a/editors/code/src/test/vscode_diagnostics.test.ts b/editors/code/src/test/vscode_diagnostics.test.ts
index ca4345626..9c5d812fa 100644
--- a/editors/code/src/test/vscode_diagnostics.test.ts
+++ b/editors/code/src/test/vscode_diagnostics.test.ts
@@ -35,6 +35,24 @@ describe('areDiagnosticsEqual', () => {
35 assert(areDiagnosticsEqual(diagnostic1, diagnostic2)); 35 assert(areDiagnosticsEqual(diagnostic1, diagnostic2));
36 }); 36 });
37 37
38 it('should treat diagnostics with different sources as inequal', () => {
39 const diagnostic1 = new vscode.Diagnostic(
40 range1,
41 'Hello, world!',
42 vscode.DiagnosticSeverity.Error
43 );
44 diagnostic1.source = 'rustc';
45
46 const diagnostic2 = new vscode.Diagnostic(
47 range1,
48 'Hello, world!',
49 vscode.DiagnosticSeverity.Error
50 );
51 diagnostic2.source = 'clippy';
52
53 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
54 });
55
38 it('should treat diagnostics with different ranges as inequal', () => { 56 it('should treat diagnostics with different ranges as inequal', () => {
39 const diagnostic1 = new vscode.Diagnostic( 57 const diagnostic1 = new vscode.Diagnostic(
40 range1, 58 range1,
diff --git a/editors/code/src/utils/rust_diagnostics.ts b/editors/code/src/utils/rust_diagnostics.ts
index ed049c95e..3c524cb37 100644
--- a/editors/code/src/utils/rust_diagnostics.ts
+++ b/editors/code/src/utils/rust_diagnostics.ts
@@ -187,8 +187,18 @@ export function mapRustDiagnosticToVsCode(
187 187
188 const vd = new vscode.Diagnostic(location.range, rd.message, severity); 188 const vd = new vscode.Diagnostic(location.range, rd.message, severity);
189 189
190 vd.source = 'rustc'; 190 let source = 'rustc';
191 vd.code = rd.code ? rd.code.code : undefined; 191 let code = rd.code && rd.code.code;
192 if (code) {
193 // See if this is an RFC #2103 scoped lint (e.g. from Clippy)
194 const scopedCode = code.split('::');
195 if (scopedCode.length === 2) {
196 [source, code] = scopedCode;
197 }
198 }
199
200 vd.source = source;
201 vd.code = code;
192 vd.relatedInformation = []; 202 vd.relatedInformation = [];
193 203
194 for (const secondarySpan of secondarySpans) { 204 for (const secondarySpan of secondarySpans) {