Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Base File.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,9 @@
// If set to true, typing /**<space> will open an inline docblock
"jsdocs_quick_open_inline": true,

// Decide whether you want to have null before or after the type of a variable
// By default 'null' will be placed after the type "array|null"
"jsdocs_null_last": true,

"jsdocs_development_mode": false
}
29 changes: 22 additions & 7 deletions jsdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,44 +777,56 @@ def parseFunction(self, line):
# (arg1, arg2)
+ '\\s*\\(\\s*(?P<args>.*)\\)'
# optional return type
+ '(\\s*?:\\s*(?P<retval>' + self.settings['typeIdentifier'] + '))?',
+ '(\\s*?:\\s*(?P<retval>\\??' + self.settings['typeIdentifier'] + '))?',
line
)
if not res:
return None

return (res.group('name'), res.group('args'), res.group('retval'))

def getArgType(self, arg):
def withNull(self, arg, allowNull):
if allowNull:
nullLast = self.viewSettings.get('jsdocs_null_last') or False
return arg + '|null' if nullLast else 'null|' + arg

return arg

def getArgType(self, arg):
res = re.search(
'(?P<type>' + self.settings['typeIdentifier'] + ')?'
'(?P<type>\\??' + self.settings['typeIdentifier'] + ')?'
+ '\\s*(?P<name>' + self.settings['varIdentifier'] + ')'
+ '(\\s*=\\s*(?P<val>.*))?',
arg
);

if (res):

argType = res.group("type")
argName = res.group("name")
argVal = res.group("val")

allowNull = argType[:1] == '?' or False
if (allowNull):
argType = argType[1:]

# function fnc_name(type $name = val)
if (argType and argVal):

# function fnc_name(array $x = array())
# function fnc_name(array $x = [])
argValType = self.guessTypeFromValue(argVal)
if argType == argValType:
return argType
return self.withNull(argType, allowNull)

# function fnc_name(type $name = null)
if argValType == 'null':
return self.withNull(argType, True)

return argType + "|" + argValType

# function fnc_name(type $name)
if (argType):
return argType
# function fnc_name(type $name)
return self.withNull(argType, allowNull)

# function fnc_name($name = value)
if (argVal):
Expand Down Expand Up @@ -880,6 +892,9 @@ def getFunctionReturnType(self, name, retval):
return 'bool' if shortPrimitives else 'boolean'

if (retval):
if (retval[:1] == '?'):
return self.withNull(retval[1:], True)

return retval

return JsdocsParser.getFunctionReturnType(self, name, retval)
Expand Down