Skip to content

lsp: Implement textDocument/signatureHelp for ProjectClientState::Local environment#12909

Merged
SomeoneToIgnore merged 96 commits intozed-industries:mainfrom
tomoikey:signature-help
Jul 11, 2024
Merged

lsp: Implement textDocument/signatureHelp for ProjectClientState::Local environment#12909
SomeoneToIgnore merged 96 commits intozed-industries:mainfrom
tomoikey:signature-help

Conversation

@tomoikey
Copy link
Copy Markdown
Contributor

@tomoikey tomoikey commented Jun 11, 2024

Closes #5155
Closes #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

image

Or

Press Auto Signature Help. (Default false)

image

Disable to show signature help after completion

Add "show_signature_help_after_completion": false to settings.json

image

Movie

2024-07-10.3.57.59.mov

Screen Shot

image image

Release Notes:

  • Show function signature popovers (4879, 5155)

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Jun 11, 2024

We require contributors to sign our Contributor License Agreement, and we don't have @tomoikey on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@tomoikey tomoikey marked this pull request as draft June 11, 2024 21:24
@tomoikey tomoikey changed the title Implement SignatureHelp in local Implement textDocument/signatureHelp in local Jun 11, 2024
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jun 11, 2024
@tomoikey tomoikey marked this pull request as ready for review June 13, 2024 17:24
@tomoikey tomoikey changed the title Implement textDocument/signatureHelp in local Implement textDocument/signatureHelp in Local Jun 13, 2024
@tomoikey tomoikey changed the title Implement textDocument/signatureHelp in Local [LSP] Implement textDocument/signatureHelp in Local Jun 13, 2024
@tomoikey tomoikey changed the title [LSP] Implement textDocument/signatureHelp in Local [LSP] Implement textDocument/signatureHelp for ProjectClientState::Local environment Jun 13, 2024
@maxdeviant maxdeviant changed the title [LSP] Implement textDocument/signatureHelp for ProjectClientState::Local environment lsp: Implement textDocument/signatureHelp for ProjectClientState::Local environment Jun 13, 2024
@tomoikey

This comment was marked as resolved.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Jun 16, 2024

The cla-bot has been summoned, and re-checked this pull request!

@tomoikey

This comment was marked as resolved.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Jun 16, 2024

The cla-bot has been summoned, and re-checked this pull request!

Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I've glanced over and left some NIT comments that are not very important.

Two more important notes I'd like to emphasize:

  • the remote code seems not finished, and if that causes issues, I'd just remove this entirely for now — having the feature working in single player mode is just fine too, I can pick up the multiplayer part later (or welcome to do so here, or in a follow-up patch).

I think this direction is less important at the current PR state, and it's more beneficial to concentrate on the single player usability (my next bullet)

  • This feature is amazing but lacks visibility and dynamics — after looking at the code, it seems that the only way to see the signature help is by calling a corresponding action?

I would also love to get it automatically open after a method completion is accepted, and, maybe, something else? (I'd try to see how it looks when shown for a certain completion menu item selected)

This way, people will see that there's something new added, and will be able to type and see the signature help (if it's close enough to the caret input).

For now, I'll transfer this PR to draft until we straighten the singleplayer mode, but it already looks very close to that, thanks!

@SomeoneToIgnore SomeoneToIgnore self-assigned this Jun 18, 2024
tomoikey added 3 commits July 10, 2024 20:40
…-> foo() occurs and auto_signature_help is false
… where markdown tests were located away from the logic
@tomoikey
Copy link
Copy Markdown
Contributor Author

@SomeoneToIgnore

I've added the remote support

Thank you for addressing the remote mode!!!
I fixed the issue where signature_help was not displayed when entering ( from the fooˇ state, even if auto_signature_help was enabled. I also added two new tests for this.

Movie

2024-07-10.22.27.32.mov

I've tested it and got somewhat confused

Regarding the combination of settings, I agree that some patterns might be confusing. However, we need to ensure that they do not interfere with each other. Using a mathematical set theory analogy, the intersection of the set auto_signature_help and the set show_signature_help_after_completion (A ^ B) should be an empty set. If the intersection of these two setting sets is not empty, it would lead to a loss of customization (independence) of the settings.

Therefore,

  • When “auto_signature_help” is true, signature_help should be triggered by cursor movement or bracket input.
  • When “auto_signature_help” is false, signature_help should not be triggered by cursor movement or bracket input.
  • When “show_signature_help_after_completion” is true, signature_help should be triggered after completion.
  • When “show_signature_help_after_completion” is false, signature_help should not be triggered after completion.

This way, the settings are independent and highly customizable without interfering with each other. If additional needs arise, these should be further divided independently or new independent settings should be added.


Additionally, I split the modules into several parts as various concepts were mixed within a single file.


One remote test had failed, surprisingly, I can investigate it on Thursday, welcome to fix it before if you get to the root of it.

This Thursday and Friday, it is highly likely that I will not be able to allocate time due to a company event.
If it’s a minor issue, I might be able to handle it, but I probably won’t have enough time, so @SomeoneToIgnore will likely discover any issues during the investigation on Thursday.
If the investigation proves challenging, I will try to find some spare time to help as well.


On a side note, interactions on GitHub feel very asynchronous and inconvenient for collaborative development.
If you don’t mind, I would appreciate it if we could use a chat application like Slack for communication. However, I understand the concerns about privacy, so it’s okay if you prefer to ignore this suggestion.

@SomeoneToIgnore
Copy link
Copy Markdown
Contributor

However, we need to ensure that they do not interfere with each other.

Why not?

My whole point is that by ensuring that they do not interfere, we make it less intuitive for certain languages.
For

"auto_signature_help": true,
"show_signature_help_after_completion": false,

issue, doing self.fˇ -> self.foo(ˇ) puts the caret between the brackets, and, as seen on the video, moving the caret around, keeping it between the brackets, does not invoke the popover while it should, according to auto_signature_help — there's no autocompletion happening after a few key presses.

This way, the settings are independent and highly customizable without interfering with each other. If additional needs arise, these should be further divided independently or new independent settings should be added.

What does this chatgpt-esque phrase mean? What is the point of the behavior, described above and who would want that?

I propose to rework the settings, if you find this configuration confusing.
My idea is to have a way to gradually enable the feature:

pub enum SignatureHelpPopovers {
    Off,
    AfterCompletionsOnly,
    Everywhere
}

there's a fourth variant, EverywhereExceptAfterCompletions that I describe above and find redundant.

@tomoikey
Copy link
Copy Markdown
Contributor Author

@SomeoneToIgnore
There has been a misunderstanding because what you think of as auto_signature_help and what I think of as auto_signature_help are different. I understood auto_signature_help to be something that triggers when crossing existing brackets, but you seem to mean something that triggers when surrounded by brackets. So, I had no issue with the signature_help not appearing after completion when auto_signature_help: true, show_signature_help_after_completion: false.

I have no choice but to imagine what behavior the Zed team wants for Zed from your words. It is natural for ambiguity to arise when using natural language. I am not good at English. The reason I sound like ChatGPT is that I am using ChatGPT as an intermediary for communication with you. I understand that I am taking up your time due to communication issues. I apologize for that.

After dinner, I plan to create a combined setting for auto_signature_help and show_signature_help_after_completion, as you suggested. However, the settings in the top right corner of the screen are toggles, so it seems they can’t represent more than three values. How would you like to handle this?

pub enum SignatureHelpPopovers {
    Off,
    AfterCompletionsOnly,
    Everywhere
}
image

@SomeoneToIgnore
Copy link
Copy Markdown
Contributor

something that triggers when crossing existing brackets

But isn't self.f -> self.foo(ˇ) also a "crossing", given that mouse-clicking into the middle of baz(foo, ˇbar) works already, hence also considered as "crossing"?
Generally, I am not sure that crossing is a good verb/approach, and was thinking in surround terms all this time.

I have the following ideas on the settings:

  • we should have a mode to always show these parameters because certain people liked that
"auto_signature_help": true,
"show_signature_help_after_completion": WHATEVER,
  • we should have a way to never show these paremeters because people prefer minimalism
"auto_signature_help": false,
"show_signature_help_after_completion": false,
  • we should have a middle ground enabled by default, so that the feature is notable by people
"auto_signature_help": false,
"show_signature_help_after_completion": true,

The middle ground was chosen to be "after the completions only" as something very useful feature-wise.

2 existing parameters are just fine with that logic if and SignatureHelpPopovers enum could stay as a mental model, as it feels simpler this way.
Then, the toggle is fine to change the auto_signature_help only.

But if you want to use the enum, I'd keep the toggle switching between SignatureHelpPopovers::Everywhere and either what was in settings (if it was not SignatureHelpPopovers:Everywhere, by default that would be SignatureHelpPopovers::AfterCompletionsOnly) or SignatureHelpPopovers::Off otherwise.

@SomeoneToIgnore
Copy link
Copy Markdown
Contributor

SomeoneToIgnore commented Jul 10, 2024

ChatGPT

Regarding the combination of settings, I agree that some patterns might be confusing. However, we need to ensure that they do not interfere with each other. Using a mathematical set theory analogy, the intersection of the set auto_signature_help and the set show_signature_help_after_completion (A ^ B) should be an empty set. If the intersection of these two setting sets is not empty, it would lead to a loss of customization (independence) of the settings.

I understand that you have to use your ways for translations which is fine per se, and my remark was not targeted at that part.

My main problem with that phrase is how "water is wet, sun rises on the east" those words are, not moving us towards an actionable resolution of the issue, something like I've tried to do in the previous comment.

The point is to identify the point of confusion, make it well usable for people and implement it without bugs, while such generic phrases bring nothing but extra confusion and the discussion bloat.

That's why I'm not sure that using a less async way of communicating will help here — from my perspective, all I constantly do in this PR for a month is: coming, opening the very same pet project, clicking around a few minutes and seeing more issues, sometimes in the very same sequence of actions.
Even the new test code appeared so far only when I noticed that this is a logic issue and has to be tested.
The velocity gets crippled not by the lack of sync approach, but rather an absence of initiative(?) and absence of testing the work on some approximation of the real projects. Maybe, it's not very clear how the feature should look like?

I want to emphasize that I do not aim to attack or anyhow express hostility with such messages, but rather provide some feedback and attempt to highlight the issues.
I'm fine with finishing this PR and the way it moves on too, but would fine as well to trade some velocity in favor of a better discussion quality.

@tomoikey
Copy link
Copy Markdown
Contributor Author

@SomeoneToIgnore
Thank you for your suggestions.
When you say "WHATEVER" in

"auto_signature_help": true,
"show_signature_help_after_completion": WHATEVER,

do you mean "true", or do you want to introduce a new concept of "WHATEVER" in addition to "true" and "false"?

Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first iteration is ready to be merged.

I've went on and fixed the settings myself as it's simpler than to explain it another time, hope that made it more clear.

One last thing that I noticed only recently: languages with overrides may provide multiple signatures for a single function/method.
image

Also, there's no other popover components such as the description.
I've laid the ground work for that, and there's a new TODO in the signature_help.rs where the data gets stripped to just one signature.
Later, somebody may follow with this up, but for now this PR is very useful for languages like Rust, thank you a lot for the heavy lifting.

@SomeoneToIgnore SomeoneToIgnore mentioned this pull request Jul 11, 2024
1 task
@SomeoneToIgnore SomeoneToIgnore merged commit 291d64c into zed-industries:main Jul 11, 2024
SomeoneToIgnore added a commit that referenced this pull request Jul 12, 2024
SomeoneToIgnore added a commit that referenced this pull request Jul 13, 2024
Follow-up of #12909

* Fully preserve LSP data when sending it via collab, and only strip it
on the client.
* Avoid extra custom request handlers, and extend multi LSP server query
protocol instead.


Release Notes:

- N/A
SomeoneToIgnore added a commit that referenced this pull request Jul 15, 2024
SomeoneToIgnore added a commit that referenced this pull request Jul 15, 2024
Follow-up of #12909

* Fully preserve LSP data when sending it via collab, and only strip it
on the client.
* Avoid extra custom request handlers, and extend multi LSP server query
protocol instead.


Release Notes:

- N/A
@mwitteveen
Copy link
Copy Markdown

This should really be enabled by default

@forresthopkinsa
Copy link
Copy Markdown

Anecdotally, it took me a long time to find this feature because I was looking for "parameter hints" or "argument hints" and didn't think to search "signature"

@hokein
Copy link
Copy Markdown
Contributor

hokein commented Dec 4, 2025

This should really be enabled by default

+1. I ended up here while trying to figure out why this feature wasn't enabled when I typed (.

This change actually does enable the feature by default (note show_signature_help_after_edits is true). However, it seems this flag was disabled in #20726 to mitigate issue #20725.

I agree that we should enable it by default (this is also the standard behavior in VS Code). If users don't need the popup, they can simply press esc. @SomeoneToIgnore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

suggest signature params when writing a function call trigger parameter hints

6 participants