Skip to content

Conversation

a7medev
Copy link
Member

@a7medev a7medev commented Aug 22, 2025

Depends on swiftlang/swift#83378


Adds support for the LSP signature help request.

Note

As of swiftlang/swift#83378, SourceKitD still doesn't separate parameter documentation from the signature documentation and thus parameters don't have their own separate documentation. This should just work once SourceKitD implements this functionality and we'll only need to modify the tests.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Very nice 🌟. If you have a screen recording showing the signature help in real life, I would be very keen to see that.

PR looks great to me, I just have a few nitpicky comments.

@a7medev a7medev requested a review from ahoppen August 23, 2025 10:27
@a7medev
Copy link
Member Author

a7medev commented Aug 23, 2025

Here's a quick demo of signature help in VS Code.

output.mp4

There are some things to improve though:

  1. Automatically triggering signature help after accepting a function or subscript completion item. We should ideally do that in vscode-swift by injecting the editor.action.triggerParameterHints command in completion items using a middleware. I plan on opening a PR for it once we get the basic implementation done.
  2. Persisting the active signature chosen by the user across re-triggers.

@a7medev a7medev force-pushed the feat/signature-help branch from b247a5b to 70e2798 Compare August 23, 2025 11:03
@a7medev
Copy link
Member Author

a7medev commented Aug 23, 2025

I've opened a PR on vscode-swift (swiftlang/vscode-swift#1802) to automatically trigger signature help on accepting a function-like completion item in VS Code.

// LSP 3.18 defines a `noActiveParameterSupport` option which allows the
// active parameter to be `null` causing editors not to show an active
// parameter which would be the best solution here.
parameters.count
Copy link
Member

Choose a reason for hiding this comment

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

Oh, that behavior is interesting. The LSP specification says the following. Does this mean that VS Code does not comply with the LSP spec in this regard?

If omitted or the value lies outside the range of signatures[activeSignature].parameters defaults to 0 if the active signature has parameters

I’m fine keeping this in but we should mention the intended behavior from the LSP spec in the comment and mention that we are deliberately relying on a VS Code LSP-non-compliance if that’s what we’re doing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's VS Code-specific behavior which we use as a workaround here. For editors that are fully LSP-compliant this will have the same behavior as if we didn't return a value and we actually don't have a way of expressing "no active parameter" in that case so it's fine. I actually found rust-analyzer using this trick too.

There are also other VS Code-specific workarounds like setting the active parameter to -1 (microsoft/vscode#145851 (comment)).

I'll update the comment to explain this part too.

@ahoppen
Copy link
Member

ahoppen commented Aug 24, 2025

The screen recording looks great 🤩

One thought that just crossed my mind to extract the documentation for the parameters: SourceKit-LSP does link against docc, so we should be able to use docc to parse the doc comment into a symbol graph and then extract the parameters from there. In general, getting docc into the loop here might be open up new possibilities such as #2256. If you want to tackle this, I would make that a separate PR though.

@a7medev a7medev requested a review from ahoppen August 24, 2025 20:00
@a7medev
Copy link
Member Author

a7medev commented Aug 24, 2025

@ahoppen Thanks for the suggestion, I'll look into it more as I'm not familiar with DocC.

I've updated the comments you mentioned as well, can you please recheck? 🙏🏼

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for adding the explanation.

@a7medev a7medev force-pushed the feat/signature-help branch from d49bd98 to d0e188a Compare September 1, 2025 13:19
@a7medev
Copy link
Member Author

a7medev commented Sep 1, 2025

@ahoppen I rebased the PR on main as it had some conflicts (due to moving default implementations from DocumentationLanguageService to LanguageService in #2261).

@ahoppen
Copy link
Member

ahoppen commented Sep 1, 2025

Thanks for rebasing and sorry for causing the conflict.

@ahoppen
Copy link
Member

ahoppen commented Sep 1, 2025

swiftlang/swift#83378

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Sep 1, 2025

swiftlang/swift#8337

@swift-ci Please test Windows

@a7medev
Copy link
Member Author

a7medev commented Sep 3, 2025

@ahoppen I've implemented preserving the user's selected active signature in 02caee7, can you please review this part as well? 🙏🏼

Sorry for modifying this after the review.

@a7medev a7medev requested a review from ahoppen September 3, 2025 22:28
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Looks good to me, just two nitpicks.

@a7medev a7medev force-pushed the feat/signature-help branch from 02caee7 to de028fd Compare September 4, 2025 10:27
@a7medev
Copy link
Member Author

a7medev commented Sep 4, 2025

@ahoppen Updated. Can you please recheck? 🙏🏼
FYI, swiftlang/swift#83378 has been merged.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

LGTM. Let’s ship this 🚀

@ahoppen
Copy link
Member

ahoppen commented Sep 4, 2025

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Sep 4, 2025

@swift-ci Please test Windows

@a7medev
Copy link
Member Author

a7medev commented Sep 4, 2025

@ahoppen @hamishknight Tests are failing on Windows with errors similar to the following:

<EXPR>:0: error: SwiftSignatureHelpTests.testSignatureHelpEnumCase : threw error "ResponseError(code: LanguageServerProtocol.ErrorCode(rawValue: -32001), message: "No language service implements textDocument/signatureHelp", data: nil)"

Any idea why that is happening? Shouldn't these tests run fine on Windows?

@bnbarham
Copy link
Contributor

bnbarham commented Sep 4, 2025

Any idea why that is happening? Shouldn't these tests run fine on Windows?

I haven't checked the logs, but I see new files with no update to CMakeLists.txt, so my guess would be that is the cause. You'll want to update Sources/SwiftLanguageService/CMakeLists.txt with the new files

@a7medev
Copy link
Member Author

a7medev commented Sep 4, 2025

@bnbarham Interesting. I didn't notice that I needed to add that since it was working fine on my machine. Do we primarily use this CMakeLists.txt file on Windows? 👀

I've added them now. Can you please rerun the tests? 🙏🏼

@bnbarham
Copy link
Contributor

bnbarham commented Sep 4, 2025

Do we primarily use this CMakeLists.txt file on Windows?

Yep :(

@bnbarham
Copy link
Contributor

bnbarham commented Sep 4, 2025

@swift-ci please test

@ahoppen
Copy link
Member

ahoppen commented Sep 5, 2025

@swift-ci Please test Windows

@hamishknight
Copy link
Contributor

🚢

@hamishknight hamishknight merged commit a5854f4 into swiftlang:main Sep 5, 2025
3 checks passed
@bnbarham
Copy link
Contributor

bnbarham commented Sep 5, 2025

Could we add a SkipUnless similar to your completion PR, to make sure that the tests pass when we have an older sourcekitd 🙏?

@a7medev
Copy link
Member Author

a7medev commented Sep 5, 2025

@bnbarham Makes sense. I've opened #2284 to add that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants