Skip to content

[ty] Autocomplete arguments if in arguments node#24167

Merged
MichaReiser merged 2 commits intoastral-sh:mainfrom
Glyphack:shaygan-arguments-autocompletion
Mar 26, 2026
Merged

[ty] Autocomplete arguments if in arguments node#24167
MichaReiser merged 2 commits intoastral-sh:mainfrom
Glyphack:shaygan-arguments-autocompletion

Conversation

@Glyphack
Copy link
Copy Markdown
Contributor

@Glyphack Glyphack commented Mar 25, 2026

Summary

Addresses this comment.
Fixes astral-sh/ty#3087.

I initially did the same ancestor walking check in both places but then I tried to come up with another way that does not iterate multiple times.
Since in add_argument_completions we are already iterating over node ancestors of the node the cursor is in, we can determine if cursor is in an arguments node.

So I did that instead of duplicating the cursor.covering_node.ancestors() ... code.

Test Plan

Added the test case that would panic in debug build without this fix.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Mar 25, 2026
@Glyphack Glyphack changed the title Autocomplete arguments if in arguments node [ty] Autocomplete arguments if in arguments node Mar 25, 2026
@Glyphack Glyphack force-pushed the shaygan-arguments-autocompletion branch from 2f2828b to 5c78e03 Compare March 25, 2026 07:35
@AlexWaygood AlexWaygood added bug Something isn't working server Related to the LSP server labels Mar 25, 2026
Comment thread crates/ty_ide/src/completion.rs Outdated
}
ast::AnyNodeRef::ExprCall(call) => {
if call.arguments.range().contains_range(cursor.range) {
if in_arguments && call.arguments.range().contains_range(cursor.range) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we still need the contains_range check`?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From the code looks like it's not needed, tests pass too and I tested the lsp locally and it works without it.

@carljm carljm removed their request for review March 25, 2026 18:14
@Glyphack Glyphack force-pushed the shaygan-arguments-autocompletion branch from 7478f30 to a760335 Compare March 26, 2026 16:51
@MichaReiser MichaReiser merged commit 9622285 into astral-sh:main Mar 26, 2026
46 checks passed
@Glyphack Glyphack deleted the shaygan-arguments-autocompletion branch March 27, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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.

Debug version panics on autocompletion when cursor is between two brackets

4 participants