Skip to content

Commit f8a9588

Browse files
committed
---
yaml --- r: 347829 b: refs/heads/master c: f2b5ce4 h: refs/heads/master i: 347827: 405b1da
1 parent e9075db commit f8a9588

File tree

8 files changed

+272
-98
lines changed

8 files changed

+272
-98
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 9505c0f4b52014eb0b2e57cfe2064a2c05b29c9a
2+
refs/heads/master: f2b5ce4b511e8210c98f92b0627a8f19cf3365ca
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class CodeCompletionCallbacks {
209209

210210
virtual void completeAssignmentRHS(AssignExpr *E) {};
211211

212-
virtual void completeCallArg(CodeCompletionExpr *E) {};
212+
virtual void completeCallArg(CodeCompletionExpr *E, bool isFirst) {};
213213

214214
virtual void completeReturnStmt(CodeCompletionExpr *E) {};
215215

trunk/lib/IDE/CodeCompletion.cpp

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13791379
void completeUnresolvedMember(CodeCompletionExpr *E,
13801380
SourceLoc DotLoc) override;
13811381
void completeAssignmentRHS(AssignExpr *E) override;
1382-
void completeCallArg(CodeCompletionExpr *E) override;
1382+
void completeCallArg(CodeCompletionExpr *E, bool isFirst) override;
13831383
void completeReturnStmt(CodeCompletionExpr *E) override;
13841384
void completeYieldStmt(CodeCompletionExpr *E,
13851385
Optional<unsigned> yieldIndex) override;
@@ -3710,81 +3710,14 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
37103710
return;
37113711

37123712
ModuleDecl *CurrModule = CurrDeclContext->getParentModule();
3713+
DeclContext *DC = const_cast<DeclContext *>(CurrDeclContext);
37133714

37143715
// We can only say .foo where foo is a static member of the contextual
37153716
// type and has the same type (or if the member is a function, then the
37163717
// same result type) as the contextual type.
37173718
FilteredDeclConsumer consumer(*this, [=](ValueDecl *VD,
37183719
DeclVisibilityKind Reason) {
3719-
3720-
if (VD->isOperator())
3721-
return false;
3722-
3723-
if (!VD->hasInterfaceType()) {
3724-
TypeResolver->resolveDeclSignature(VD);
3725-
if (!VD->hasInterfaceType())
3726-
return false;
3727-
}
3728-
3729-
if (T->getOptionalObjectType() &&
3730-
VD->getModuleContext()->isStdlibModule()) {
3731-
// In optional context, ignore '.init(<some>)', 'init(nilLiteral:)',
3732-
if (isa<ConstructorDecl>(VD))
3733-
return false;
3734-
// TODO: Ignore '.some(<Wrapped>)' and '.none' too *in expression
3735-
// context*. They are useful in pattern context though.
3736-
}
3737-
3738-
// Enum element decls can always be referenced by implicit member
3739-
// expression.
3740-
if (isa<EnumElementDecl>(VD))
3741-
return true;
3742-
3743-
// Only non-failable constructors are implicitly referenceable.
3744-
if (auto CD = dyn_cast<ConstructorDecl>(VD)) {
3745-
switch (CD->getFailability()) {
3746-
case OTK_None:
3747-
case OTK_ImplicitlyUnwrappedOptional:
3748-
return true;
3749-
case OTK_Optional:
3750-
return false;
3751-
}
3752-
}
3753-
3754-
// Otherwise, check the result type matches the contextual type.
3755-
auto declTy = T->getTypeOfMember(CurrModule, VD);
3756-
if (declTy->is<ErrorType>())
3757-
return false;
3758-
3759-
DeclContext *DC = const_cast<DeclContext *>(CurrDeclContext);
3760-
3761-
// Member types can also be implicitly referenceable as long as it's
3762-
// convertible to the contextual type.
3763-
if (auto CD = dyn_cast<TypeDecl>(VD)) {
3764-
declTy = declTy->getMetatypeInstanceType();
3765-
3766-
// Emit construction for the same type via typealias doesn't make sense
3767-
// because we are emitting all `.init()`s.
3768-
if (declTy->isEqual(T))
3769-
return false;
3770-
return swift::isConvertibleTo(declTy, T, *DC);
3771-
}
3772-
3773-
// Only static member can be referenced.
3774-
if (!VD->isStatic())
3775-
return false;
3776-
3777-
if (isa<FuncDecl>(VD)) {
3778-
// Strip '(Self.Type) ->' and parameters.
3779-
declTy = declTy->castTo<AnyFunctionType>()->getResult();
3780-
declTy = declTy->castTo<AnyFunctionType>()->getResult();
3781-
} else if (auto FT = declTy->getAs<AnyFunctionType>()) {
3782-
// The compiler accepts 'static var factory: () -> T' for implicit
3783-
// member expression.
3784-
// FIXME: This emits just 'factory'. We should emit 'factory()' instead.
3785-
declTy = FT->getResult();
3786-
}
3787-
return declTy->isEqual(T) || swift::isConvertibleTo(declTy, T, *DC);
3720+
return isReferenceableByImplicitMemberExpr(CurrModule, DC, T, VD);
37883721
});
37893722

37903723
auto baseType = MetatypeType::get(T);
@@ -4700,10 +4633,26 @@ void CodeCompletionCallbacksImpl::completeAssignmentRHS(AssignExpr *E) {
47004633
Kind = CompletionKind::AssignmentRHS;
47014634
}
47024635

4703-
void CodeCompletionCallbacksImpl::completeCallArg(CodeCompletionExpr *E) {
4636+
void CodeCompletionCallbacksImpl::completeCallArg(CodeCompletionExpr *E,
4637+
bool isFirst) {
47044638
CurDeclContext = P.CurDeclContext;
47054639
CodeCompleteTokenExpr = E;
47064640
Kind = CompletionKind::CallArg;
4641+
4642+
ShouldCompleteCallPatternAfterParen = false;
4643+
if (isFirst) {
4644+
ShouldCompleteCallPatternAfterParen = true;
4645+
if (Context.LangOpts.CodeCompleteCallPatternHeuristics) {
4646+
// Lookahead one token to decide what kind of call completions to provide.
4647+
// When it appears that there is already code for the call present, just
4648+
// complete values and/or argument labels. Otherwise give the entire call
4649+
// pattern.
4650+
Token next = P.peekToken();
4651+
if (!next.isAtStartOfLine() && !next.is(tok::eof) && !next.is(tok::r_paren)) {
4652+
ShouldCompleteCallPatternAfterParen = false;
4653+
}
4654+
}
4655+
}
47074656
}
47084657

47094658
void CodeCompletionCallbacksImpl::completeReturnStmt(CodeCompletionExpr *E) {
@@ -5408,13 +5357,32 @@ void CodeCompletionCallbacksImpl::doneParsing() {
54085357
}
54095358
case CompletionKind::CallArg : {
54105359
ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr);
5411-
if (!ContextInfo.getPossibleNames().empty()) {
5360+
5361+
bool shouldPerformGlobalCompletion = true;
5362+
5363+
if (ShouldCompleteCallPatternAfterParen &&
5364+
!ContextInfo.getPossibleCallees().empty()) {
5365+
Lookup.setHaveLParen(true);
5366+
for (auto &typeAndDecl : ContextInfo.getPossibleCallees())
5367+
Lookup.tryFunctionCallCompletions(typeAndDecl.first,
5368+
typeAndDecl.second);
5369+
Lookup.setHaveLParen(false);
5370+
5371+
shouldPerformGlobalCompletion =
5372+
!Lookup.FoundFunctionCalls ||
5373+
(Lookup.FoundFunctionCalls &&
5374+
Lookup.FoundFunctionsWithoutFirstKeyword);
5375+
} else if (!ContextInfo.getPossibleNames().empty()) {
54125376
Lookup.addArgNameCompletionResults(ContextInfo.getPossibleNames());
5413-
break;
5377+
5378+
shouldPerformGlobalCompletion = !ContextInfo.getPossibleTypes().empty();
5379+
}
5380+
5381+
if (shouldPerformGlobalCompletion) {
5382+
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
5383+
ContextInfo.isSingleExpressionBody());
5384+
DoPostfixExprBeginning();
54145385
}
5415-
Lookup.setExpectedTypes(ContextInfo.getPossibleTypes(),
5416-
ContextInfo.isSingleExpressionBody());
5417-
DoPostfixExprBeginning();
54185386
break;
54195387
}
54205388

0 commit comments

Comments
 (0)