Skip to content

Commit eccec44

Browse files
committed
[CodeCompletion] Always suggest call pattern for nested function calls
When completing in cases like `bar(arg: foo(|, option: 1)`, we don’t know if `option` belongs to the call to `foo` or `bar`. Be defensive and also suggest the signature.
1 parent 9607e9d commit eccec44

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/IDE/ArgumentCompletion.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ void ArgumentTypeCheckCompletionCallback::sawSolutionImpl(const Solution &S) {
284284
// and the code completion token doesn’t have a label, we have a case like
285285
// `Point(|)`. Suggest the entire function signature.
286286
IncludeSignature = true;
287+
} else if (!ParentCall->getArgs()->empty() &&
288+
ParentCall->getArgs()->getExpr(0) == CompletionExpr) {
289+
if (auto ParentExpr = CS.getParentExpr(ParentCall);
290+
ParentExpr && CS.getParentExpr(ParentCall)->getArgs()) {
291+
// We are completing in cases like `bar(arg: foo(|, option: 1)`
292+
// In these cases, we don’t know if `option` belongs to the call to `foo`
293+
// or `bar`. Be defensive and also suggest the signature.
294+
IncludeSignature = true;
295+
}
287296
}
288297

289298
Results.push_back(

test/IDE/complete_call_arg.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,3 +1407,14 @@ struct AtStartOfFunctionCallWithExistingParams {
14071407
// AT_START_OF_CALL_ONE_EXISTING_ARGUMENT-DAG: Pattern/Local/Flair[ArgLabels]: {#a: Int#}[#Int#]; name=a:
14081408
}
14091409
}
1410+
1411+
func nestedCallsWithoutClosingParen() {
1412+
func foo(arg: Int, arg2: Int) -> Int { 1 }
1413+
func bar(arg: Int, option: Int) -> Int { 1 }
1414+
1415+
bar(arg: foo(#^NESTED_CALL_AT_START^#, option: 1)
1416+
// NESTED_CALL_AT_START-DAG: Decl[FreeFunction]/Local/Flair[ArgLabels]/TypeRelation[Convertible]: ['(']{#arg: Int#}, {#arg2: Int#}[')'][#Int#];
1417+
1418+
bar(arg: foo(arg: 1, #^NESTED_CALL_AT_SECOND_ARG^#, option: 1)
1419+
// NESTED_CALL_AT_SECOND_ARG-DAG: Pattern/Local/Flair[ArgLabels]: {#arg2: Int#}[#Int#];
1420+
}

0 commit comments

Comments
 (0)