[CodeCompletion] Add completion for property overrides

This mostly works the same as for functions. It required a slight tweak
to how we handle 'var <complete>' to avoid consuming the code completion
token prematurely.

rdar://problem/21012767

Swift SVN r32844
This commit is contained in:
Ben Langmuir
2015-10-23 05:38:07 +00:00
parent 51495c833c
commit 889b033964
7 changed files with 115 additions and 25 deletions

View File

@@ -3033,14 +3033,18 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
const DeclContext *CurrDeclContext;
SmallVectorImpl<StringRef> &ParsedKeywords;
bool hasFuncIntroducer = false;
bool hasVarIntroducer = false;
public:
CompletionOverrideLookup(CodeCompletionResultSink &Sink,
ASTContext &Ctx,
CompletionOverrideLookup(CodeCompletionResultSink &Sink, ASTContext &Ctx,
const DeclContext *CurrDeclContext,
SmallVectorImpl<StringRef> &ParsedKeywords)
: Sink(Sink), TypeResolver(createLazyResolver(Ctx)),
CurrDeclContext(CurrDeclContext),
ParsedKeywords(ParsedKeywords){}
CurrDeclContext(CurrDeclContext), ParsedKeywords(ParsedKeywords) {
hasFuncIntroducer = isKeywordSpecified("func");
hasVarIntroducer = isKeywordSpecified("var") || isKeywordSpecified("let");
}
bool isKeywordSpecified(StringRef Word) {
return std::find(ParsedKeywords.begin(), ParsedKeywords.end(), Word)
@@ -3072,6 +3076,7 @@ public:
Options.PrintImplicitAttrs = false;
Options.ExclusiveAttrList.push_back(DAK_NoReturn);
Options.PrintOverrideKeyword = false;
Options.PrintPropertyAccessors = false;
VD->print(Printer, Options);
NameOffset = Printer.NameOffset.getValue();
}
@@ -3085,8 +3090,7 @@ public:
->getAnyNominal()
->getFormalAccess();
bool missingDeclIntroducer =
isa<FuncDecl>(VD) && !isKeywordSpecified("func");
bool missingDeclIntroducer = !hasVarIntroducer && !hasFuncIntroducer;
bool missingAccess = !isKeywordSpecified("private") &&
!isKeywordSpecified("public") &&
!isKeywordSpecified("internal");
@@ -3117,6 +3121,14 @@ public:
Builder.addBraceStmtWithCursor();
}
void addVarOverride(const VarDecl *VD, DeclVisibilityKind Reason) {
CodeCompletionResultBuilder Builder(
Sink, CodeCompletionResult::ResultKind::Declaration,
SemanticContextKind::Super, {});
Builder.setAssociatedDecl(VD);
addValueOverride(VD, Reason, Builder);
}
void addConstructor(const ConstructorDecl *CD) {
CodeCompletionResultBuilder Builder(
Sink,
@@ -3148,6 +3160,8 @@ public:
if (!D->hasType())
TypeResolver->resolveDeclSignature(D);
bool hasIntroducer = hasFuncIntroducer || hasVarIntroducer;
if (auto *FD = dyn_cast<FuncDecl>(D)) {
// We can override operators as members.
if (FD->isBinaryOperator() || FD->isUnaryOperator())
@@ -3157,10 +3171,17 @@ public:
if (FD->isAccessor())
return;
addMethodOverride(FD, Reason);
if (!hasIntroducer || hasFuncIntroducer)
addMethodOverride(FD, Reason);
return;
}
if (auto *VD = dyn_cast<VarDecl>(D)) {
if (!hasIntroducer || hasVarIntroducer) {
addVarOverride(VD, Reason);
}
}
if (auto *CD = dyn_cast<ConstructorDecl>(D)) {
if (!isa<ProtocolDecl>(CD->getDeclContext()))
return;