Use Project::search
in ProjectFind
and show search results
This commit is contained in:
parent
5644336df3
commit
0bf944e038
12 changed files with 484 additions and 336 deletions
|
@ -7,8 +7,9 @@ use collections::{Bound, HashMap, HashSet};
|
|||
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
||||
pub use language::Completion;
|
||||
use language::{
|
||||
Buffer, BufferChunks, BufferSnapshot, Chunk, DiagnosticEntry, Event, File, Language, Outline,
|
||||
OutlineItem, Selection, ToOffset as _, ToPoint as _, ToPointUtf16 as _, TransactionId,
|
||||
char_kind, Buffer, BufferChunks, BufferSnapshot, CharKind, Chunk, DiagnosticEntry, Event, File,
|
||||
Language, Outline, OutlineItem, Selection, ToOffset as _, ToPoint as _, ToPointUtf16 as _,
|
||||
TransactionId,
|
||||
};
|
||||
use std::{
|
||||
cell::{Ref, RefCell},
|
||||
|
@ -50,14 +51,6 @@ struct History {
|
|||
group_interval: Duration,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)]
|
||||
pub enum CharKind {
|
||||
Newline,
|
||||
Punctuation,
|
||||
Whitespace,
|
||||
Word,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Transaction {
|
||||
id: TransactionId,
|
||||
|
@ -102,6 +95,7 @@ pub struct MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub struct ExcerptBoundary {
|
||||
pub id: ExcerptId,
|
||||
pub row: u32,
|
||||
pub buffer: BufferSnapshot,
|
||||
pub range: Range<text::Anchor>,
|
||||
|
@ -773,6 +767,21 @@ impl MultiBuffer {
|
|||
ids
|
||||
}
|
||||
|
||||
pub fn clear(&mut self, cx: &mut ModelContext<Self>) {
|
||||
self.buffers.borrow_mut().clear();
|
||||
let mut snapshot = self.snapshot.borrow_mut();
|
||||
let prev_len = snapshot.len();
|
||||
snapshot.excerpts = Default::default();
|
||||
snapshot.trailing_excerpt_update_count += 1;
|
||||
snapshot.is_dirty = false;
|
||||
snapshot.has_conflict = false;
|
||||
self.subscriptions.publish_mut([Edit {
|
||||
old: 0..prev_len,
|
||||
new: 0..0,
|
||||
}]);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn excerpt_ids_for_buffer(&self, buffer: &ModelHandle<Buffer>) -> Vec<ExcerptId> {
|
||||
self.buffers
|
||||
.borrow()
|
||||
|
@ -1342,9 +1351,12 @@ impl MultiBufferSnapshot {
|
|||
(start..end, word_kind)
|
||||
}
|
||||
|
||||
fn as_singleton(&self) -> Option<&Excerpt> {
|
||||
pub fn as_singleton(&self) -> Option<(&ExcerptId, usize, &BufferSnapshot)> {
|
||||
if self.singleton {
|
||||
self.excerpts.iter().next()
|
||||
self.excerpts
|
||||
.iter()
|
||||
.next()
|
||||
.map(|e| (&e.id, e.buffer_id, &e.buffer))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -1359,8 +1371,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn clip_offset(&self, offset: usize, bias: Bias) -> usize {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.clip_offset(offset, bias);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.clip_offset(offset, bias);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<usize>();
|
||||
|
@ -1378,8 +1390,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn clip_point(&self, point: Point, bias: Bias) -> Point {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.clip_point(point, bias);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.clip_point(point, bias);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<Point>();
|
||||
|
@ -1397,8 +1409,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn clip_point_utf16(&self, point: PointUtf16, bias: Bias) -> PointUtf16 {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.clip_point_utf16(point, bias);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.clip_point_utf16(point, bias);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<PointUtf16>();
|
||||
|
@ -1466,8 +1478,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn offset_to_point(&self, offset: usize) -> Point {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.offset_to_point(offset);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.offset_to_point(offset);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(usize, Point)>();
|
||||
|
@ -1487,8 +1499,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn offset_to_point_utf16(&self, offset: usize) -> PointUtf16 {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.offset_to_point_utf16(offset);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.offset_to_point_utf16(offset);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(usize, PointUtf16)>();
|
||||
|
@ -1508,8 +1520,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn point_to_point_utf16(&self, point: Point) -> PointUtf16 {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.point_to_point_utf16(point);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.point_to_point_utf16(point);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(Point, PointUtf16)>();
|
||||
|
@ -1529,8 +1541,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn point_to_offset(&self, point: Point) -> usize {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.point_to_offset(point);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.point_to_offset(point);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(Point, usize)>();
|
||||
|
@ -1550,8 +1562,8 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn point_utf16_to_offset(&self, point: PointUtf16) -> usize {
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt.buffer.point_utf16_to_offset(point);
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer.point_utf16_to_offset(point);
|
||||
}
|
||||
|
||||
let mut cursor = self.excerpts.cursor::<(PointUtf16, usize)>();
|
||||
|
@ -1711,9 +1723,8 @@ impl MultiBufferSnapshot {
|
|||
D: TextDimension + Ord + Sub<D, Output = D>,
|
||||
I: 'a + IntoIterator<Item = &'a Anchor>,
|
||||
{
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
return excerpt
|
||||
.buffer
|
||||
if let Some((_, _, buffer)) = self.as_singleton() {
|
||||
return buffer
|
||||
.summaries_for_anchors(anchors.into_iter().map(|a| &a.text_anchor))
|
||||
.collect();
|
||||
}
|
||||
|
@ -1878,11 +1889,11 @@ impl MultiBufferSnapshot {
|
|||
|
||||
pub fn anchor_at<T: ToOffset>(&self, position: T, mut bias: Bias) -> Anchor {
|
||||
let offset = position.to_offset(self);
|
||||
if let Some(excerpt) = self.as_singleton() {
|
||||
if let Some((excerpt_id, buffer_id, buffer)) = self.as_singleton() {
|
||||
return Anchor {
|
||||
buffer_id: Some(excerpt.buffer_id),
|
||||
excerpt_id: excerpt.id.clone(),
|
||||
text_anchor: excerpt.buffer.anchor_at(offset, bias),
|
||||
buffer_id: Some(buffer_id),
|
||||
excerpt_id: excerpt_id.clone(),
|
||||
text_anchor: buffer.anchor_at(offset, bias),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1989,6 +2000,7 @@ impl MultiBufferSnapshot {
|
|||
let excerpt = cursor.item()?;
|
||||
let starts_new_buffer = Some(excerpt.buffer_id) != prev_buffer_id;
|
||||
let boundary = ExcerptBoundary {
|
||||
id: excerpt.id.clone(),
|
||||
row: cursor.start().1.row,
|
||||
buffer: excerpt.buffer.clone(),
|
||||
range: excerpt.range.clone(),
|
||||
|
@ -2090,7 +2102,7 @@ impl MultiBufferSnapshot {
|
|||
{
|
||||
self.as_singleton()
|
||||
.into_iter()
|
||||
.flat_map(move |excerpt| excerpt.buffer.diagnostic_group(group_id))
|
||||
.flat_map(move |(_, _, buffer)| buffer.diagnostic_group(group_id))
|
||||
}
|
||||
|
||||
pub fn diagnostics_in_range<'a, T, O>(
|
||||
|
@ -2101,11 +2113,11 @@ impl MultiBufferSnapshot {
|
|||
T: 'a + ToOffset,
|
||||
O: 'a + text::FromAnchor,
|
||||
{
|
||||
self.as_singleton().into_iter().flat_map(move |excerpt| {
|
||||
excerpt
|
||||
.buffer
|
||||
.diagnostics_in_range(range.start.to_offset(self)..range.end.to_offset(self))
|
||||
})
|
||||
self.as_singleton()
|
||||
.into_iter()
|
||||
.flat_map(move |(_, _, buffer)| {
|
||||
buffer.diagnostics_in_range(range.start.to_offset(self)..range.end.to_offset(self))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn range_for_syntax_ancestor<T: ToOffset>(&self, range: Range<T>) -> Option<Range<usize>> {
|
||||
|
@ -2147,16 +2159,16 @@ impl MultiBufferSnapshot {
|
|||
}
|
||||
|
||||
pub fn outline(&self, theme: Option<&SyntaxTheme>) -> Option<Outline<Anchor>> {
|
||||
let excerpt = self.as_singleton()?;
|
||||
let outline = excerpt.buffer.outline(theme)?;
|
||||
let (excerpt_id, _, buffer) = self.as_singleton()?;
|
||||
let outline = buffer.outline(theme)?;
|
||||
Some(Outline::new(
|
||||
outline
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|item| OutlineItem {
|
||||
depth: item.depth,
|
||||
range: self.anchor_in_excerpt(excerpt.id.clone(), item.range.start)
|
||||
..self.anchor_in_excerpt(excerpt.id.clone(), item.range.end),
|
||||
range: self.anchor_in_excerpt(excerpt_id.clone(), item.range.start)
|
||||
..self.anchor_in_excerpt(excerpt_id.clone(), item.range.end),
|
||||
text: item.text,
|
||||
highlight_ranges: item.highlight_ranges,
|
||||
name_ranges: item.name_ranges,
|
||||
|
@ -2764,18 +2776,6 @@ impl ToPointUtf16 for PointUtf16 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn char_kind(c: char) -> CharKind {
|
||||
if c == '\n' {
|
||||
CharKind::Newline
|
||||
} else if c.is_whitespace() {
|
||||
CharKind::Whitespace
|
||||
} else if c.is_alphanumeric() || c == '_' {
|
||||
CharKind::Word
|
||||
} else {
|
||||
CharKind::Punctuation
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue