Skip to content

[SourceKit] Compute code completion type relation when wrapping a ContextFreeCodeCompletionResult in a CodeCompletionResult #40999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 25, 2022

This is the last refactoring before we can start computing type relations for global results from the code completion cache.

@ahoppen
Copy link
Member Author

ahoppen commented Jan 25, 2022

@swift-ci Please smoke test macOS

…evel type

Preliminary work to compute the type relation when constructing a contextual code completion result.
@ahoppen ahoppen force-pushed the pr/compute-type-relation-in-contextual-result branch from e07dfff to 35cbe87 Compare February 8, 2022 15:40
@ahoppen ahoppen marked this pull request as ready for review February 8, 2022 15:40
@ahoppen ahoppen requested a review from rintaro February 8, 2022 15:40
@ahoppen
Copy link
Member Author

ahoppen commented Feb 8, 2022

@swift-ci Please smoke test

@rintaro rintaro self-assigned this Feb 15, 2022

/// The context in which this completion item is used. Used to compute the
/// type relation to \c ResultType.
ExpectedTypeContext TypeContext;
Copy link
Member

Choose a reason for hiding this comment

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

Copying ExpectedTypeContext is not trivial. Could you use a reference?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not super easily. If setResultTypes was never called, we don’t have a TypeContext. Currently, it just defaults to an empty ExpectedTypeContext. We could make this a pointer but this also means that we need to accept a pointer in the CodeCompletionResult initializer, which, I think, makes that API worse.

Copy link
Member

Choose a reason for hiding this comment

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

We could make this a pointer but this also means that we need to accept a pointer in the CodeCompletionResult initializer

Can we dereference the pointer when calling CodeCompletionResult constructor?


That being said, I now feel like the ideal solution is that CodeCompletionResultBuilder only build ContextFreeCodeCompletionResult. Then, after collecting all context free results including cached results, we can loop through them to construct contextual CodeCompletionResults using ExpectedTypeContext and DeclContext.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I just thought about it again and figured out it’s better to pass ExpectedTypeContext around using pointers instead of references anyway to match the fact that we are also using DeclContext * and not DeclContext &.

…textFreeCodeCompletionResult in a CodeCompletionResult

[CodeCompletion] Make ExpectedTypeContext a class with explicit getters/setters

This simplifies debugging because you can break when the possible types are set and you can also search for references to `setPossibleType` to figure out where the expected types are being set.
@ahoppen ahoppen force-pushed the pr/compute-type-relation-in-contextual-result branch from f078254 to 6bc0de9 Compare February 16, 2022 19:28
@ahoppen
Copy link
Member Author

ahoppen commented Feb 16, 2022

@swift-ci Please smoke test

@ahoppen ahoppen merged commit bac3b67 into swiftlang:main Feb 16, 2022
@ahoppen ahoppen deleted the pr/compute-type-relation-in-contextual-result branch February 16, 2022 21:13
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.

2 participants