Skip to content

[ty] IDE: only provide declarations and bindings as completions#18456

Merged
sharkdp merged 3 commits intomainfrom
david/ide-only-suggest-declarations-and-bindings
Jun 4, 2025
Merged

[ty] IDE: only provide declarations and bindings as completions#18456
sharkdp merged 3 commits intomainfrom
david/ide-only-suggest-declarations-and-bindings

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Jun 4, 2025

Summary

Previously, all symbols where provided as possible completions. In an example like the following, both foo and f were suggested as completions, because f itself is a symbol.

foo = 1

f<CURSOR>

Similarly, in the following example, hidden_symbol was suggested, even though it is not statically visible:

if 1 + 2 != 3:
    hidden_symbol = 1

hidden_<CURSOR>

With the change suggested here, we only use statically visible declarations and bindings as a source for completions. In the scenario from this comment, we do not include ReadableBuffer anymore (which is available as a symbol, but not re-exported from typing). A test for this was also added here.

image

Test Plan

  • Updated snapshot tests
  • New test for statically hidden definitions
  • Added test for star import

@sharkdp sharkdp added server Related to the LSP server ty Multi-file analysis & type inference labels Jun 4, 2025
assert_snapshot!(test.completions(), @r"
Fo
float
");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

float will be available again once we add all builtins as a source for completions.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2025

mypy_primer results

No ecosystem changes detected ✅

@sharkdp sharkdp marked this pull request as ready for review June 4, 2025 09:18
@MichaReiser MichaReiser requested a review from BurntSushi June 4, 2025 09:40
@sharkdp sharkdp force-pushed the david/ide-only-suggest-declarations-and-bindings branch from 24dd681 to 823a556 Compare June 4, 2025 09:53
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!

@sharkdp sharkdp merged commit f1883d7 into main Jun 4, 2025
35 checks passed
@sharkdp sharkdp deleted the david/ide-only-suggest-declarations-and-bindings branch June 4, 2025 14:11
carljm added a commit to mtshiba/ruff that referenced this pull request Jun 4, 2025
* main:
  [ty] Only consider a type `T` a subtype of a protocol `P` if all of `P`'s members are fully bound on `T` (astral-sh#18466)
  [ty] Exclude members starting with `_abc_` from a protocol interface (astral-sh#18467)
  [ty] Add subdiagnostic suggestion to `unresolved-reference` diagnostic when variable exists on `self` (astral-sh#18444)
  [ty] IDE: only provide declarations and bindings as completions (astral-sh#18456)
  [ty] ty_ide: Hotfix for `expression_scope_id` panics (astral-sh#18455)
  [ty] Improve docs for Class{Literal,Type}::instance_member (astral-sh#18454)
  [ty] Add meta-type tests for legavy TypeVars (astral-sh#18453)
  update to salsa that doesn't panic silently on cycles (astral-sh#18450)
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.

3 participants