Skip to content

[ty] Sort keyword argument completions higher#22297

Merged
MichaReiser merged 3 commits intoastral-sh:mainfrom
RasmusNygren:fix-argument-completion-order
Jan 6, 2026
Merged

[ty] Sort keyword argument completions higher#22297
MichaReiser merged 3 commits intoastral-sh:mainfrom
RasmusNygren:fix-argument-completion-order

Conversation

@RasmusNygren
Copy link
Contributor

Summary

Fixes astral-sh/ty#2271

Test Plan

Fix existing snapshot tests

@@ -0,0 +1 @@
class Foo(m<CURSOR: metaclass>)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't really capture the sort order of this very well in existing tests in completion.rs::tests so it probably makes sense to capture it here as an eval test

@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Dec 30, 2025
@RasmusNygren RasmusNygren force-pushed the fix-argument-completion-order branch from 99e9db6 to 19c242f Compare January 4, 2026 22:31
Copy link
Member

@MichaReiser MichaReiser 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

If we have identified context-aware argument
completions we know that they will always
be valid and are more likely to more precise
than any other completions, hence we sort
them first.
@MichaReiser MichaReiser force-pushed the fix-argument-completion-order branch from 19c242f to e869046 Compare January 6, 2026 10:51
@MichaReiser MichaReiser enabled auto-merge (squash) January 6, 2026 10:52
@MichaReiser MichaReiser merged commit ce059c4 into astral-sh:main Jan 6, 2026
43 checks passed
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Nice! Thank you!

/// If that's the case, we know this is a very precise completion
/// that should always be valid and can be preferred when
/// ordering completions.
pub is_context_specific: bool,
Copy link
Member

Choose a reason for hiding this comment

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

Yeah okay, I think I buy this. I'm slightly concerned about collapsing all context specific information down into a single bool, but I think this is fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree, I mainly did it like that because clippy started complaining about too many bools in that struct when I added another one and I didn't really feel the need to consider a bigger change at that point when I thought this seemed fine enough for now :) (and it does seem like a reasonable lint to obey and not just slap an ignore on)

Copy link
Member

Choose a reason for hiding this comment

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

Hah. I will happily squash that lint for structs personally. (Too many bool parameters to a function is another story though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe that's what I should have done instead then, for next time :)

@RasmusNygren RasmusNygren deleted the fix-argument-completion-order branch January 15, 2026 18:26
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.

Prioritize keyword arguments in call completions

4 participants