Closes https://github.com/zed-industries/zed/issues/5155 Closes https://github.com/zed-industries/zed/issues/4879 # Purpose There was no way to know what to put in function signatures or struct fields other than hovering at the moment. Therefore, it was necessary to implement LSP's `textDocument/signatureHelp`. I tried my best to match the surrounding coding style, but since this is my first contribution, I believe there are various aspects that may be lacking. I would greatly appreciate your code review. # Description When the window is displayed, the current argument or field at the cursor's position is automatically bolded. If the cursor moves and there is nothing to display, the window closes automatically. To minimize changes and reduce the burden of review and debugging, the SignatureHelp feature is implemented only when `is_local` is `true`. Some `unimplemented!()` macros are embedded, but rest assured that they are not called in this implementation. # How to try it out Press `cmd + i` (MacOS), `ctrl + i` (Linux). # Enable auto signature help (2 ways) ### Add `"auto_signature_help": true` to `settings.json` <img width="426" alt="image" src="https://github.com/zed-industries/zed/assets/55743826/61310c39-47f9-4586-94b0-ae519dc3b37c"> Or ### Press `Auto Signature Help`. (Default `false`) <img width="226" alt="image" src="https://github.com/zed-industries/zed/assets/55743826/34155215-1eb5-4621-b09b-55df2f1ab6a8"> # Disable to show signature help after completion ### Add `"show_signature_help_after_completion": false` to `settings.json` <img width="438" alt="image" src="https://github.com/zed-industries/zed/assets/55743826/5e5bacac-62e0-4921-9243-17e1e72d5eb6"> # Movie https://github.com/zed-industries/zed/assets/55743826/77c12d51-b0a5-415d-8901-f93ef92098e7 # Screen Shot <img width="628" alt="image" src="https://github.com/zed-industries/zed/assets/55743826/3ebcf4b6-2b94-4dea-97f9-ac4f33e0291e"> <img width="637" alt="image" src="https://github.com/zed-industries/zed/assets/55743826/6dc3eb4d-beee-460b-8dbe-d6eec6379b76"> Release Notes: - Show function signature popovers ([4879](https://github.com/zed-industries/zed/issues/4879), [5155](https://github.com/zed-industries/zed/issues/5155)) --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
66 lines
1.6 KiB
Rust
66 lines
1.6 KiB
Rust
use crate::signature_help::popover::SignatureHelpPopover;
|
|
use crate::signature_help::SignatureHelpHiddenBy;
|
|
use gpui::Task;
|
|
|
|
#[derive(Default, Debug)]
|
|
pub struct SignatureHelpState {
|
|
task: Option<Task<()>>,
|
|
popover: Option<SignatureHelpPopover>,
|
|
hidden_by: Option<SignatureHelpHiddenBy>,
|
|
backspace_pressed: bool,
|
|
}
|
|
|
|
impl SignatureHelpState {
|
|
pub fn set_task(&mut self, task: Task<()>) {
|
|
self.task = Some(task);
|
|
self.hidden_by = None;
|
|
}
|
|
|
|
pub fn kill_task(&mut self) {
|
|
self.task = None;
|
|
}
|
|
|
|
pub fn popover(&self) -> Option<&SignatureHelpPopover> {
|
|
self.popover.as_ref()
|
|
}
|
|
|
|
pub fn popover_mut(&mut self) -> Option<&mut SignatureHelpPopover> {
|
|
self.popover.as_mut()
|
|
}
|
|
|
|
pub fn backspace_pressed(&self) -> bool {
|
|
self.backspace_pressed
|
|
}
|
|
|
|
pub fn set_backspace_pressed(&mut self, backspace_pressed: bool) {
|
|
self.backspace_pressed = backspace_pressed;
|
|
}
|
|
|
|
pub fn set_popover(&mut self, popover: SignatureHelpPopover) {
|
|
self.popover = Some(popover);
|
|
self.hidden_by = None;
|
|
}
|
|
|
|
pub fn hide(&mut self, hidden_by: SignatureHelpHiddenBy) {
|
|
if self.hidden_by.is_none() {
|
|
self.popover = None;
|
|
self.hidden_by = Some(hidden_by);
|
|
}
|
|
}
|
|
|
|
pub fn hidden_by_selection(&self) -> bool {
|
|
self.hidden_by == Some(SignatureHelpHiddenBy::Selection)
|
|
}
|
|
|
|
pub fn is_shown(&self) -> bool {
|
|
self.popover.is_some()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
impl SignatureHelpState {
|
|
pub fn task(&self) -> Option<&Task<()>> {
|
|
self.task.as_ref()
|
|
}
|
|
}
|