Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands/lsp.rs')
| -rw-r--r-- | helix-term/src/commands/lsp.rs | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 9c55c830..99a6d62f 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1357,6 +1357,7 @@ fn compute_inlay_hints_for_view( let mut padding_after_inlay_hints = Vec::new(); let doc_text = doc.text(); + let inlay_hints_length_limit = doc.config.load().lsp.inlay_hints_length_limit; for hint in hints { let char_idx = @@ -1367,7 +1368,7 @@ fn compute_inlay_hints_for_view( None => continue, }; - let label = match hint.label { + let mut label = match hint.label { lsp::InlayHintLabel::String(s) => s, lsp::InlayHintLabel::LabelParts(parts) => parts .into_iter() @@ -1375,6 +1376,31 @@ fn compute_inlay_hints_for_view( .collect::<Vec<_>>() .join(""), }; + // Truncate the hint if too long + if let Some(limit) = inlay_hints_length_limit { + // Limit on displayed width + use helix_core::unicode::{ + segmentation::UnicodeSegmentation, width::UnicodeWidthStr, + }; + + let width = label.width(); + let limit = limit.get().into(); + if width > limit { + let mut floor_boundary = 0; + let mut acc = 0; + for (i, grapheme_cluster) in label.grapheme_indices(true) { + acc += grapheme_cluster.width(); + + if acc > limit { + floor_boundary = i; + break; + } + } + + label.truncate(floor_boundary); + label.push('…'); + } + } let inlay_hints_vec = match hint.kind { Some(lsp::InlayHintKind::TYPE) => &mut type_inlay_hints, |