From 0c54921f9398df5d181ade11520072baadb36859 Mon Sep 17 00:00:00 2001 From: yipinliu Date: Sat, 12 Mar 2022 20:36:56 +0800 Subject: [PATCH] Fixed code style issues --- crates/ide/src/syntax_highlighting.rs | 25 ++++++---- .../test_data/highlight_byte_string.html | 47 ------------------- .../test_data/highlight_strings.html | 3 ++ crates/ide/src/syntax_highlighting/tests.rs | 17 ++----- 4 files changed, 21 insertions(+), 71 deletions(-) delete mode 100644 crates/ide/src/syntax_highlighting/test_data/highlight_byte_string.html diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 1bd95c4c437..8f764e33367 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -375,18 +375,23 @@ fn traverse( if let (Some(token), Some(descended_token)) = (token, descended_element.as_token()) { if ast::String::can_cast(token.kind()) && ast::String::can_cast(descended_token.kind()) { - let string = ast::String::cast(token).unwrap(); - let expanded_string = ast::String::cast(descended_token.clone()).unwrap(); - if string.is_raw() { - if inject::ra_fixture(hl, sema, &string, &expanded_string).is_some() { - continue; + let string = ast::String::cast(token); + let string_to_highlight = ast::String::cast(descended_token.clone()); + if let Some((string, expanded_string)) = string.zip(string_to_highlight) { + if string.is_raw() { + if inject::ra_fixture(hl, sema, &string, &expanded_string).is_some() { + continue; + } } + highlight_format_string(hl, &string, &expanded_string, range); + highlight_escape_string(hl, &string, range.start()); + } + } else if ast::ByteString::can_cast(token.kind()) + && ast::ByteString::can_cast(descended_token.kind()) + { + if let Some(byte_string) = ast::ByteString::cast(token) { + highlight_escape_string(hl, &byte_string, range.start()); } - highlight_format_string(hl, &string, &expanded_string, range); - highlight_escape_string(hl, &string, range.start()); - } else if ast::ByteString::can_cast(token.kind()) { - let byte_string = ast::ByteString::cast(token).unwrap(); - highlight_escape_string(hl, &byte_string, range.start()); } } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_byte_string.html b/crates/ide/src/syntax_highlighting/test_data/highlight_byte_string.html deleted file mode 100644 index 113b73af0c4..00000000000 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_byte_string.html +++ /dev/null @@ -1,47 +0,0 @@ - - -
fn main() {
-    let _ = "\x28\x28\x00\x63\n";
-    let _ = b"\x28\x28\x00\x63\n";
-}
\ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index 07c7881a1f7..3715164bbf7 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html @@ -136,6 +136,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd println!("Hello\nWorld"); println!("\u{48}\x65\x6C\x6C\x6F World"); + let _ = "\x28\x28\x00\x63\n"; + let _ = b"\x28\x28\x00\x63\n"; + println!("{\x41}", A = 92); println!("{ничоси}", ничоси = 92); diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index f9c2404c358..a8c69875e0c 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -459,6 +459,9 @@ fn main() { println!("Hello\nWorld"); println!("\u{48}\x65\x6C\x6C\x6F World"); + let _ = "\x28\x28\x00\x63\n"; + let _ = b"\x28\x28\x00\x63\n"; + println!("{\x41}", A = 92); println!("{ничоси}", ничоси = 92); @@ -476,20 +479,6 @@ fn main() { ); } -#[test] -fn test_byte_string_highlight() { - check_highlighting( - r#" -fn main() { - let _ = "\x28\x28\x00\x63\n"; - let _ = b"\x28\x28\x00\x63\n"; -} -"#, - expect_file!["./test_data/highlight_byte_string.html"], - false, - ); -} - #[test] fn test_unsafe_highlighting() { check_highlighting(