Code completion: report "semantic context" for every code completion result

Semantic context describes the origin of the declaration and serves the same
purpose as opaque numeric "priority" in Clang -- to determine the most likely
completion.

This is the initial implementation.  There are a few opportunities to bump the
priority of a certain decl by giving it SemanticContextKind::ExprSpecific
context that are not implemented yet.


Swift SVN r9052
This commit is contained in:
Dmitri Hrybenko
2013-10-09 02:08:05 +00:00
parent f07d0c17f0
commit 6895c34741
8 changed files with 363 additions and 115 deletions

View File

@@ -561,13 +561,15 @@ void ModuleFile::lookupVisibleDecls(Module::AccessPathTy accessPath,
return;
for (auto item : *iter)
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)));
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)),
DeclVisibilityKind::VisibleAtTopLevel);
}
for (auto entry : make_range(TopLevelDecls->data_begin(),
TopLevelDecls->data_end())) {
for (auto item : entry)
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)));
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)),
DeclVisibilityKind::VisibleAtTopLevel);
}
}
@@ -643,7 +645,7 @@ void ModuleFile::lookupClassMembers(Module::AccessPathTy accessPath,
dc = dc->getParent();
if (auto nominal = dc->getDeclaredTypeInContext()->getAnyNominal())
if (nominal->getName() == accessPath.front().first)
consumer.foundDecl(vd);
consumer.foundDecl(vd, DeclVisibilityKind::DynamicLookup);
}
}
return;
@@ -652,7 +654,8 @@ void ModuleFile::lookupClassMembers(Module::AccessPathTy accessPath,
for (const auto &list : make_range(ClassMembersByName->data_begin(),
ClassMembersByName->data_end())) {
for (auto item : list)
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)));
consumer.foundDecl(cast<ValueDecl>(getDecl(item.second)),
DeclVisibilityKind::DynamicLookup);
}
}