[ty] Include definition site for "members of" API

In the course of writing the "add an import" implementation,
I realized that we needed to know which symbols were in scope
and how they were defined. This was necessary to be able to
determine how to add a new import in a way that (minimally)
does not conflict with existing symbols.

I'm not sure that this is fully correct (especially for
symbol bindings) and it's unclear to me in which cases a
definition site will be missing. But this seems to work for
some of the basic cases that I tried.
This commit is contained in:
Andrew Gallant 2025-09-16 13:10:12 -04:00 committed by Andrew Gallant
parent 6ec52991cb
commit 6c3c963f8a
2 changed files with 48 additions and 15 deletions

View file

@ -236,9 +236,9 @@ impl<'db> SemanticModel<'db> {
for (file_scope, _) in index.ancestor_scopes(file_scope) {
completions.extend(
all_declarations_and_bindings(self.db, file_scope.to_scope_id(self.db, self.file))
.map(|member| Completion {
name: member.name,
ty: Some(member.ty),
.map(|memberdef| Completion {
name: memberdef.member.name,
ty: Some(memberdef.member.ty),
kind: None,
builtin: false,
}),