Skip to content

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 23, 2023

In a first commit, I split deliverResults into a collectResults call that gathers all the code completion results and then trySolverCompletion is responsible for delivering the results to the code completion consumer.

When we are performing code completion after a call that already has a trailing closure, we first perform the normal postfix completion, which will give us results for operators and member access. We then rewrite the call slightly to include the code completion token as an additional argument, and run argument completion on it. This gives us the completion for the trailing closure label. Once we have collected the results from both completion kinds, we deliver them to the consumer

As a little side-quest, I realized that when computing the code completion results from the cached modules, we were always using the type context of the last lookup that we performed. I changed that slightly to compute a unified type context that contains all possible types from all constraint system solutions. We then use that unified type context to compute the type relations of the global results – this didn’t change any tests.

Oh, and one more thing: When completing after Void, we were providing ==, <= etc operators that are defined on tuples. These also showed up when completing trailing closure labels of a call that returns Void. Since they are never useful, I now hide operators from code completion if the left-hand-side is Void.

rdar://113472967

@ahoppen ahoppen force-pushed the ahoppen/labeled-trailing-closure-solver-based branch 2 times, most recently from 4733bc1 to b48ee42 Compare August 23, 2023 00:36
@ahoppen
Copy link
Member Author

ahoppen commented Aug 23, 2023

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Aug 23, 2023

@swift-ci Please SourceKit stress test

->lookThroughAllOptionalTypes()
->is<AnyFunctionType>()) {
// We are completing an argument after the first trailing closure, i.e.
// a mulitple trailing closure label but the parameter is not a function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple

@ahoppen
Copy link
Member Author

ahoppen commented Aug 23, 2023

Note to self: The stress tester hit 4 new timeouts, which we are accepting because of the improvements this brings and because it unblocks #68080, which deletes a huge amount of code.

@ahoppen ahoppen force-pushed the ahoppen/labeled-trailing-closure-solver-based branch from b48ee42 to 2b4c3bc Compare August 23, 2023 14:48
Comment on lines 86 to 88
if (IdealType.isNull() != Other.IdealType.isNull()) {
IdealType = Type();
} else if (IdealType && Other.IdealType &&
!IdealType->isEqual(Other.IdealType)) {
IdealType = Type();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Seems like this could be reduced to !IdealType || !Other.IdealType || !IdealType->isEqual(Other.IdealType)

…onsumer phase

This will allow us to run two different completion kinds and deliver results from both of them.

Also: Compute a unified type context for global lookup. Previously, we always used the expected type context of the last lookup. But really, we should be considering all possible types from all constraint system solutions when computing code completion results from the cache.
@ahoppen ahoppen force-pushed the ahoppen/labeled-trailing-closure-solver-based branch from 2b4c3bc to 48ce1b3 Compare August 24, 2023 22:52
@ahoppen
Copy link
Member Author

ahoppen commented Sep 1, 2023

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2023

@swift-ci Please test Windows

2 similar comments
@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2023

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented Sep 6, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit acc6c10 into swiftlang:main Sep 6, 2023
@ahoppen ahoppen deleted the ahoppen/labeled-trailing-closure-solver-based branch September 6, 2023 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants