Skip to content

Comments

Assign lower completion ranking to deprecated names in auto import#23188

Merged
BurntSushi merged 4 commits intoastral-sh:mainfrom
Glyphack:auto-import-cmp-deprecated
Feb 11, 2026
Merged

Assign lower completion ranking to deprecated names in auto import#23188
BurntSushi merged 4 commits intoastral-sh:mainfrom
Glyphack:auto-import-cmp-deprecated

Conversation

@Glyphack
Copy link
Contributor

@Glyphack Glyphack commented Feb 9, 2026

Summary

Follow up to #23089 this PR assigns lower completion ranking to deprecated names in auto import suggestions.
The implementation relies on finding a decorator named deprecated in the source code ton consider that name deprecated.

Fixes astral-sh/ty#2654 for real :)

Test Plan

Added another test case for this.

I could not find an

Here's how the behavior changed:

Before:

abstractc

AbstractAsyncContextManager (module: contextlib)
AbstractBasicAuthHandler (module: urllib.request)
AbstractChildWatcher (module: asyncio)
AbstractContextManager (module: contextlib)
AbstractEventLoopPolicy (module: asyncio)
abstractclassmethod (module: abc)
abstractstaticmethod (module: abc)

After:

AbstractAsyncContextManager (module: contextlib)
AbstractBasicAuthHandler (module: urllib.request)
AbstractContextManager (module: contextlib) (*, 3/7)
AbstractEventLoopPolicy (module: asyncio)
AbstractChildWatcher (module: asyncio)
abstractclassmethod (module: abc)
abstractstaticmethod (module: abc)

@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Feb 9, 2026
@Glyphack Glyphack marked this pull request as ready for review February 10, 2026 16:39
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! That was easy. This LGTM with a unit test in crates/ty_ide/src/symbols.rs. You'll probably want to add a helper method PublicTest::exports that returns a &FlatSymbols (see PublicTest::exports_for). Then you can iterate over it and check whether the symbols it contains are deprecated.

@AlexWaygood AlexWaygood removed their request for review February 10, 2026 19:35
In playground this term abstractc is autocompleted to
AbstractContextManager but in the ty_completion_eval this is option 3.
Nevertheless I'm using that because I expect that to show up higher
and this case actually breaks the test case if we don't have the
deprecated functionality.
@Glyphack
Copy link
Contributor Author

The name PublicTest::exports was already taken (if I understand correctly that you wanted to create that function) it was returning the str of the exports. So I created a new function PublicTest::exported_symbols instead that returns the FlatSymbols.

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.

Ah yeah, perfect!

@BurntSushi BurntSushi merged commit 9ba7c4a into astral-sh:main Feb 11, 2026
46 checks passed
@Glyphack Glyphack deleted the auto-import-cmp-deprecated branch February 11, 2026 15:31
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.

[completions] Down-rank deprecated symbols

3 participants