mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] IDE: only provide declarations and bindings as completions (#18456)
## 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. ```py foo = 1 f<CURSOR> ``` Similarly, in the following example, `hidden_symbol` was suggested, even though it is not statically visible: ```py 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. ## Test Plan - Updated snapshot tests - New test for statically hidden definitions - Added test for star import
This commit is contained in:
parent
11db567b0b
commit
f1883d71a4
4 changed files with 126 additions and 86 deletions
|
@ -10,6 +10,7 @@ use crate::module_resolver::{Module, resolve_module};
|
|||
use crate::semantic_index::ast_ids::HasScopedExpressionId;
|
||||
use crate::semantic_index::semantic_index;
|
||||
use crate::semantic_index::symbol::FileScopeId;
|
||||
use crate::types::ide_support::all_declarations_and_bindings;
|
||||
use crate::types::{Type, binding_type, infer_scope_types};
|
||||
|
||||
pub struct SemanticModel<'db> {
|
||||
|
@ -66,9 +67,10 @@ impl<'db> SemanticModel<'db> {
|
|||
};
|
||||
let mut symbols = vec![];
|
||||
for (file_scope, _) in index.ancestor_scopes(file_scope) {
|
||||
for symbol in index.symbol_table(file_scope).symbols() {
|
||||
symbols.push(symbol.name().clone());
|
||||
}
|
||||
symbols.extend(all_declarations_and_bindings(
|
||||
self.db,
|
||||
file_scope.to_scope_id(self.db, self.file),
|
||||
));
|
||||
}
|
||||
symbols
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue