Skip to content

Fix completions in return when in function with contextual 'this' #45340

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
merged 1 commit into from
Aug 6, 2021

Conversation

rbuckton
Copy link
Contributor

@rbuckton rbuckton commented Aug 5, 2021

This change forces the containing function to be type-checked when requesting completions so that contextual this parameters in the containing function are already checked (and cached). Prior to this change, pulling on a type while requesting completions could result in a circularity that doesn't exist at compile time.

Fixes #39946

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Aug 5, 2021
@rbuckton rbuckton requested review from sandersn and weswigham August 5, 2021 19:10
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

Precaching the type in the services layer works, although I wonder if maybe instead we should be doing it during the normal checking process, rather than relying on tree ordering ensuring things are in the cache as needed?

@rbuckton rbuckton marked this pull request as ready for review August 6, 2021 03:58
@rbuckton
Copy link
Contributor Author

rbuckton commented Aug 6, 2021

getCompletionData calls program.getTypeChecker(), so I'm not sure if this is a side-effect of a non-diagnostics-producing checker, or some other reason why the this type isn't already cached.

@rbuckton
Copy link
Contributor Author

rbuckton commented Aug 6, 2021

I'll go with this solution for now, but will revisit if necessary.

@rbuckton rbuckton merged commit 4fc4c18 into main Aug 6, 2021
@rbuckton rbuckton deleted the fix39946 branch August 6, 2021 05:40
BobobUnicorn pushed a commit to BobobUnicorn/TypeScript that referenced this pull request Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'this' autocomplete broken
3 participants