signature: use the suggested LSP signature when changed (#10655)
some LSPs does update the active signature and some not. To make both worlds happy, make the active signature more intelligent. 1. SignatureHelp store now the suggested lsp_signature 2. if the lsp_signature changes then use it 3. otherwise use the last signature from the old popup 4. in case the old signature doesn't exist anymore, show the last signature Signed-off-by: Ben Fekih, Hichem <hichem.f@live.de>
This commit is contained in:
parent
31273c69e0
commit
cfca30887c
2 changed files with 28 additions and 7 deletions
|
@ -238,19 +238,33 @@ pub fn show_signature_help(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let old_popup = compositor.find_id::<Popup<SignatureHelp>>(SignatureHelp::ID);
|
let old_popup = compositor.find_id::<Popup<SignatureHelp>>(SignatureHelp::ID);
|
||||||
let mut active_signature = old_popup
|
let lsp_signature = response.active_signature.map(|s| s as usize);
|
||||||
.as_ref()
|
|
||||||
.map(|popup| popup.contents().active_signature())
|
|
||||||
.unwrap_or_else(|| response.active_signature.unwrap_or_default() as usize);
|
|
||||||
|
|
||||||
if active_signature >= signatures.len() {
|
// take the new suggested lsp signature if changed
|
||||||
active_signature = signatures.len() - 1;
|
// 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(
|
let contents = SignatureHelp::new(
|
||||||
language.to_string(),
|
language.to_string(),
|
||||||
Arc::clone(&editor.syn_loader),
|
Arc::clone(&editor.syn_loader),
|
||||||
active_signature,
|
active_signature,
|
||||||
|
lsp_signature,
|
||||||
signatures,
|
signatures,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ pub struct SignatureHelp {
|
||||||
language: String,
|
language: String,
|
||||||
config_loader: Arc<ArcSwap<syntax::Loader>>,
|
config_loader: Arc<ArcSwap<syntax::Loader>>,
|
||||||
active_signature: usize,
|
active_signature: usize,
|
||||||
|
lsp_signature: Option<usize>,
|
||||||
signatures: Vec<Signature>,
|
signatures: Vec<Signature>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,12 +38,14 @@ impl SignatureHelp {
|
||||||
language: String,
|
language: String,
|
||||||
config_loader: Arc<ArcSwap<syntax::Loader>>,
|
config_loader: Arc<ArcSwap<syntax::Loader>>,
|
||||||
active_signature: usize,
|
active_signature: usize,
|
||||||
|
lsp_signature: Option<usize>,
|
||||||
signatures: Vec<Signature>,
|
signatures: Vec<Signature>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
language,
|
language,
|
||||||
config_loader,
|
config_loader,
|
||||||
active_signature,
|
active_signature,
|
||||||
|
lsp_signature,
|
||||||
signatures,
|
signatures,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +54,10 @@ impl SignatureHelp {
|
||||||
self.active_signature
|
self.active_signature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn lsp_signature(&self) -> Option<usize> {
|
||||||
|
self.lsp_signature
|
||||||
|
}
|
||||||
|
|
||||||
pub fn visible_popup(compositor: &mut Compositor) -> Option<&mut Popup<Self>> {
|
pub fn visible_popup(compositor: &mut Compositor) -> Option<&mut Popup<Self>> {
|
||||||
compositor.find_id::<Popup<Self>>(Self::ID)
|
compositor.find_id::<Popup<Self>>(Self::ID)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue