Skip to content

Commit 656e952

Browse files
committed
Warnings as hint or info
1 parent 5d7974e commit 656e952

7 files changed

+402
-13
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
use std::{ffi::OsString, path::PathBuf};
1111

12+
use crate::diagnostics::DiagnosticsConfig;
1213
use lsp_types::ClientCapabilities;
1314
use ra_flycheck::FlycheckConfig;
1415
use ra_ide::{AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig};
@@ -20,6 +21,7 @@ pub struct Config {
2021
pub client_caps: ClientCapsConfig,
2122

2223
pub publish_diagnostics: bool,
24+
pub diagnostics: DiagnosticsConfig,
2325
pub lru_capacity: Option<usize>,
2426
pub proc_macro_srv: Option<(PathBuf, Vec<OsString>)>,
2527
pub files: FilesConfig,
@@ -136,6 +138,7 @@ impl Default for Config {
136138

137139
with_sysroot: true,
138140
publish_diagnostics: true,
141+
diagnostics: DiagnosticsConfig::default(),
139142
lru_capacity: None,
140143
proc_macro_srv: None,
141144
files: FilesConfig { watcher: FilesWatcher::Notify, exclude: Vec::new() },
@@ -184,6 +187,8 @@ impl Config {
184187

185188
set(value, "/withSysroot", &mut self.with_sysroot);
186189
set(value, "/diagnostics/enable", &mut self.publish_diagnostics);
190+
set(value, "/diagnostics/warningsAsInfo", &mut self.diagnostics.warnings_as_info);
191+
set(value, "/diagnostics/warningsAsHint", &mut self.diagnostics.warnings_as_hint);
187192
set(value, "/lruCapacity", &mut self.lru_capacity);
188193
self.files.watcher = match get(value, "/files/watcher") {
189194
Some("client") => FilesWatcher::Client,

crates/rust-analyzer/src/diagnostics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ use crate::lsp_ext;
1010

1111
pub type CheckFixes = Arc<HashMap<FileId, Vec<Fix>>>;
1212

13+
#[derive(Debug, Default, Clone)]
14+
pub struct DiagnosticsConfig {
15+
pub warnings_as_info: Vec<String>,
16+
pub warnings_as_hint: Vec<String>,
17+
}
18+
1319
#[derive(Debug, Default, Clone)]
1420
pub struct DiagnosticCollection {
1521
pub native: HashMap<FileId, Vec<Diagnostic>>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3+
expression: diag
4+
---
5+
[
6+
MappedRustDiagnostic {
7+
location: Location {
8+
uri: "file:///test/driver/subcommand/repl.rs",
9+
range: Range {
10+
start: Position {
11+
line: 290,
12+
character: 8,
13+
},
14+
end: Position {
15+
line: 290,
16+
character: 11,
17+
},
18+
},
19+
},
20+
diagnostic: Diagnostic {
21+
range: Range {
22+
start: Position {
23+
line: 290,
24+
character: 8,
25+
},
26+
end: Position {
27+
line: 290,
28+
character: 11,
29+
},
30+
},
31+
severity: Some(
32+
Hint,
33+
),
34+
code: Some(
35+
String(
36+
"unused_variables",
37+
),
38+
),
39+
source: Some(
40+
"rustc",
41+
),
42+
message: "unused variable: `foo`\n#[warn(unused_variables)] on by default",
43+
related_information: None,
44+
tags: Some(
45+
[
46+
Unnecessary,
47+
],
48+
),
49+
},
50+
fixes: [
51+
CodeAction {
52+
title: "consider prefixing with an underscore",
53+
id: None,
54+
group: None,
55+
kind: Some(
56+
"quickfix",
57+
),
58+
command: None,
59+
edit: Some(
60+
SnippetWorkspaceEdit {
61+
changes: Some(
62+
{
63+
"file:///test/driver/subcommand/repl.rs": [
64+
TextEdit {
65+
range: Range {
66+
start: Position {
67+
line: 290,
68+
character: 8,
69+
},
70+
end: Position {
71+
line: 290,
72+
character: 11,
73+
},
74+
},
75+
new_text: "_foo",
76+
},
77+
],
78+
},
79+
),
80+
document_changes: None,
81+
},
82+
),
83+
},
84+
],
85+
},
86+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
source: crates/rust-analyzer/src/diagnostics/to_proto.rs
3+
expression: diag
4+
---
5+
[
6+
MappedRustDiagnostic {
7+
location: Location {
8+
uri: "file:///test/driver/subcommand/repl.rs",
9+
range: Range {
10+
start: Position {
11+
line: 290,
12+
character: 8,
13+
},
14+
end: Position {
15+
line: 290,
16+
character: 11,
17+
},
18+
},
19+
},
20+
diagnostic: Diagnostic {
21+
range: Range {
22+
start: Position {
23+
line: 290,
24+
character: 8,
25+
},
26+
end: Position {
27+
line: 290,
28+
character: 11,
29+
},
30+
},
31+
severity: Some(
32+
Information,
33+
),
34+
code: Some(
35+
String(
36+
"unused_variables",
37+
),
38+
),
39+
source: Some(
40+
"rustc",
41+
),
42+
message: "unused variable: `foo`\n#[warn(unused_variables)] on by default",
43+
related_information: None,
44+
tags: Some(
45+
[
46+
Unnecessary,
47+
],
48+
),
49+
},
50+
fixes: [
51+
CodeAction {
52+
title: "consider prefixing with an underscore",
53+
id: None,
54+
group: None,
55+
kind: Some(
56+
"quickfix",
57+
),
58+
command: None,
59+
edit: Some(
60+
SnippetWorkspaceEdit {
61+
changes: Some(
62+
{
63+
"file:///test/driver/subcommand/repl.rs": [
64+
TextEdit {
65+
range: Range {
66+
start: Position {
67+
line: 290,
68+
character: 8,
69+
},
70+
end: Position {
71+
line: 290,
72+
character: 11,
73+
},
74+
},
75+
new_text: "_foo",
76+
},
77+
],
78+
},
79+
),
80+
document_changes: None,
81+
},
82+
),
83+
},
84+
],
85+
},
86+
]

0 commit comments

Comments
 (0)