mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-27 10:59:53 +00:00
fix bracket ranges failing test
This commit is contained in:
parent
57a7ff9a6f
commit
5e4d113308
5 changed files with 31 additions and 7 deletions
|
@ -2346,7 +2346,7 @@ impl BufferSnapshot {
|
||||||
Some(items)
|
Some(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns bracket range pairs overlapping `range`
|
/// Returns bracket range pairs overlapping or adjacent to `range`
|
||||||
pub fn bracket_ranges<'a, T: ToOffset>(
|
pub fn bracket_ranges<'a, T: ToOffset>(
|
||||||
&'a self,
|
&'a self,
|
||||||
range: Range<T>,
|
range: Range<T>,
|
||||||
|
@ -2355,7 +2355,7 @@ impl BufferSnapshot {
|
||||||
let range = range.start.to_offset(self).saturating_sub(1)
|
let range = range.start.to_offset(self).saturating_sub(1)
|
||||||
..self.len().min(range.end.to_offset(self) + 1);
|
..self.len().min(range.end.to_offset(self) + 1);
|
||||||
|
|
||||||
let mut matches = self.syntax.matches(range, &self.text, |grammar| {
|
let mut matches = self.syntax.matches(range.clone(), &self.text, |grammar| {
|
||||||
grammar.brackets_config.as_ref().map(|c| &c.query)
|
grammar.brackets_config.as_ref().map(|c| &c.query)
|
||||||
});
|
});
|
||||||
let configs = matches
|
let configs = matches
|
||||||
|
@ -2380,6 +2380,12 @@ impl BufferSnapshot {
|
||||||
matches.advance();
|
matches.advance();
|
||||||
|
|
||||||
let Some((open, close)) = open.zip(close) else { continue };
|
let Some((open, close)) = open.zip(close) else { continue };
|
||||||
|
|
||||||
|
let bracket_range = open.start..=close.end;
|
||||||
|
if !bracket_range.contains(&range.start) && !bracket_range.contains(&range.end) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return Some((open, close));
|
return Some((open, close));
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
|
@ -578,7 +578,7 @@ async fn test_symbols_containing(cx: &mut gpui::TestAppContext) {
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
fn test_enclosing_bracket_ranges(cx: &mut MutableAppContext) {
|
fn test_enclosing_bracket_ranges(cx: &mut MutableAppContext) {
|
||||||
let mut assert = |selection_text, range_markers| {
|
let mut assert = |selection_text, range_markers| {
|
||||||
assert_enclosing_bracket_pairs(selection_text, range_markers, rust_lang(), cx)
|
assert_bracket_pairs(selection_text, range_markers, rust_lang(), cx)
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
|
@ -696,7 +696,7 @@ fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(
|
||||||
cx: &mut MutableAppContext,
|
cx: &mut MutableAppContext,
|
||||||
) {
|
) {
|
||||||
let mut assert = |selection_text, bracket_pair_texts| {
|
let mut assert = |selection_text, bracket_pair_texts| {
|
||||||
assert_enclosing_bracket_pairs(selection_text, bracket_pair_texts, javascript_lang(), cx)
|
assert_bracket_pairs(selection_text, bracket_pair_texts, javascript_lang(), cx)
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
|
@ -710,6 +710,7 @@ fn test_enclosing_bracket_ranges_where_brackets_are_not_outermost_children(
|
||||||
}"}],
|
}"}],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
eprintln!("-----------------------");
|
||||||
// Regression test: even though the parent node of the parentheses (the for loop) does
|
// Regression test: even though the parent node of the parentheses (the for loop) does
|
||||||
// intersect the given range, the parentheses themselves do not contain the range, so
|
// intersect the given range, the parentheses themselves do not contain the range, so
|
||||||
// they should not be returned. Only the curly braces contain the range.
|
// they should not be returned. Only the curly braces contain the range.
|
||||||
|
@ -2047,7 +2048,7 @@ fn get_tree_sexp(buffer: &ModelHandle<Buffer>, cx: &gpui::TestAppContext) -> Str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that the enclosing bracket ranges around the selection match the pairs indicated by the marked text in `range_markers`
|
// Assert that the enclosing bracket ranges around the selection match the pairs indicated by the marked text in `range_markers`
|
||||||
fn assert_enclosing_bracket_pairs(
|
fn assert_bracket_pairs(
|
||||||
selection_text: &'static str,
|
selection_text: &'static str,
|
||||||
bracket_pair_texts: Vec<&'static str>,
|
bracket_pair_texts: Vec<&'static str>,
|
||||||
language: Language,
|
language: Language,
|
||||||
|
|
|
@ -5,6 +5,7 @@ edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
path = "src/util.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -22,7 +23,6 @@ serde_json = { version = "1.0", features = ["preserve_order"], optional = true }
|
||||||
git2 = { version = "0.15", default-features = false, optional = true }
|
git2 = { version = "0.15", default-features = false, optional = true }
|
||||||
dirs = "3.0"
|
dirs = "3.0"
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempdir = { version = "0.3.7" }
|
tempdir = { version = "0.3.7" }
|
||||||
serde_json = { version = "1.0", features = ["preserve_order"] }
|
serde_json = { version = "1.0", features = ["preserve_order"] }
|
||||||
|
|
|
@ -101,6 +101,7 @@ actions!(
|
||||||
NewTerminal,
|
NewTerminal,
|
||||||
NewSearch,
|
NewSearch,
|
||||||
Feedback,
|
Feedback,
|
||||||
|
Restart
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1329,7 +1330,19 @@ impl Workspace {
|
||||||
focus_item: bool,
|
focus_item: bool,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> {
|
) -> Task<Result<Box<dyn ItemHandle>, anyhow::Error>> {
|
||||||
let pane = pane.unwrap_or_else(|| self.active_pane().downgrade());
|
let pane = pane.unwrap_or_else(|| {
|
||||||
|
if !self.dock_active() {
|
||||||
|
self.active_pane().downgrade()
|
||||||
|
} else {
|
||||||
|
self.last_active_center_pane.clone().unwrap_or_else(|| {
|
||||||
|
self.panes
|
||||||
|
.first()
|
||||||
|
.expect("There must be an active pane")
|
||||||
|
.downgrade()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let task = self.load_path(path.into(), cx);
|
let task = self.load_path(path.into(), cx);
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let (project_entry_id, build_item) = task.await?;
|
let (project_entry_id, build_item) = task.await?;
|
||||||
|
@ -1636,6 +1649,10 @@ impl Workspace {
|
||||||
self.dock.pane()
|
self.dock.pane()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dock_active(&self) -> bool {
|
||||||
|
&self.active_pane == self.dock.pane()
|
||||||
|
}
|
||||||
|
|
||||||
fn project_remote_id_changed(&mut self, remote_id: Option<u64>, cx: &mut ViewContext<Self>) {
|
fn project_remote_id_changed(&mut self, remote_id: Option<u64>, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(remote_id) = remote_id {
|
if let Some(remote_id) = remote_id {
|
||||||
self.remote_entity_subscription =
|
self.remote_entity_subscription =
|
||||||
|
|
Loading…
Reference in a new issue