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

signature: use the suggested LSP signature when changed #10655

Merged
merged 1 commit into from
May 3, 2024
Merged
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
28 changes: 21 additions & 7 deletions helix-term/src/handlers/signature_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,33 @@ pub fn show_signature_help(
.collect();

let old_popup = compositor.find_id::<Popup<SignatureHelp>>(SignatureHelp::ID);
let mut active_signature = old_popup
.as_ref()
.map(|popup| popup.contents().active_signature())
.unwrap_or_else(|| response.active_signature.unwrap_or_default() as usize);
let lsp_signature = response.active_signature.map(|s| s as usize);

if active_signature >= signatures.len() {
active_signature = signatures.len() - 1;
}
// take the new suggested lsp signature if changed
// otherwise take the old signature if possible
// otherwise the last one (in case there is less signatures than before)
let active_signature = old_popup
.as_ref()
.map(|popup| {
let old_lsp_sig = popup.contents().lsp_signature();
let old_sig = popup
.contents()
.active_signature()
.min(signatures.len() - 1);

if old_lsp_sig != lsp_signature {
lsp_signature.unwrap_or(old_sig)
} else {
old_sig
}
})
.unwrap_or(lsp_signature.unwrap_or_default());

let contents = SignatureHelp::new(
language.to_string(),
Arc::clone(&editor.syn_loader),
active_signature,
lsp_signature,
signatures,
);

Expand Down
7 changes: 7 additions & 0 deletions helix-term/src/ui/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct SignatureHelp {
language: String,
config_loader: Arc<ArcSwap<syntax::Loader>>,
active_signature: usize,
lsp_signature: Option<usize>,
signatures: Vec<Signature>,
}

Expand All @@ -37,12 +38,14 @@ impl SignatureHelp {
language: String,
config_loader: Arc<ArcSwap<syntax::Loader>>,
active_signature: usize,
lsp_signature: Option<usize>,
signatures: Vec<Signature>,
) -> Self {
Self {
language,
config_loader,
active_signature,
lsp_signature,
signatures,
}
}
Expand All @@ -51,6 +54,10 @@ impl SignatureHelp {
self.active_signature
}

pub fn lsp_signature(&self) -> Option<usize> {
self.lsp_signature
}

pub fn visible_popup(compositor: &mut Compositor) -> Option<&mut Popup<Self>> {
compositor.find_id::<Popup<Self>>(Self::ID)
}
Expand Down
Loading