spadgos/sublime-jsdocs — Issue #38: @return type detection
Author: ton4y
Created: 2012-02-17 18:49:02+00:00
State: open

This is not an issue, rather a request for implementing a feature.

As I can see from the Python source, there is no functionality about guessing a function's return value (in PHP), other than by checking if function's name stars with get / set / add and so on.

It would be very nice if it would look into the function's body and detect return statements. Then we can make a detection algorithm that would rely on typecasts, variable types and so on. If there are many return statements, it is possible to check if they all relate to the same type and suggest it, otherwise just set the return type to 'mixed' instead of [type].

Here are some suggestions on how to detect return type:

If there is a typecast:
return (type)
...will clearly mean that the return type is the one in the brackets.

If the return is a new object / array:
return array(...) or return new Object(...)
In the first case the type is clearly array and in the second it is the object's name.

If the return is a plain value:
return 1 or return 3.14 or return "some string" or return 'another string' etc.
This is actually already implemented in function guessTypeFromValue.

If the return is a variable:
return $var;
Here is where it gets complex. This is rather advanced / extra guess, so its not that important, but it is not impossible to track-back the variable and check for typecasts, plain value assigns and other (the above checks could be used as well).

I do not know Python, so I cannot tell how to implement all these features, but I know they shouldn't be impossible.
I guess the variable track-back could be rather "slow", so it can be an optional feature?

Anyway, I thought I could suggest some "modifications" that I think would be handy for people extensively using such features (like me).

Thanks!