highlight_matching_bracket.rs

  1use gpui::ViewContext;
  2
  3use crate::{Editor, RangeToAnchorExt};
  4
  5enum MatchingBracketHighlight {}
  6
  7pub fn refresh_matching_bracket_highlights(editor: &mut Editor, cx: &mut ViewContext<Editor>) {
  8    todo!()
  9    // // editor.clear_background_highlights::<MatchingBracketHighlight>(cx);
 10
 11    // let newest_selection = editor.selections.newest::<usize>(cx);
 12    // // Don't highlight brackets if the selection isn't empty
 13    // if !newest_selection.is_empty() {
 14    //     return;
 15    // }
 16
 17    // let head = newest_selection.head();
 18    // let snapshot = editor.snapshot(cx);
 19    // if let Some((opening_range, closing_range)) = snapshot
 20    //     .buffer_snapshot
 21    //     .innermost_enclosing_bracket_ranges(head..head)
 22    // {
 23    //     editor.highlight_background::<MatchingBracketHighlight>(
 24    //         vec![
 25    //             opening_range.to_anchors(&snapshot.buffer_snapshot),
 26    //             closing_range.to_anchors(&snapshot.buffer_snapshot),
 27    //         ],
 28    //         |theme| theme.editor.document_highlight_read_background,
 29    //         cx,
 30    //     )
 31    // }
 32}
 33
 34// #[cfg(test)]
 35// mod tests {
 36//     use super::*;
 37//     use crate::{editor_tests::init_test, test::editor_lsp_test_context::EditorLspTestContext};
 38//     use indoc::indoc;
 39//     use language::{BracketPair, BracketPairConfig, Language, LanguageConfig};
 40
 41//     #[gpui::test]
 42//     async fn test_matching_bracket_highlights(cx: &mut gpui::TestAppContext) {
 43//         init_test(cx, |_| {});
 44
 45//         let mut cx = EditorLspTestContext::new(
 46//             Language::new(
 47//                 LanguageConfig {
 48//                     name: "Rust".into(),
 49//                     path_suffixes: vec!["rs".to_string()],
 50//                     brackets: BracketPairConfig {
 51//                         pairs: vec![
 52//                             BracketPair {
 53//                                 start: "{".to_string(),
 54//                                 end: "}".to_string(),
 55//                                 close: false,
 56//                                 newline: true,
 57//                             },
 58//                             BracketPair {
 59//                                 start: "(".to_string(),
 60//                                 end: ")".to_string(),
 61//                                 close: false,
 62//                                 newline: true,
 63//                             },
 64//                         ],
 65//                         ..Default::default()
 66//                     },
 67//                     ..Default::default()
 68//                 },
 69//                 Some(tree_sitter_rust::language()),
 70//             )
 71//             .with_brackets_query(indoc! {r#"
 72//                 ("{" @open "}" @close)
 73//                 ("(" @open ")" @close)
 74//                 "#})
 75//             .unwrap(),
 76//             Default::default(),
 77//             cx,
 78//         )
 79//         .await;
 80
 81//         // positioning cursor inside bracket highlights both
 82//         cx.set_state(indoc! {r#"
 83//             pub fn test("Test ˇargument") {
 84//                 another_test(1, 2, 3);
 85//             }
 86//         "#});
 87//         cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"
 88//             pub fn test«(»"Test argument"«)» {
 89//                 another_test(1, 2, 3);
 90//             }
 91//         "#});
 92
 93//         cx.set_state(indoc! {r#"
 94//             pub fn test("Test argument") {
 95//                 another_test(1, ˇ2, 3);
 96//             }
 97//         "#});
 98//         cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"
 99//             pub fn test("Test argument") {
100//                 another_test«(»1, 2, 3«)»;
101//             }
102//         "#});
103
104//         cx.set_state(indoc! {r#"
105//             pub fn test("Test argument") {
106//                 anotherˇ_test(1, 2, 3);
107//             }
108//         "#});
109//         cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"
110//             pub fn test("Test argument") «{»
111//                 another_test(1, 2, 3);
112//             «}»
113//         "#});
114
115//         // positioning outside of brackets removes highlight
116//         cx.set_state(indoc! {r#"
117//             pub fˇn test("Test argument") {
118//                 another_test(1, 2, 3);
119//             }
120//         "#});
121//         cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"
122//             pub fn test("Test argument") {
123//                 another_test(1, 2, 3);
124//             }
125//         "#});
126
127//         // non empty selection dismisses highlight
128//         cx.set_state(indoc! {r#"
129//             pub fn test("Te«st argˇ»ument") {
130//                 another_test(1, 2, 3);
131//             }
132//         "#});
133//         cx.assert_editor_background_highlights::<MatchingBracketHighlight>(indoc! {r#"
134//             pub fn test("Test argument") {
135//                 another_test(1, 2, 3);
136//             }
137//         "#});
138//     }
139// }