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

Function parameter types should default to what is doc'd if a type cannot be computed #392

Closed
mrennie opened this issue Sep 17, 2014 · 7 comments

Comments

@mrennie
Copy link
Contributor

mrennie commented Sep 17, 2014

Use the following snippet in the Tern demo:

/**

  • @name f
  • @param {Number} one the first one
  • @param {orion.Editor} two
    */
    function f(one, two, three) {
    loop: do{
    t//ASSIST HERE
    //empty
    continue loop;
    } while(true)
    }

Activate assist where indicated and notice the type for 'two' is computed to be '?' I would expect it to be 'orion.Editor' since thats what I said it is.

@marijnh
Copy link
Member

marijnh commented Sep 26, 2014

Is it possible that Tern can not find a type called orion.Editor?

@mrennie
Copy link
Contributor Author

mrennie commented Sep 26, 2014

Yes, that type would not be available in the demo, but I assumed that since the demo was using the doc plugin it would be able to infer the type as orion.Editor. Or does tern ignore what is specified in doc if it cannot find the type while inferring?

@marijnh
Copy link
Member

marijnh commented Sep 29, 2014

Tern currently doesn't have a mechanism for storing types that it only knows the string name of -- it works with type objects that it either got from loading a .json definition file or from analyzing the code itself. You could write a simple .json file that defines orion.Editor and the other types you need, as a way to work around this.

@jgiles
Copy link
Contributor

jgiles commented Oct 1, 2014

Alternatively, the third-party tern-closure plugin creates stand-in types for types in docs that it cannot locate (meaning that an orion.Editor type would be reported, though it probably wouldn't have any useful information until the file where orion.Editor is defined was loaded).

@marijnh
Copy link
Member

marijnh commented Oct 1, 2014

@jgiles That sounds good. How did you solve the problem of the made-up type introducing ambiguity later on?

@jgiles
Copy link
Contributor

jgiles commented Nov 12, 2014

@marijnh At present, stand-in types are just propagated with a low weight, and when the actual value is declared and assigned later it displaces the stand-in.

@marijnh
Copy link
Member

marijnh commented Nov 21, 2014

Attached patch adds something like this to the doc_comments plugin.

@marijnh marijnh closed this as completed Nov 21, 2014
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

No branches or pull requests

3 participants