diff --git a/src/actions/compiler_message_parsing.rs b/src/actions/compiler_message_parsing.rs index 9558d741b22..276d4192f2a 100644 --- a/src/actions/compiler_message_parsing.rs +++ b/src/actions/compiler_message_parsing.rs @@ -105,7 +105,13 @@ pub fn parse(message: &str) -> Result { 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 { diff --git a/src/test/mod.rs b/src/test/mod.rs index 504e12c0084..1a4171c802b 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -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")]); } diff --git a/test_data/mismatched_types/Cargo.lock b/test_data/mismatched_types/Cargo.lock new file mode 100644 index 00000000000..5bf0f8d4c9d --- /dev/null +++ b/test_data/mismatched_types/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "mismatched_types" +version = "0.1.0" + diff --git a/test_data/mismatched_types/Cargo.toml b/test_data/mismatched_types/Cargo.toml new file mode 100644 index 00000000000..11ca40702be --- /dev/null +++ b/test_data/mismatched_types/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "mismatched_types" +version = "0.1.0" +authors = ["Nelson Chen "] + +[dependencies] diff --git a/test_data/mismatched_types/src/main.rs b/test_data/mismatched_types/src/main.rs new file mode 100644 index 00000000000..cfdc9cb3a48 --- /dev/null +++ b/test_data/mismatched_types/src/main.rs @@ -0,0 +1,8 @@ +fn main() { + let a_string = "hoop"; + u32_only(a_string); +} + +fn u32_only(i: u32) -> u32 { + i +}