tern
tern copied to clipboard
computedRet not used for completions
Given the definitions below, the completions returned for text 'Builder.' shows addQuery as a fn() with no return type.
{
"!name": "builder",
"Builder": {
"addQuery": {
"!type": "fn() -> !this",
"!doc": "I am an object"
},
"build": {
"!type": "fn() ->!this",
"!doc": "I am an object"
}
}
}
I've done some digging and it looks like the !this results in a retType of ANull and sets computedRet to a function that returns the first argument. When building completions (addCompletion) the type comes from infer.toString, which doesn't add a return type if this.retval.isEmpty(). Since ANull's isEmpty method always returns true, the return type is not added.
@jameshoward Hi, i'm running into the exact same issue. Did you find some workaround?
How about this
{
"!name": "builder",
"Builder": {
"addQuery": {
"!type": "fn() -> Builder",
"!doc": "I am an object"
},
"build": {
"!type": "fn() ->Builder",
"!doc": "I am an object"
}
}
}
I actually ran into this issue in cases that are a bit more complex, for example like Promise.prototype.then: https://github.com/ternjs/tern/blob/master/defs/ecmascript.json#L22 Again, since the return type is !custom, toString does not indicate any return type.
About Promise, I think it should be a default type in infer.js.
Just like Obj, and Fn. And this issue should be solved with this change.
But I still need to discuss with Marijnh. I don't think this will be solved very quick.
Cool. But still, even if Promise will be solved, I think custom return types need a way to define how should their toString behave.
@itaipelles I am looking at this now.
Can you provide any test step for this?
Or you are just looking for the type of a promise.
I use Tern to get the type of a promise object, and it returns Promise.
Try getting the type of Promise.then, and see that the toString has no return type