Skip to content

Provide better services for incomplete generic calls #16535

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
4 commits merged into from
Jun 27, 2017
Merged

Provide better services for incomplete generic calls #16535

4 commits merged into from
Jun 27, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jun 14, 2017

Fixes #15412

  • Add a getBestGuessSignature method to the checker which acts like getResolvedSignature, but which does a better job in the case of an error.

  • Normally the type checker will automatically fill in {} for type arguments that it can't infer. We now track when we do this, so if we have a Signature we can tell whether it has a bogus instantiation. Would also be useful for no-inferred-empty-object-type which currently has an unreliable implementation.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 14, 2017

@Andy-MS can you check with @ahejlsberg, he had thoughts about this area for a similar change.

Andy Hanson added 2 commits June 16, 2017 13:27
…have `resolveSignature` always get the best signature if !produceDiagnostics
@@ -69,6 +69,9 @@ namespace ts {
undefinedSymbol.declarations = [];
const argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments");

/** This will be set during calls to `getResolvedSignature` where services determines an apparent number of arguments greater than what is actually provided. */
let apparentArgumentCount: number | undefined;
Copy link
Author

Choose a reason for hiding this comment

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

It would be nice if we just computed this at the moment we need it, but that seems to involve getting the tokens array, which is currently code exclusive to services. See getArgumentCount in signatureHelp.ts.

@ghost ghost requested a review from sandersn June 19, 2017 18:00
@ghost
Copy link
Author

ghost commented Jun 19, 2017

Per discussion with @ahejlsberg, removed getBestGuessSignature in favor of just changing the behavior of getResolvedSignature if !produceDiagnostics. Also removed everything relating to inferredAnyDefaultTypeArgument; we will show an "inferred" type argument even if it is {}.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Seems like a good change, if a little clunky because of the co-ordination between checker and signature help. I assume that the reason the find-longest-candidate code has to move into the checker is that the instantiation has to happen after it runs, and instantiation only happens in the checker. Is this correct?

All else being equal, I'd like to have language-service-specific heuristics like that kept in the language service, so that's why I'm asking.

@@ -15631,22 +15642,35 @@ namespace ts {
// declare function f(a: { xa: number; xb: number; });
Copy link
Member

Choose a reason for hiding this comment

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

comments above here need to be updated and typos fixed (specifically, that → than in one case)

@@ -15689,6 +15714,24 @@ namespace ts {

}

function getBestCandidateIndex(candidates: Signature[], argsCount: number): number {
Copy link
Member

Choose a reason for hiding this comment

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

maybe call this getLongestCandidateIndex

@ghost
Copy link
Author

ghost commented Jun 23, 2017

Unfortunately, it wouldn't be easy to break this out of the checker as we don't just need this behavior in signature help; we also need getContextualType to give us a good contextual signature even in the presence of errors.

@ghost ghost merged commit 1835754 into master Jun 27, 2017
@ghost ghost deleted the generics branch June 27, 2017 16:14
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants