Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ellipsis for inlay-hint #12872

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use helix_core::{
use helix_stdx::path;
use helix_view::{
document::{DocumentInlayHints, DocumentInlayHintsId},
editor::Action,
editor::{Action, LspConfig},
handlers::lsp::SignatureHelpInvoked,
theme::Style,
Document, View,
Expand Down Expand Up @@ -1274,7 +1274,8 @@ pub fn select_references_to_symbol_under_cursor(cx: &mut Context) {
}

pub fn compute_inlay_hints_for_all_views(editor: &mut Editor, jobs: &mut crate::job::Jobs) {
if !editor.config().lsp.display_inlay_hints {
let lsp = &editor.config().lsp;
if !lsp.display_inlay_hints {
return;
}

Expand All @@ -1283,7 +1284,7 @@ pub fn compute_inlay_hints_for_all_views(editor: &mut Editor, jobs: &mut crate::
Some(doc) => doc,
None => continue,
};
if let Some(callback) = compute_inlay_hints_for_view(view, doc) {
if let Some(callback) = compute_inlay_hints_for_view(view, doc, lsp) {
jobs.callback(callback);
}
}
Expand All @@ -1292,6 +1293,7 @@ pub fn compute_inlay_hints_for_all_views(editor: &mut Editor, jobs: &mut crate::
fn compute_inlay_hints_for_view(
view: &View,
doc: &Document,
lsp: &LspConfig,
) -> Option<std::pin::Pin<Box<impl Future<Output = Result<crate::job::Callback, anyhow::Error>>>>> {
let view_id = view.id;
let doc_id = view.doc;
Expand Down Expand Up @@ -1340,6 +1342,7 @@ fn compute_inlay_hints_for_view(

let offset_encoding = language_server.offset_encoding();

let max_inlay_length = lsp.max_inlay_hint_length;
let callback = super::make_job_callback(
language_server.text_document_range_inlay_hints(doc.identifier(), range, None)?,
move |editor, _compositor, response: Option<Vec<lsp::InlayHint>>| {
Expand Down Expand Up @@ -1409,7 +1412,17 @@ fn compute_inlay_hints_for_view(
padding_before_inlay_hints.push(InlineAnnotation::new(char_idx, " "));
}

inlay_hints_vec.push(InlineAnnotation::new(char_idx, label));
let len = label.len();
inlay_hints_vec.push(InlineAnnotation::new(
char_idx,
if max_inlay_length > 0 && len > max_inlay_length {
let mut label = label[0..max_inlay_length - 3].to_string();
label.push_str("...");
label
} else {
label
},
));

if let Some(true) = hint.padding_right {
padding_after_inlay_hints.push(InlineAnnotation::new(char_idx, " "));
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ pub struct LspConfig {
pub snippets: bool,
/// Whether to include declaration in the goto reference query
pub goto_reference_include_declaration: bool,
/// Controls the length of the inlay, setting it to 0(default) will not limit.
pub max_inlay_hint_length: usize,
}

impl Default for LspConfig {
Expand All @@ -463,6 +465,7 @@ impl Default for LspConfig {
display_inlay_hints: false,
snippets: true,
goto_reference_include_declaration: true,
max_inlay_hint_length: 0,
}
}
}
Expand Down