Skip to content
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

Skip method this type validity filter for objects with more than 20 members #28692

Conversation

weswigham
Copy link
Member

Fixes #23285 specifically by limiting the number of properties we filter methods on to 20 (so if an object has > 20 members, we no longer filter invalid method calls from the completion list), though the underlying issue remains. It's also questionable if the filtering is even really correct, since using the member in a non-calling fashion is still acceptable - the choice to filter methods at all feels somewhat pragmatic.

That underlying issue is that every anonymous type instantiation is unique - so even though we're querying similar types across the ~300 this-type comparisons we perform, since the input anonymous types are differing identities, we repeat a lot of very similar work. Caching on signatures doesn't help here, since each comparison is triggered for a different signature. The issue is simply that if I have 200 methods with this: {item: T}, then every time we infer from {item: string} to {item: T} and instantiate T with string, we get a new overall type identity and need to perform a structural comparison, even though it's still just {item: string}.

Copy link
Member

@sheetalkamat sheetalkamat left a comment

Choose a reason for hiding this comment

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

Could this be confusing from user perspective? I am wondering what we are achieving anything significant through filtering. To me it seems the filtering helps when there are too many options but here we are limiting when there are fewer options so seems contradictory. Change looks good but will let @DanielRosenwasser comment on whether we should skip this type check all the time or with the condition you have.

if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? <ImportTypeNode>node : <PropertyAccessExpression>node.parent, type, symbol)) {
const props = type.getApparentProperties();
for (const symbol of props) {
if (typeChecker.isValidPropertyAccessForCompletions(node.kind === SyntaxKind.ImportType ? <ImportTypeNode>node : <PropertyAccessExpression>node.parent, type, symbol, props.length > 20)) {
Copy link
Member

Choose a reason for hiding this comment

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

Make 20 a constant for better readability and maintainability

@weswigham
Copy link
Member Author

It's probably worth noting that at least @rbuckton apparently has a library that relies on this filtering for more accurate method completions. :S

@weswigham
Copy link
Member Author

Superseded by #31377

@weswigham weswigham closed this May 13, 2019
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.

Long running 'completions' request on TS project using lodash
2 participants