editor: Shrink size of Inlay slightly (#39089)
And some other smaller cleanup things I noticed while reading through some stuff Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -76,7 +76,7 @@ pub enum MessageEditorEvent {
|
|||||||
|
|
||||||
impl EventEmitter<MessageEditorEvent> for MessageEditor {}
|
impl EventEmitter<MessageEditorEvent> for MessageEditor {}
|
||||||
|
|
||||||
const COMMAND_HINT_INLAY_ID: usize = 0;
|
const COMMAND_HINT_INLAY_ID: u32 = 0;
|
||||||
|
|
||||||
impl MessageEditor {
|
impl MessageEditor {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
|||||||
@@ -1443,11 +1443,7 @@ impl<'a> Iterator for FoldChunks<'a> {
|
|||||||
[(self.inlay_offset - buffer_chunk_start).0..(chunk_end - buffer_chunk_start).0];
|
[(self.inlay_offset - buffer_chunk_start).0..(chunk_end - buffer_chunk_start).0];
|
||||||
|
|
||||||
let bit_end = (chunk_end - buffer_chunk_start).0;
|
let bit_end = (chunk_end - buffer_chunk_start).0;
|
||||||
let mask = if bit_end >= 128 {
|
let mask = 1u128.unbounded_shl(bit_end as u32).wrapping_sub(1);
|
||||||
u128::MAX
|
|
||||||
} else {
|
|
||||||
(1u128 << bit_end) - 1
|
|
||||||
};
|
|
||||||
|
|
||||||
chunk.tabs = (chunk.tabs >> (self.inlay_offset - buffer_chunk_start).0) & mask;
|
chunk.tabs = (chunk.tabs >> (self.inlay_offset - buffer_chunk_start).0) & mask;
|
||||||
chunk.chars = (chunk.chars >> (self.inlay_offset - buffer_chunk_start).0) & mask;
|
chunk.chars = (chunk.chars >> (self.inlay_offset - buffer_chunk_start).0) & mask;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use multi_buffer::{
|
|||||||
use std::{
|
use std::{
|
||||||
cmp,
|
cmp,
|
||||||
ops::{Add, AddAssign, Range, Sub, SubAssign},
|
ops::{Add, AddAssign, Range, Sub, SubAssign},
|
||||||
sync::Arc,
|
sync::{Arc, OnceLock},
|
||||||
};
|
};
|
||||||
use sum_tree::{Bias, Cursor, Dimensions, SumTree};
|
use sum_tree::{Bias, Cursor, Dimensions, SumTree};
|
||||||
use text::{ChunkBitmaps, Patch, Rope};
|
use text::{ChunkBitmaps, Patch, Rope};
|
||||||
@@ -41,12 +41,17 @@ enum Transform {
|
|||||||
pub struct Inlay {
|
pub struct Inlay {
|
||||||
pub id: InlayId,
|
pub id: InlayId,
|
||||||
pub position: Anchor,
|
pub position: Anchor,
|
||||||
pub text: text::Rope,
|
pub content: InlayContent,
|
||||||
color: Option<Hsla>,
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum InlayContent {
|
||||||
|
Text(text::Rope),
|
||||||
|
Color(Hsla),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Inlay {
|
impl Inlay {
|
||||||
pub fn hint(id: usize, position: Anchor, hint: &project::InlayHint) -> Self {
|
pub fn hint(id: u32, position: Anchor, hint: &project::InlayHint) -> Self {
|
||||||
let mut text = hint.text();
|
let mut text = hint.text();
|
||||||
if hint.padding_right && text.reversed_chars_at(text.len()).next() != Some(' ') {
|
if hint.padding_right && text.reversed_chars_at(text.len()).next() != Some(' ') {
|
||||||
text.push(" ");
|
text.push(" ");
|
||||||
@@ -57,51 +62,57 @@ impl Inlay {
|
|||||||
Self {
|
Self {
|
||||||
id: InlayId::Hint(id),
|
id: InlayId::Hint(id),
|
||||||
position,
|
position,
|
||||||
text,
|
content: InlayContent::Text(text),
|
||||||
color: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn mock_hint(id: usize, position: Anchor, text: impl Into<Rope>) -> Self {
|
pub fn mock_hint(id: u32, position: Anchor, text: impl Into<Rope>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: InlayId::Hint(id),
|
id: InlayId::Hint(id),
|
||||||
position,
|
position,
|
||||||
text: text.into(),
|
content: InlayContent::Text(text.into()),
|
||||||
color: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn color(id: usize, position: Anchor, color: Rgba) -> Self {
|
pub fn color(id: u32, position: Anchor, color: Rgba) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: InlayId::Color(id),
|
id: InlayId::Color(id),
|
||||||
position,
|
position,
|
||||||
text: Rope::from("◼"),
|
content: InlayContent::Color(color.into()),
|
||||||
color: Some(Hsla::from(color)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn edit_prediction<T: Into<Rope>>(id: usize, position: Anchor, text: T) -> Self {
|
pub fn edit_prediction<T: Into<Rope>>(id: u32, position: Anchor, text: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: InlayId::EditPrediction(id),
|
id: InlayId::EditPrediction(id),
|
||||||
position,
|
position,
|
||||||
text: text.into(),
|
content: InlayContent::Text(text.into()),
|
||||||
color: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn debugger<T: Into<Rope>>(id: usize, position: Anchor, text: T) -> Self {
|
pub fn debugger<T: Into<Rope>>(id: u32, position: Anchor, text: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: InlayId::DebuggerValue(id),
|
id: InlayId::DebuggerValue(id),
|
||||||
position,
|
position,
|
||||||
text: text.into(),
|
content: InlayContent::Text(text.into()),
|
||||||
color: None,
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn text(&self) -> &Rope {
|
||||||
|
static COLOR_TEXT: OnceLock<Rope> = OnceLock::new();
|
||||||
|
match &self.content {
|
||||||
|
InlayContent::Text(text) => text,
|
||||||
|
InlayContent::Color(_) => COLOR_TEXT.get_or_init(|| Rope::from("◼")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn get_color(&self) -> Option<Hsla> {
|
pub fn get_color(&self) -> Option<Hsla> {
|
||||||
self.color
|
match self.content {
|
||||||
|
InlayContent::Color(color) => Some(color),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +127,7 @@ impl sum_tree::Item for Transform {
|
|||||||
},
|
},
|
||||||
Transform::Inlay(inlay) => TransformSummary {
|
Transform::Inlay(inlay) => TransformSummary {
|
||||||
input: TextSummary::default(),
|
input: TextSummary::default(),
|
||||||
output: inlay.text.summary(),
|
output: inlay.text().summary(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -354,7 +365,7 @@ impl<'a> Iterator for InlayChunks<'a> {
|
|||||||
let mut renderer = None;
|
let mut renderer = None;
|
||||||
let mut highlight_style = match inlay.id {
|
let mut highlight_style = match inlay.id {
|
||||||
InlayId::EditPrediction(_) => self.highlight_styles.edit_prediction.map(|s| {
|
InlayId::EditPrediction(_) => self.highlight_styles.edit_prediction.map(|s| {
|
||||||
if inlay.text.chars().all(|c| c.is_whitespace()) {
|
if inlay.text().chars().all(|c| c.is_whitespace()) {
|
||||||
s.whitespace
|
s.whitespace
|
||||||
} else {
|
} else {
|
||||||
s.insertion
|
s.insertion
|
||||||
@@ -363,7 +374,7 @@ impl<'a> Iterator for InlayChunks<'a> {
|
|||||||
InlayId::Hint(_) => self.highlight_styles.inlay_hint,
|
InlayId::Hint(_) => self.highlight_styles.inlay_hint,
|
||||||
InlayId::DebuggerValue(_) => self.highlight_styles.inlay_hint,
|
InlayId::DebuggerValue(_) => self.highlight_styles.inlay_hint,
|
||||||
InlayId::Color(_) => {
|
InlayId::Color(_) => {
|
||||||
if let Some(color) = inlay.color {
|
if let InlayContent::Color(color) = inlay.content {
|
||||||
renderer = Some(ChunkRenderer {
|
renderer = Some(ChunkRenderer {
|
||||||
id: ChunkRendererId::Inlay(inlay.id),
|
id: ChunkRendererId::Inlay(inlay.id),
|
||||||
render: Arc::new(move |cx| {
|
render: Arc::new(move |cx| {
|
||||||
@@ -410,7 +421,7 @@ impl<'a> Iterator for InlayChunks<'a> {
|
|||||||
let start = offset_in_inlay;
|
let start = offset_in_inlay;
|
||||||
let end = cmp::min(self.max_output_offset, self.transforms.end().0)
|
let end = cmp::min(self.max_output_offset, self.transforms.end().0)
|
||||||
- self.transforms.start().0;
|
- self.transforms.start().0;
|
||||||
let chunks = inlay.text.chunks_in_range(start.0..end.0);
|
let chunks = inlay.text().chunks_in_range(start.0..end.0);
|
||||||
text::ChunkWithBitmaps(chunks)
|
text::ChunkWithBitmaps(chunks)
|
||||||
});
|
});
|
||||||
let ChunkBitmaps {
|
let ChunkBitmaps {
|
||||||
@@ -706,7 +717,7 @@ impl InlayMap {
|
|||||||
|
|
||||||
for inlay_to_insert in to_insert {
|
for inlay_to_insert in to_insert {
|
||||||
// Avoid inserting empty inlays.
|
// Avoid inserting empty inlays.
|
||||||
if inlay_to_insert.text.is_empty() {
|
if inlay_to_insert.text().is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,7 +755,7 @@ impl InlayMap {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn randomly_mutate(
|
pub(crate) fn randomly_mutate(
|
||||||
&mut self,
|
&mut self,
|
||||||
next_inlay_id: &mut usize,
|
next_inlay_id: &mut u32,
|
||||||
rng: &mut rand::rngs::StdRng,
|
rng: &mut rand::rngs::StdRng,
|
||||||
) -> (InlaySnapshot, Vec<InlayEdit>) {
|
) -> (InlaySnapshot, Vec<InlayEdit>) {
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
@@ -822,7 +833,7 @@ impl InlaySnapshot {
|
|||||||
InlayPoint(cursor.start().1.0 + (buffer_end - buffer_start))
|
InlayPoint(cursor.start().1.0 + (buffer_end - buffer_start))
|
||||||
}
|
}
|
||||||
Some(Transform::Inlay(inlay)) => {
|
Some(Transform::Inlay(inlay)) => {
|
||||||
let overshoot = inlay.text.offset_to_point(overshoot);
|
let overshoot = inlay.text().offset_to_point(overshoot);
|
||||||
InlayPoint(cursor.start().1.0 + overshoot)
|
InlayPoint(cursor.start().1.0 + overshoot)
|
||||||
}
|
}
|
||||||
None => self.max_point(),
|
None => self.max_point(),
|
||||||
@@ -852,7 +863,7 @@ impl InlaySnapshot {
|
|||||||
InlayOffset(cursor.start().1.0 + (buffer_offset_end - buffer_offset_start))
|
InlayOffset(cursor.start().1.0 + (buffer_offset_end - buffer_offset_start))
|
||||||
}
|
}
|
||||||
Some(Transform::Inlay(inlay)) => {
|
Some(Transform::Inlay(inlay)) => {
|
||||||
let overshoot = inlay.text.point_to_offset(overshoot);
|
let overshoot = inlay.text().point_to_offset(overshoot);
|
||||||
InlayOffset(cursor.start().1.0 + overshoot)
|
InlayOffset(cursor.start().1.0 + overshoot)
|
||||||
}
|
}
|
||||||
None => self.len(),
|
None => self.len(),
|
||||||
@@ -1064,7 +1075,7 @@ impl InlaySnapshot {
|
|||||||
Some(Transform::Inlay(inlay)) => {
|
Some(Transform::Inlay(inlay)) => {
|
||||||
let suffix_start = overshoot;
|
let suffix_start = overshoot;
|
||||||
let suffix_end = cmp::min(cursor.end().0, range.end).0 - cursor.start().0.0;
|
let suffix_end = cmp::min(cursor.end().0, range.end).0 - cursor.start().0.0;
|
||||||
summary = inlay.text.cursor(suffix_start).summary(suffix_end);
|
summary = inlay.text().cursor(suffix_start).summary(suffix_end);
|
||||||
cursor.next();
|
cursor.next();
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
@@ -1086,7 +1097,7 @@ impl InlaySnapshot {
|
|||||||
}
|
}
|
||||||
Some(Transform::Inlay(inlay)) => {
|
Some(Transform::Inlay(inlay)) => {
|
||||||
let prefix_end = overshoot;
|
let prefix_end = overshoot;
|
||||||
summary += inlay.text.cursor(0).summary::<TextSummary>(prefix_end);
|
summary += inlay.text().cursor(0).summary::<TextSummary>(prefix_end);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
@@ -1269,7 +1280,7 @@ mod tests {
|
|||||||
resolve_state: ResolveState::Resolved,
|
resolve_state: ResolveState::Resolved,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.text
|
.text()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
"a",
|
"a",
|
||||||
"Should not pad label if not requested"
|
"Should not pad label if not requested"
|
||||||
@@ -1289,7 +1300,7 @@ mod tests {
|
|||||||
resolve_state: ResolveState::Resolved,
|
resolve_state: ResolveState::Resolved,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.text
|
.text()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
" a ",
|
" a ",
|
||||||
"Should pad label for every side requested"
|
"Should pad label for every side requested"
|
||||||
@@ -1309,7 +1320,7 @@ mod tests {
|
|||||||
resolve_state: ResolveState::Resolved,
|
resolve_state: ResolveState::Resolved,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.text
|
.text()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
" a ",
|
" a ",
|
||||||
"Should not change already padded label"
|
"Should not change already padded label"
|
||||||
@@ -1329,7 +1340,7 @@ mod tests {
|
|||||||
resolve_state: ResolveState::Resolved,
|
resolve_state: ResolveState::Resolved,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.text
|
.text()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
" a ",
|
" a ",
|
||||||
"Should not change already padded label"
|
"Should not change already padded label"
|
||||||
@@ -1352,7 +1363,7 @@ mod tests {
|
|||||||
resolve_state: ResolveState::Resolved,
|
resolve_state: ResolveState::Resolved,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.text
|
.text()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
" 🎨 ",
|
" 🎨 ",
|
||||||
"Should pad single emoji correctly"
|
"Should pad single emoji correctly"
|
||||||
@@ -1750,7 +1761,7 @@ mod tests {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut expected_text = Rope::from(&buffer_snapshot.text());
|
let mut expected_text = Rope::from(&buffer_snapshot.text());
|
||||||
for (offset, inlay) in inlays.iter().rev() {
|
for (offset, inlay) in inlays.iter().rev() {
|
||||||
expected_text.replace(*offset..*offset, &inlay.text.to_string());
|
expected_text.replace(*offset..*offset, &inlay.text().to_string());
|
||||||
}
|
}
|
||||||
assert_eq!(inlay_snapshot.text(), expected_text.to_string());
|
assert_eq!(inlay_snapshot.text(), expected_text.to_string());
|
||||||
|
|
||||||
@@ -1803,7 +1814,7 @@ mod tests {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|i| {
|
.filter_map(|i| {
|
||||||
let (_, inlay) = &inlays[i];
|
let (_, inlay) = &inlays[i];
|
||||||
let inlay_text_len = inlay.text.len();
|
let inlay_text_len = inlay.text().len();
|
||||||
match inlay_text_len {
|
match inlay_text_len {
|
||||||
0 => None,
|
0 => None,
|
||||||
1 => Some(InlayHighlight {
|
1 => Some(InlayHighlight {
|
||||||
@@ -1812,7 +1823,7 @@ mod tests {
|
|||||||
range: 0..1,
|
range: 0..1,
|
||||||
}),
|
}),
|
||||||
n => {
|
n => {
|
||||||
let inlay_text = inlay.text.to_string();
|
let inlay_text = inlay.text().to_string();
|
||||||
let mut highlight_end = rng.random_range(1..n);
|
let mut highlight_end = rng.random_range(1..n);
|
||||||
let mut highlight_start = rng.random_range(0..highlight_end);
|
let mut highlight_start = rng.random_range(0..highlight_end);
|
||||||
while !inlay_text.is_char_boundary(highlight_end) {
|
while !inlay_text.is_char_boundary(highlight_end) {
|
||||||
@@ -2138,8 +2149,7 @@ mod tests {
|
|||||||
let inlay = Inlay {
|
let inlay = Inlay {
|
||||||
id: InlayId::Hint(0),
|
id: InlayId::Hint(0),
|
||||||
position,
|
position,
|
||||||
text: text::Rope::from(inlay_text),
|
content: InlayContent::Text(text::Rope::from(inlay_text)),
|
||||||
color: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]);
|
let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]);
|
||||||
@@ -2253,8 +2263,7 @@ mod tests {
|
|||||||
let inlay = Inlay {
|
let inlay = Inlay {
|
||||||
id: InlayId::Hint(0),
|
id: InlayId::Hint(0),
|
||||||
position,
|
position,
|
||||||
text: text::Rope::from(test_case.inlay_text),
|
content: InlayContent::Text(text::Rope::from(test_case.inlay_text)),
|
||||||
color: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]);
|
let (inlay_snapshot, _) = inlay_map.splice(&[], vec![inlay]);
|
||||||
|
|||||||
@@ -53,9 +53,12 @@ pub fn replacement(c: char) -> Option<&'static str> {
|
|||||||
} else if contains(c, PRESERVE) {
|
} else if contains(c, PRESERVE) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some("\u{2007}") // fixed width space
|
Some(FIXED_WIDTH_SPACE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FIXED_WIDTH_SPACE: &str = "\u{2007}";
|
||||||
|
|
||||||
// IDEOGRAPHIC SPACE is common alongside Chinese and other wide character sets.
|
// IDEOGRAPHIC SPACE is common alongside Chinese and other wide character sets.
|
||||||
// We don't highlight this for now (as it already shows up wide in the editor),
|
// We don't highlight this for now (as it already shows up wide in the editor),
|
||||||
// but could if we tracked state in the classifier.
|
// but could if we tracked state in the classifier.
|
||||||
@@ -117,11 +120,11 @@ const PRESERVE: &[(char, char)] = &[
|
|||||||
];
|
];
|
||||||
|
|
||||||
fn contains(c: char, list: &[(char, char)]) -> bool {
|
fn contains(c: char, list: &[(char, char)]) -> bool {
|
||||||
for (start, end) in list {
|
for &(start, end) in list {
|
||||||
if c < *start {
|
if c < start {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if c <= *end {
|
if c <= end {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,9 +54,7 @@ impl TabMap {
|
|||||||
new_snapshot.version += 1;
|
new_snapshot.version += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut tab_edits = Vec::with_capacity(fold_edits.len());
|
let tab_edits = if old_snapshot.tab_size == new_snapshot.tab_size {
|
||||||
|
|
||||||
if old_snapshot.tab_size == new_snapshot.tab_size {
|
|
||||||
// Expand each edit to include the next tab on the same line as the edit,
|
// Expand each edit to include the next tab on the same line as the edit,
|
||||||
// and any subsequent tabs on that line that moved across the tab expansion
|
// and any subsequent tabs on that line that moved across the tab expansion
|
||||||
// boundary.
|
// boundary.
|
||||||
@@ -112,7 +110,7 @@ impl TabMap {
|
|||||||
let _old_alloc_ptr = fold_edits.as_ptr();
|
let _old_alloc_ptr = fold_edits.as_ptr();
|
||||||
// Combine any edits that overlap due to the expansion.
|
// Combine any edits that overlap due to the expansion.
|
||||||
let mut fold_edits = fold_edits.into_iter();
|
let mut fold_edits = fold_edits.into_iter();
|
||||||
let fold_edits = if let Some(mut first_edit) = fold_edits.next() {
|
if let Some(mut first_edit) = fold_edits.next() {
|
||||||
// This code relies on reusing allocations from the Vec<_> - at the time of writing .flatten() prevents them.
|
// This code relies on reusing allocations from the Vec<_> - at the time of writing .flatten() prevents them.
|
||||||
#[allow(clippy::filter_map_identity)]
|
#[allow(clippy::filter_map_identity)]
|
||||||
let mut v: Vec<_> = fold_edits
|
let mut v: Vec<_> = fold_edits
|
||||||
@@ -132,29 +130,30 @@ impl TabMap {
|
|||||||
.collect();
|
.collect();
|
||||||
v.push(first_edit);
|
v.push(first_edit);
|
||||||
debug_assert_eq!(v.as_ptr(), _old_alloc_ptr, "Fold edits were reallocated");
|
debug_assert_eq!(v.as_ptr(), _old_alloc_ptr, "Fold edits were reallocated");
|
||||||
v
|
v.into_iter()
|
||||||
|
.map(|fold_edit| {
|
||||||
|
let old_start = fold_edit.old.start.to_point(&old_snapshot.fold_snapshot);
|
||||||
|
let old_end = fold_edit.old.end.to_point(&old_snapshot.fold_snapshot);
|
||||||
|
let new_start = fold_edit.new.start.to_point(&new_snapshot.fold_snapshot);
|
||||||
|
let new_end = fold_edit.new.end.to_point(&new_snapshot.fold_snapshot);
|
||||||
|
TabEdit {
|
||||||
|
old: old_snapshot.to_tab_point(old_start)
|
||||||
|
..old_snapshot.to_tab_point(old_end),
|
||||||
|
new: new_snapshot.to_tab_point(new_start)
|
||||||
|
..new_snapshot.to_tab_point(new_end),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
|
||||||
|
|
||||||
for fold_edit in fold_edits {
|
|
||||||
let old_start = fold_edit.old.start.to_point(&old_snapshot.fold_snapshot);
|
|
||||||
let old_end = fold_edit.old.end.to_point(&old_snapshot.fold_snapshot);
|
|
||||||
let new_start = fold_edit.new.start.to_point(&new_snapshot.fold_snapshot);
|
|
||||||
let new_end = fold_edit.new.end.to_point(&new_snapshot.fold_snapshot);
|
|
||||||
tab_edits.push(TabEdit {
|
|
||||||
old: old_snapshot.to_tab_point(old_start)..old_snapshot.to_tab_point(old_end),
|
|
||||||
new: new_snapshot.to_tab_point(new_start)..new_snapshot.to_tab_point(new_end),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new_snapshot.version += 1;
|
new_snapshot.version += 1;
|
||||||
tab_edits.push(TabEdit {
|
vec![TabEdit {
|
||||||
old: TabPoint::zero()..old_snapshot.max_point(),
|
old: TabPoint::zero()..old_snapshot.max_point(),
|
||||||
new: TabPoint::zero()..new_snapshot.max_point(),
|
new: TabPoint::zero()..new_snapshot.max_point(),
|
||||||
});
|
}]
|
||||||
}
|
};
|
||||||
|
|
||||||
*old_snapshot = new_snapshot;
|
*old_snapshot = new_snapshot;
|
||||||
(old_snapshot.clone(), tab_edits)
|
(old_snapshot.clone(), tab_edits)
|
||||||
}
|
}
|
||||||
@@ -195,37 +194,28 @@ impl TabSnapshot {
|
|||||||
.fold_snapshot
|
.fold_snapshot
|
||||||
.text_summary_for_range(input_start..input_end);
|
.text_summary_for_range(input_start..input_end);
|
||||||
|
|
||||||
let mut first_line_chars = 0;
|
|
||||||
let line_end = if range.start.row() == range.end.row() {
|
let line_end = if range.start.row() == range.end.row() {
|
||||||
range.end
|
range.end
|
||||||
} else {
|
} else {
|
||||||
self.max_point()
|
self.max_point()
|
||||||
};
|
};
|
||||||
for c in self
|
let first_line_chars = self
|
||||||
.chunks(range.start..line_end, false, Highlights::default())
|
.chunks(range.start..line_end, false, Highlights::default())
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
{
|
.take_while(|&c| c != '\n')
|
||||||
if c == '\n' {
|
.count() as u32;
|
||||||
break;
|
|
||||||
}
|
|
||||||
first_line_chars += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut last_line_chars = 0;
|
let last_line_chars = if range.start.row() == range.end.row() {
|
||||||
if range.start.row() == range.end.row() {
|
first_line_chars
|
||||||
last_line_chars = first_line_chars;
|
|
||||||
} else {
|
} else {
|
||||||
for _ in self
|
self.chunks(
|
||||||
.chunks(
|
TabPoint::new(range.end.row(), 0)..range.end,
|
||||||
TabPoint::new(range.end.row(), 0)..range.end,
|
false,
|
||||||
false,
|
Highlights::default(),
|
||||||
Highlights::default(),
|
)
|
||||||
)
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
.count() as u32
|
||||||
{
|
};
|
||||||
last_line_chars += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextSummary {
|
TextSummary {
|
||||||
lines: range.end.0 - range.start.0,
|
lines: range.end.0 - range.start.0,
|
||||||
@@ -514,15 +504,17 @@ impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
|
|||||||
|
|
||||||
pub struct TabChunks<'a> {
|
pub struct TabChunks<'a> {
|
||||||
snapshot: &'a TabSnapshot,
|
snapshot: &'a TabSnapshot,
|
||||||
|
max_expansion_column: u32,
|
||||||
|
max_output_position: Point,
|
||||||
|
tab_size: NonZeroU32,
|
||||||
|
// region: iteration state
|
||||||
fold_chunks: FoldChunks<'a>,
|
fold_chunks: FoldChunks<'a>,
|
||||||
chunk: Chunk<'a>,
|
chunk: Chunk<'a>,
|
||||||
column: u32,
|
column: u32,
|
||||||
max_expansion_column: u32,
|
|
||||||
output_position: Point,
|
output_position: Point,
|
||||||
input_column: u32,
|
input_column: u32,
|
||||||
max_output_position: Point,
|
|
||||||
tab_size: NonZeroU32,
|
|
||||||
inside_leading_tab: bool,
|
inside_leading_tab: bool,
|
||||||
|
// endregion: iteration state
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TabChunks<'_> {
|
impl TabChunks<'_> {
|
||||||
|
|||||||
@@ -279,15 +279,15 @@ impl InlineValueCache {
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum InlayId {
|
pub enum InlayId {
|
||||||
EditPrediction(usize),
|
EditPrediction(u32),
|
||||||
DebuggerValue(usize),
|
DebuggerValue(u32),
|
||||||
// LSP
|
// LSP
|
||||||
Hint(usize),
|
Hint(u32),
|
||||||
Color(usize),
|
Color(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InlayId {
|
impl InlayId {
|
||||||
fn id(&self) -> usize {
|
fn id(&self) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
Self::EditPrediction(id) => *id,
|
Self::EditPrediction(id) => *id,
|
||||||
Self::DebuggerValue(id) => *id,
|
Self::DebuggerValue(id) => *id,
|
||||||
@@ -1118,7 +1118,8 @@ pub struct Editor {
|
|||||||
edit_prediction_indent_conflict: bool,
|
edit_prediction_indent_conflict: bool,
|
||||||
edit_prediction_requires_modifier_in_indent_conflict: bool,
|
edit_prediction_requires_modifier_in_indent_conflict: bool,
|
||||||
inlay_hint_cache: InlayHintCache,
|
inlay_hint_cache: InlayHintCache,
|
||||||
next_inlay_id: usize,
|
next_inlay_id: u32,
|
||||||
|
next_color_inlay_id: u32,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
pixel_position_of_newest_cursor: Option<gpui::Point<Pixels>>,
|
pixel_position_of_newest_cursor: Option<gpui::Point<Pixels>>,
|
||||||
gutter_dimensions: GutterDimensions,
|
gutter_dimensions: GutterDimensions,
|
||||||
@@ -1182,7 +1183,6 @@ pub struct Editor {
|
|||||||
pub change_list: ChangeList,
|
pub change_list: ChangeList,
|
||||||
inline_value_cache: InlineValueCache,
|
inline_value_cache: InlineValueCache,
|
||||||
selection_drag_state: SelectionDragState,
|
selection_drag_state: SelectionDragState,
|
||||||
next_color_inlay_id: usize,
|
|
||||||
colors: Option<LspColorData>,
|
colors: Option<LspColorData>,
|
||||||
folding_newlines: Task<()>,
|
folding_newlines: Task<()>,
|
||||||
pub lookup_key: Option<Box<dyn Any + Send + Sync>>,
|
pub lookup_key: Option<Box<dyn Any + Send + Sync>>,
|
||||||
@@ -20531,7 +20531,7 @@ impl Editor {
|
|||||||
Anchor::in_buffer(excerpt_id, buffer_id, hint.position),
|
Anchor::in_buffer(excerpt_id, buffer_id, hint.position),
|
||||||
hint.text(),
|
hint.text(),
|
||||||
);
|
);
|
||||||
if !inlay.text.chars().contains(&'\n') {
|
if !inlay.text().chars().contains(&'\n') {
|
||||||
new_inlays.push(inlay);
|
new_inlays.push(inlay);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ pub fn update_inlay_link_and_hover_points(
|
|||||||
inlay: hovered_hint.id,
|
inlay: hovered_hint.id,
|
||||||
inlay_position: hovered_hint.position,
|
inlay_position: hovered_hint.position,
|
||||||
range: extra_shift_left
|
range: extra_shift_left
|
||||||
..hovered_hint.text.len() + extra_shift_right,
|
..hovered_hint.text().len() + extra_shift_right,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
window,
|
window,
|
||||||
|
|||||||
@@ -3571,7 +3571,7 @@ pub mod tests {
|
|||||||
editor
|
editor
|
||||||
.visible_inlay_hints(cx)
|
.visible_inlay_hints(cx)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|hint| hint.text.to_string())
|
.map(|hint| hint.text().to_string())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ use util::post_inc;
|
|||||||
const NEWLINES: &[u8] = &[b'\n'; u8::MAX as usize];
|
const NEWLINES: &[u8] = &[b'\n'; u8::MAX as usize];
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Default, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct ExcerptId(usize);
|
pub struct ExcerptId(u32);
|
||||||
|
|
||||||
/// One or more [`Buffers`](Buffer) being edited in a single view.
|
/// One or more [`Buffers`](Buffer) being edited in a single view.
|
||||||
///
|
///
|
||||||
@@ -7202,7 +7202,7 @@ impl ExcerptId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn max() -> Self {
|
pub fn max() -> Self {
|
||||||
Self(usize::MAX)
|
Self(u32::MAX)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_proto(self) -> u64 {
|
pub fn to_proto(self) -> u64 {
|
||||||
@@ -7222,7 +7222,7 @@ impl ExcerptId {
|
|||||||
|
|
||||||
impl From<ExcerptId> for usize {
|
impl From<ExcerptId> for usize {
|
||||||
fn from(val: ExcerptId) -> Self {
|
fn from(val: ExcerptId) -> Self {
|
||||||
val.0
|
val.0 as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-13
@@ -62,26 +62,23 @@ impl Anchor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn bias(&self, bias: Bias, buffer: &BufferSnapshot) -> Anchor {
|
pub fn bias(&self, bias: Bias, buffer: &BufferSnapshot) -> Anchor {
|
||||||
if bias == Bias::Left {
|
match bias {
|
||||||
self.bias_left(buffer)
|
Bias::Left => self.bias_left(buffer),
|
||||||
} else {
|
Bias::Right => self.bias_right(buffer),
|
||||||
self.bias_right(buffer)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bias_left(&self, buffer: &BufferSnapshot) -> Anchor {
|
pub fn bias_left(&self, buffer: &BufferSnapshot) -> Anchor {
|
||||||
if self.bias == Bias::Left {
|
match self.bias {
|
||||||
*self
|
Bias::Left => *self,
|
||||||
} else {
|
Bias::Right => buffer.anchor_before(self),
|
||||||
buffer.anchor_before(self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bias_right(&self, buffer: &BufferSnapshot) -> Anchor {
|
pub fn bias_right(&self, buffer: &BufferSnapshot) -> Anchor {
|
||||||
if self.bias == Bias::Right {
|
match self.bias {
|
||||||
*self
|
Bias::Left => buffer.anchor_after(self),
|
||||||
} else {
|
Bias::Right => *self,
|
||||||
buffer.anchor_after(self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +93,7 @@ impl Anchor {
|
|||||||
pub fn is_valid(&self, buffer: &BufferSnapshot) -> bool {
|
pub fn is_valid(&self, buffer: &BufferSnapshot) -> bool {
|
||||||
if *self == Anchor::MIN || *self == Anchor::MAX {
|
if *self == Anchor::MIN || *self == Anchor::MAX {
|
||||||
true
|
true
|
||||||
} else if self.buffer_id != Some(buffer.remote_id) {
|
} else if self.buffer_id.is_none_or(|id| id != buffer.remote_id) {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
let Some(fragment_id) = buffer.try_fragment_id_for_anchor(self) else {
|
let Some(fragment_id) = buffer.try_fragment_id_for_anchor(self) else {
|
||||||
|
|||||||
Reference in New Issue
Block a user