Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Append the label value of the primary spans of diagnostics to the LSP diagnostics message if it is available. #447

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/actions/compiler_message_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ pub fn parse(message: &str) -> Result<FileDiagnostic, ParseError> {
None => String::new(),
})),
source: Some("rustc".into()),
message: message.message,
message: {
if let Some(label) = primary.label {
format!("{}\n{}", message.message, label)
} else {
message.message
}
},
};

Ok(FileDiagnostic {
Expand Down
21 changes: 20 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,26 @@ fn test_borrow_error() {
ls_server::ServerStateChange::Continue);
expect_messages(results.clone(), &[ExpectedMessage::new(Some(0)).expect_contains("capabilities"),
ExpectedMessage::new(None).expect_contains("diagnosticsBegin"),
ExpectedMessage::new(None).expect_contains(r#""message":"cannot borrow `x` as mutable more than once at a time""#),
ExpectedMessage::new(None).expect_contains(r#""message":"cannot borrow `x` as mutable more than once at a time\nsecond mutable borrow occurs here""#),
ExpectedMessage::new(None).expect_contains("diagnosticsEnd")]);
}

#[test]
fn test_mismatched_types() {
let (cache, _tc) = init_env("mismatched_types");

let root_path = cache.abs_path(Path::new("."));
let messages = vec![
ServerMessage::initialize(0, root_path.as_os_str().to_str().map(|x| x.to_owned()))
];

let (mut server, results) = mock_server(messages);
// Initialise and build.
assert_eq!(ls_server::LsService::handle_message(&mut server),
ls_server::ServerStateChange::Continue);
expect_messages(results.clone(), &[ExpectedMessage::new(Some(0)).expect_contains("capabilities"),
ExpectedMessage::new(None).expect_contains("diagnosticsBegin"),
ExpectedMessage::new(None).expect_contains(r#""message":"mismatched types\nexpected u32, found &str""#),
ExpectedMessage::new(None).expect_contains("diagnosticsEnd")]);
}

Expand Down
4 changes: 4 additions & 0 deletions test_data/mismatched_types/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test_data/mismatched_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "mismatched_types"
version = "0.1.0"
authors = ["Nelson Chen <crazysim@gmail.com>"]

[dependencies]
8 changes: 8 additions & 0 deletions test_data/mismatched_types/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn main() {
let a_string = "hoop";
u32_only(a_string);
}

fn u32_only(i: u32) -> u32 {
i
}