Skip to content

[ty] Add function parentheses completion#25305

Merged
MichaReiser merged 10 commits into
mainfrom
micha/ty-complete-function-parentheses
May 29, 2026
Merged

[ty] Add function parentheses completion#25305
MichaReiser merged 10 commits into
mainfrom
micha/ty-complete-function-parentheses

Conversation

@MichaReiser

@MichaReiser MichaReiser commented May 21, 2026

Copy link
Copy Markdown
Member

Summary

Add an opt-in completion setting that inserts parentheses snippets for callable completions.

Closes astral-sh/ty#977

Test Plan

Screen.Recording.2026-05-22.at.12.11.07.mov

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 21, 2026
@MichaReiser MichaReiser force-pushed the micha/ty-complete-function-parentheses branch 2 times, most recently from 3df4dd9 to e68d358 Compare May 21, 2026 22:29
@astral-sh-bot

astral-sh-bot Bot commented May 21, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented May 21, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@MichaReiser MichaReiser force-pushed the micha/ty-complete-function-parentheses branch 2 times, most recently from cab4fd8 to e303636 Compare May 21, 2026 22:35
@astral-sh-bot

astral-sh-bot Bot commented May 21, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Large timing changes:

Project Old Time New Time Change
scipy 2.02s 3.09s +53%

Full report with detailed diff (timing results)

@MichaReiser MichaReiser force-pushed the micha/ty-complete-function-parentheses branch 3 times, most recently from 63906f9 to 13026a7 Compare May 22, 2026 09:07
@MichaReiser MichaReiser marked this pull request as ready for review May 22, 2026 10:40
@astral-sh-bot astral-sh-bot Bot requested a review from lerebear May 22, 2026 10:41
@MichaReiser MichaReiser added the server Related to the LSP server label May 22, 2026

@lerebear lerebear left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me overall, but I think there is one potential regression that we should attend to before we proceed.

Comment thread crates/ty_completion_bench/src/main.rs Outdated
Comment thread crates/ty_server/tests/e2e/completions.rs Outdated
Comment thread crates/ty_server/tests/e2e/completions.rs
Comment thread crates/ty_server/src/server/api/requests/completion.rs Outdated
Comment on lines +61 to +62
completion_settings.complete_function_parentheses &=
client_capabilities.supports_completion_item_snippets();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By contrast, Pyrefly still inserts parens when snippets aren't supported, just without placing the cursor in between the parens. That has its drawbacks (the cursor ends up in an annoying position), but it is potentially less surprising once the user has enabled the complete_function_parentheses setting. Should we perhaps follow suit?

On a related note, do we have enough information to potentially do better than just inserting parens and placing the cursor in between them? For example, are there cases where we understand the signature of the method we're suggesting for completion such that we can add tab stops for each required argument? We needn't do that immediately, but it might be a nice touch for the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

On a related note, do we have enough information to potentially do better than just inserting parens and placing the cursor in between them?

I think so and this is also something that I realized that this would be another use case for snippets. I'd have to check if this is already covered by our signature completions. If not, that would be another great extension.

@MichaReiser MichaReiser force-pushed the micha/ty-complete-function-parentheses branch from 3bbb4b9 to 70bb32a Compare May 27, 2026 09:52

@lerebear lerebear left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the edits; latest looks great ✨

@AlexWaygood AlexWaygood removed their request for review May 27, 2026 19:06
Comment thread crates/ty_ide/src/completion.rs Outdated
Comment thread crates/ty_ide/src/completion.rs Outdated
@MichaReiser MichaReiser force-pushed the micha/ty-complete-function-parentheses branch from b22948f to c57c4d3 Compare May 29, 2026 13:14
@MichaReiser MichaReiser changed the title [ty] Add function parentheses completion setting [ty] Add function parentheses completion May 29, 2026
@MichaReiser MichaReiser merged commit 0c1a69c into main May 29, 2026
59 checks passed
@MichaReiser MichaReiser deleted the micha/ty-complete-function-parentheses branch May 29, 2026 13:25
@tamimbook

Copy link
Copy Markdown

@MichaReiser thank you and the ty team for hearing my idea! love the feature!

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

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete parentheses for function calls when selecting a function completion

3 participants