Update lsp.rs

pull/9109/head
Daniel 11 months ago
parent 73a8622332
commit 27aed73abb

@ -1636,79 +1636,29 @@ fn compute_inlay_hints_for_view(
} }
} }
fn collect_to_map<'a>( let vimmise_inlays = |hints: &mut Vec<InlineAnnotation>, prefix| {
doc_text: &helix_core::Rope, hints.iter_mut().map(|it| {
hints: &'a Vec<InlineAnnotation>, it.char_idx = helix_core::line_ending::line_end_char_index(&doc_text.slice(..), doc_text.char_to_line(it.char_idx));
) -> HashMap<usize, helix_core::SmallVec<[&'a str; 1]>> { (it.char_idx, it)
let mut v = HashMap::new(); }).fold(HashMap::<usize, Vec<&mut InlineAnnotation>>::new(), |mut map, (id, annot)| {
for hint in hints { match map.get_mut(&id) {
let char_idx = hint.char_idx; Some(v) => v.push(annot),
let char_pos = helix_core::coords_at_pos(doc_text.byte_slice(..), char_idx); None => {map.insert(id, vec![annot]);}
let char_index = helix_core::line_ending::line_end_char_index( };
&doc_text.slice(..), map
char_pos.row, }).into_iter().for_each(|(_, mut v)| {
); v[0].text.insert_str(0, prefix);
v.iter_mut().for_each(|s| s.text.push_str(","));
let refm = match v.get_mut(&char_index) { let last = v.last_mut().unwrap();
Some(l) => l, last.text.truncate(last.text.len() - 1);
None => { });
v.insert(char_index, helix_core::SmallVec::<[&str; 1]>::new());
v.get_mut(&char_index).unwrap()
}
}; };
refm.push(hint.text.as_str()); vimmise_inlays(&mut type_inlay_hints, " => ");
} vimmise_inlays(&mut parameter_inlay_hints, " <= ");
v vimmise_inlays(&mut other_inlay_hints, " == ");
} padding_after_inlay_hints = vec![];
padding_before_inlay_hints = vec![];
fn inlay_map_to_vec(
map: HashMap<usize, helix_core::SmallVec<[&str; 1]>>,
type_hint_prefix: &str,
) -> Vec<InlineAnnotation> {
map.into_iter()
.map(|(char_index, hints)| {
let type_hint_midfix = ",";
let type_hint_suffix = "";
let mut type_built_string = String::with_capacity(
hints
.iter()
.map(|it| it.len() + type_hint_midfix.len())
.sum::<usize>()
+ type_hint_suffix.len()
+ type_hint_prefix.len(),
);
type_built_string.push_str(type_hint_prefix);
for hint in hints {
type_built_string.push_str(hint);
type_built_string.push_str(type_hint_midfix);
}
for _ in 0..type_hint_midfix.len() {
type_built_string.pop();
}
type_built_string.push_str(type_hint_suffix);
InlineAnnotation::new(0, type_built_string)
})
.collect()
}
let type_hint_line_index_map = collect_to_map(doc_text, &type_inlay_hints);
let param_hint_line_index_map = collect_to_map(doc_text, &parameter_inlay_hints);
type_inlay_hints = inlay_map_to_vec(type_hint_line_index_map, " > ");
parameter_inlay_hints = inlay_map_to_vec(param_hint_line_index_map, " < ");
padding_after_inlay_hints = type_inlay_hints
.iter()
.map(|it| InlineAnnotation::new(it.char_idx, " "))
.collect();
padding_before_inlay_hints = parameter_inlay_hints
.iter()
.map(|it| InlineAnnotation::new(it.char_idx, " "))
.collect();
doc.set_inlay_hints( doc.set_inlay_hints(
view_id, view_id,

Loading…
Cancel
Save