aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorGokul Soumya2022-07-19 02:28:24 +0000
committerGitHub2022-07-19 02:28:24 +0000
commit791bf7e50a19bcf7612788deb7514847089cb976 (patch)
tree0bac607be8b940aed8000b77a2f4dfa2e14882b8 /helix-term/src/commands.rs
parent02f009921007301284cbb0db4bc36bc629088fbb (diff)
Add lsp signature help (#1755)
* Add lsp signature help * Do not move signature help popup on multiple triggers * Highlight current parameter in signature help * Auto close signature help * Position signature help above to not block completion * Update signature help on backspace/insert mode delete * Add lsp.auto-signature-help config option * Add serde default annotation for LspConfig * Show LSP inactive message only if signature help is invoked manually * Do not assume valid signature help response from LSP Malformed LSP responses are common, and these should not crash the editor. * Check signature help capability before sending request * Reuse Open enum for PositionBias in popup * Close signature popup and exit insert mode on escape * Add config to control signature help docs display * Use new Margin api in signature help * Invoke signature help on changing to insert mode
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs42
1 files changed, 23 insertions, 19 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index dad3db86..3ee75f6a 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -715,6 +715,8 @@ fn kill_to_line_start(cx: &mut Context) {
Range::new(head, anchor)
});
delete_selection_insert_mode(doc, view, &selection);
+
+ lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
}
fn kill_to_line_end(cx: &mut Context) {
@@ -734,6 +736,8 @@ fn kill_to_line_end(cx: &mut Context) {
new_range
});
delete_selection_insert_mode(doc, view, &selection);
+
+ lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
}
fn goto_first_nonwhitespace(cx: &mut Context) {
@@ -2399,7 +2403,8 @@ async fn make_format_callback(
Ok(call)
}
-enum Open {
+#[derive(PartialEq)]
+pub enum Open {
Below,
Above,
}
@@ -2797,6 +2802,9 @@ pub mod insert {
use helix_lsp::lsp;
// if ch matches signature_help char, trigger
let doc = doc_mut!(cx.editor);
+ // The language_server!() macro is not used here since it will
+ // print an "LSP not active for current buffer" message on
+ // every keypress.
let language_server = match doc.language_server() {
Some(language_server) => language_server,
None => return,
@@ -2816,26 +2824,15 @@ pub mod insert {
{
// TODO: what if trigger is multiple chars long
let is_trigger = triggers.iter().any(|trigger| trigger.contains(ch));
+ // lsp doesn't tell us when to close the signature help, so we request
+ // the help information again after common close triggers which should
+ // return None, which in turn closes the popup.
+ let close_triggers = &[')', ';', '.'];
- if is_trigger {
- super::signature_help(cx);
+ if is_trigger || close_triggers.contains(&ch) {
+ super::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
}
}
-
- // SignatureHelp {
- // signatures: [
- // SignatureInformation {
- // label: "fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error>",
- // documentation: None,
- // parameters: Some(
- // [ParameterInformation { label: Simple("path: PathBuf"), documentation: None },
- // ParameterInformation { label: Simple("action: Action"), documentation: None }]
- // ),
- // active_parameter: Some(0)
- // }
- // ],
- // active_signature: None, active_parameter: Some(0)
- // }
}
// The default insert hook: simply insert the character
@@ -2870,7 +2867,6 @@ pub mod insert {
// this could also generically look at Transaction, but it's a bit annoying to look at
// Operation instead of Change.
for hook in &[language_server_completion, signature_help] {
- // for hook in &[signature_help] {
hook(cx, c);
}
}
@@ -3042,6 +3038,8 @@ pub mod insert {
}
});
doc.apply(&transaction, view.id);
+
+ lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
}
pub fn delete_char_forward(cx: &mut Context) {
@@ -3058,6 +3056,8 @@ pub mod insert {
)
});
doc.apply(&transaction, view.id);
+
+ lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
}
pub fn delete_word_backward(cx: &mut Context) {
@@ -3071,6 +3071,8 @@ pub mod insert {
exclude_cursor(text, next, range)
});
delete_selection_insert_mode(doc, view, &selection);
+
+ lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
}
pub fn delete_word_forward(cx: &mut Context) {
@@ -3083,6 +3085,8 @@ pub mod insert {
.clone()
.transform(|range| movement::move_next_word_start(text, range, count));
delete_selection_insert_mode(doc, view, &selection);
+
+ lsp::signature_help_impl(cx, SignatureHelpInvoked::Automatic);
}
}