aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorPascal Kuthe2023-11-19 21:34:03 +0000
committerBlaž Hrastnik2024-03-23 06:35:25 +0000
commit69e07ab61e51598ba6e31bdd79608091fdbba254 (patch)
tree896d9d861dcb7875adbd6afe3c446f036ed078b3 /helix-view/src
parent68b21578ac4b5ded1a262469c6887794a689284f (diff)
use slices instead of Rc for virtual text
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs42
-rw-r--r--helix-view/src/view.rs28
2 files changed, 29 insertions, 41 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index f813c742..090e4dd5 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -8,7 +8,7 @@ use helix_core::chars::char_is_word;
use helix_core::doc_formatter::TextFormat;
use helix_core::encoding::Encoding;
use helix_core::syntax::{Highlight, LanguageServerFeature};
-use helix_core::text_annotations::{InlineAnnotation, TextAnnotations};
+use helix_core::text_annotations::InlineAnnotation;
use helix_lsp::util::lsp_pos_to_pos;
use helix_vcs::{DiffHandle, DiffProviderRegistry};
@@ -21,7 +21,6 @@ use std::collections::HashMap;
use std::fmt::Display;
use std::future::Future;
use std::path::{Path, PathBuf};
-use std::rc::Rc;
use std::str::FromStr;
use std::sync::{Arc, Weak};
use std::time::SystemTime;
@@ -200,22 +199,22 @@ pub struct DocumentInlayHints {
pub id: DocumentInlayHintsId,
/// Inlay hints of `TYPE` kind, if any.
- pub type_inlay_hints: Rc<[InlineAnnotation]>,
+ pub type_inlay_hints: Vec<InlineAnnotation>,
/// Inlay hints of `PARAMETER` kind, if any.
- pub parameter_inlay_hints: Rc<[InlineAnnotation]>,
+ pub parameter_inlay_hints: Vec<InlineAnnotation>,
/// Inlay hints that are neither `TYPE` nor `PARAMETER`.
///
/// LSPs are not required to associate a kind to their inlay hints, for example Rust-Analyzer
/// currently never does (February 2023) and the LSP spec may add new kinds in the future that
/// we want to display even if we don't have some special highlighting for them.
- pub other_inlay_hints: Rc<[InlineAnnotation]>,
+ pub other_inlay_hints: Vec<InlineAnnotation>,
/// Inlay hint padding. When creating the final `TextAnnotations`, the `before` padding must be
/// added first, then the regular inlay hints, then the `after` padding.
- pub padding_before_inlay_hints: Rc<[InlineAnnotation]>,
- pub padding_after_inlay_hints: Rc<[InlineAnnotation]>,
+ pub padding_before_inlay_hints: Vec<InlineAnnotation>,
+ pub padding_after_inlay_hints: Vec<InlineAnnotation>,
}
impl DocumentInlayHints {
@@ -223,11 +222,11 @@ impl DocumentInlayHints {
pub fn empty_with_id(id: DocumentInlayHintsId) -> Self {
Self {
id,
- type_inlay_hints: Rc::new([]),
- parameter_inlay_hints: Rc::new([]),
- other_inlay_hints: Rc::new([]),
- padding_before_inlay_hints: Rc::new([]),
- padding_after_inlay_hints: Rc::new([]),
+ type_inlay_hints: Vec::new(),
+ parameter_inlay_hints: Vec::new(),
+ other_inlay_hints: Vec::new(),
+ padding_before_inlay_hints: Vec::new(),
+ padding_after_inlay_hints: Vec::new(),
}
}
}
@@ -1266,13 +1265,12 @@ impl Document {
});
// Update the inlay hint annotations' positions, helping ensure they are displayed in the proper place
- let apply_inlay_hint_changes = |annotations: &mut Rc<[InlineAnnotation]>| {
- if let Some(data) = Rc::get_mut(annotations) {
- changes.update_positions(
- data.iter_mut()
- .map(|annotation| (&mut annotation.char_idx, Assoc::After)),
- );
- }
+ let apply_inlay_hint_changes = |annotations: &mut Vec<InlineAnnotation>| {
+ changes.update_positions(
+ annotations
+ .iter_mut()
+ .map(|annotation| (&mut annotation.char_idx, Assoc::After)),
+ );
};
self.inlay_hints_oudated = true;
@@ -1940,12 +1938,6 @@ impl Document {
}
}
- /// Get the text annotations that apply to the whole document, those that do not apply to any
- /// specific view.
- pub fn text_annotations(&self, _theme: Option<&Theme>) -> TextAnnotations {
- TextAnnotations::default()
- }
-
/// Set the inlay hints for this document and `view_id`.
pub fn set_inlay_hints(&mut self, view_id: ViewId, inlay_hints: DocumentInlayHints) {
self.inlay_hints.insert(view_id, inlay_hints);
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index e5e2641a..bbdc74a7 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -19,7 +19,6 @@ use helix_core::{
use std::{
collections::{HashMap, VecDeque},
fmt,
- rc::Rc,
};
const JUMP_LIST_CAPACITY: usize = 30;
@@ -409,10 +408,12 @@ impl View {
}
/// Get the text annotations to display in the current view for the given document and theme.
- pub fn text_annotations(&self, doc: &Document, theme: Option<&Theme>) -> TextAnnotations {
- // TODO custom annotations for custom views like side by side diffs
-
- let mut text_annotations = doc.text_annotations(theme);
+ pub fn text_annotations<'a>(
+ &self,
+ doc: &'a Document,
+ theme: Option<&Theme>,
+ ) -> TextAnnotations<'a> {
+ let mut text_annotations = TextAnnotations::default();
let DocumentInlayHints {
id: _,
@@ -436,20 +437,15 @@ impl View {
.and_then(|t| t.find_scope_index("ui.virtual.inlay-hint"))
.map(Highlight);
- let mut add_annotations = |annotations: &Rc<[_]>, style| {
- if !annotations.is_empty() {
- text_annotations.add_inline_annotations(Rc::clone(annotations), style);
- }
- };
-
// Overlapping annotations are ignored apart from the first so the order here is not random:
// types -> parameters -> others should hopefully be the "correct" order for most use cases,
// with the padding coming before and after as expected.
- add_annotations(padding_before_inlay_hints, None);
- add_annotations(type_inlay_hints, type_style);
- add_annotations(parameter_inlay_hints, parameter_style);
- add_annotations(other_inlay_hints, other_style);
- add_annotations(padding_after_inlay_hints, None);
+ text_annotations
+ .add_inline_annotations(padding_before_inlay_hints, None)
+ .add_inline_annotations(type_inlay_hints, type_style)
+ .add_inline_annotations(parameter_inlay_hints, parameter_style)
+ .add_inline_annotations(other_inlay_hints, other_style)
+ .add_inline_annotations(padding_after_inlay_hints, None);
text_annotations
}