Skip to content

Fix jsdoc type resolution #24106

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

Closed
wants to merge 94 commits into from
Closed

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented May 14, 2018

  1. Type resolution did not check for all special assignment kinds. Now it does.
  2. Type parameter resolution in @param tags previously used the default walk up the syntax tree, which is incorrect. Type parameters are bound by the containing function, so the walk should start from the parameter itself, not the @param tag.

Notes

  1. This branch is based on jsdoc/callback because it relies on the already-improved jsdoc type resolution there.
  2. Note that in getJSSpecialAssignment, the predicate for prototype methods is a subset of the predicate in getHostSignatureFromJSDoc, so the prototype method check needs to come first in order to correctly look up types on the source constructor function.

An example of prototype method type resolution is something like this:

/** @template T */
function Z() {
}
/** @param {T} t */
function Z.prototype.M = function(t) { }

Fixes #22621

Edit: Now also fixes #20832

sandersn and others added 30 commits May 10, 2018 16:51
Still doesn't work correctly for multiple merges
…eds-to-be-handled-in-excludeSpecs

Add declarationDir to excludeSpec
LEGO: Merge pull request 24077
LEGO: Merge pull request 24097
Fix async generator rejection handling
Cut back on more 'caught exceptions' from vfs
Breaks type parameter resolution that is looked up through prototype
methods, though. I need to fix that still.
* Use SHA256 hash for project info telemetry

* Update API baselines
Andy and others added 16 commits May 16, 2018 12:28
…24169)

* codeFixInferFromUsage: Avoid duplicate fix for variable declaration

* Include VariableDeclaration initializer as a candidate type
* Use jsdoc aliases if visible when printing types

* Modify implementation a bit, add test that aughta change in the new future

* Accept baselines- hold off on typedef template lookup change
… and quick info (#23492)

* Correctly show instantiated signatures for JSX element signature help

* Also bundle fix for quickinfo

* Use more complete cache to avoid duplicate errors
It's throwing an exception (since there's no program from which to
retrieve the SourceFile) and there's no reason to fix it since the
same files are open in the semantic server.
Don't collect open-file telemetry on the syntax server
Remove assert in `symbolToParameterDeclaration`
LEGO: Merge pull request 24183
mhegazy and others added 8 commits May 16, 2018 15:44
* Sort the whole diagnostic

* Also strip references to our repos node_modules, since removing it is hard
LEGO: Merge pull request 24188
add quick fix for import type missing typeof
* Add initial tests

* Add types

* Half of parsing (builds but does not pass tests)

* Parsing done; types are uglier; doesn't crash but doesn't pass

* Bind callback tag

Builds but tests still don't pass

* Only bind param tags inside callback tags

* Fix binding switch to only handle param tags once

* Checking is 1/3 done or so.

Now I'm going to go rename some members to be more uniform. I hate
unnnecessary conditionals.

* Rename typeExpression to type (for some jsdoc)

(maybe I'll rename more later)

* Rename the rest of typeExpressions

Turns out there is a constraint in services such that they all need to
be named the same.

* Few more checker changes

* Revert "Rename the rest of typeExpressions"

This reverts commit f41a96b.

* Revert "Rename typeExpression to type (for some jsdoc)"

This reverts commit 7d2233a.

* Finish undoing typeExpression rename

* Rename and improve getTypeParametersForAliasSymbol

Plus some other small fixes

* Core checking works, but is flabbergastingly messy

I'm serious.

* Callback return types work now

* Fix crash in services

* Make github diff smaller

* Try to make github diff even smaller

* Fix rename for callback tag

* Fix nav bar for callback tag

Also clean up some now-redundant code there to find the name of typedefs.

* Handle ooorder callback tags

Also get rid of redundant typedef name code *in the binder*. It's
everywhere!

* Add ooorder callback tag test

* Parse comments for typedef/callback+display param comments

* Always export callbacks

This requires almost no new code since it is basically the same as
typedefs

* Update baselines

* Fix support for nested namespaced callbacks

And add test

* Callbacks support type parameters

1. Haven't run it with all tests
2. Haven't tested typedef tags yet
3. Still allows shared symbols when on function or class declarations.

* Template tags are now bound correctly

* Test oorder template tags

It works.

* Parser cleanup

* Cleanup types and utilities

As much as possible, and not as much as I would like.

* Handle callback more often in services

* Cleanup of binder and checker

* More checker cleanup

* Remove TODOs and one more cleanup

* Support parameter-less callback tags

* Remove extra bind call on template type parameters

* Bind template tag containers

Doesn't quite work with typedefs, but that's because it's now stricter,
without the typedef fixes. I'm going to merge with jsdoc/callback and
see how it goes.

* Fix fourslash failures

* Stop pre-binding js type aliases

Next up, stop pre-binding js type parameters

* Further cleanup of delayed js type alias binding

* Stop prebinding template tags too

This gets rid of prebinding entirely

* Remove TODO

* Fix lint

* Finish merge with use-jsdoc-aliases

* Update callback tag baselines

* Rename getTypeParametersForAliasSymbol

The real fix is *probably* to rename Type.aliasTypeArguments to
aliasTypeParameters, but I want to make sure and then put it in a
separate PR.
@sandersn
Copy link
Member Author

I've managed to mangle this PR beyond recognition. I'm going to open a new one.

@sandersn sandersn closed this May 17, 2018
@sandersn sandersn deleted the js/fix-jsdoc-type-resolution branch May 17, 2018 16:56
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
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.