tern icon indicating copy to clipboard operation
tern copied to clipboard

computedRet not used for completions

Open jameshoward opened this issue 7 years ago • 7 comments

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 avatar Dec 14 '17 12:12 jameshoward

@jameshoward Hi, i'm running into the exact same issue. Did you find some workaround?

itaipelles avatar Jul 15 '18 10:07 itaipelles

How about this

{
	"!name": "builder",
	"Builder": {
		"addQuery": {
			"!type": "fn() -> Builder",
			"!doc": "I am an object"
		},
		"build": {
			"!type": "fn() ->Builder",
			"!doc": "I am an object"
		}
	}
}

othree avatar Jul 15 '18 10:07 othree

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.

itaipelles avatar Jul 15 '18 11:07 itaipelles

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.

othree avatar Jul 15 '18 14:07 othree

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 avatar Jul 16 '18 10:07 itaipelles

@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.

othree avatar Aug 08 '18 03:08 othree

Try getting the type of Promise.then, and see that the toString has no return type

itaipelles avatar Aug 08 '18 08:08 itaipelles