diff --git a/autoload/pdv.vim b/autoload/pdv.vim index f66ec82..8d925c4 100644 --- a/autoload/pdv.vim +++ b/autoload/pdv.vim @@ -75,6 +75,9 @@ let s:regex["interface"] = '^\(\s*\)interface\s\+\(\S\+\)\(\s\+extends\s\+\(\S\+ " 1:indent, 2:name let s:regex["trait"] = '^\(\s*\)trait\s\+\(\S\+\)\s*{\?\s*$' +let s:regex["variable"] = '^\(\s*\)\(\$[^ =]\+\)\s*=\s*\([^;]\+\);$' +let s:regex["newobject"] = '^\s*new\s*\([^(;]\+\).*$' + let s:regex["types"] = {} let s:regex["types"]["array"] = "^array *(.*" @@ -104,6 +107,9 @@ let s:mapping = [ \ {"regex": s:regex["trait"], \ "function": function("pdv#ParseTraitData"), \ "template": "trait"}, + \ {"regex": s:regex["variable"], + \ "function": function("pdv#ParseVariableData"), + \ "template": "variable"}, \ ] func! pdv#DocumentCurrentLine() @@ -289,6 +295,27 @@ func! pdv#ParseAttributeData(line) return l:data endfunc +func! pdv#ParseVariableData(line) + let l:text = getline(a:line) + + let l:data = {} + let l:matches = matchlist(l:text, s:regex["variable"]) + + let l:data["indent"] = l:matches[1] + let l:data["name"] = l:matches[2] + " TODO: Cleanup ; and friends + let l:data["default"] = get(l:matches, 3, '') + + let l:types = matchlist(l:matches[3], s:regex["newobject"]) + if (!empty(l:types)) + let l:data["type"] = l:types[1] + elseif (!empty(l:data["default"])) + let l:data["type"] = s:GuessType(l:data["default"]) + endif + + return l:data +endfunc + func! pdv#ParseFunctionData(line) let l:text = getline(a:line) diff --git a/templates/variable.tpl b/templates/variable.tpl new file mode 100644 index 0000000..20dbb06 --- /dev/null +++ b/templates/variable.tpl @@ -0,0 +1 @@ +/** @var {{type}}{{^type}}mixed{{/type}} {{name}} */ diff --git a/templates_snip/variable.tpl b/templates_snip/variable.tpl new file mode 100644 index 0000000..d8d8157 --- /dev/null +++ b/templates_snip/variable.tpl @@ -0,0 +1 @@ +/** @var ${2:{{type}}{{^type}}mixed{{/type}}} ${1:{{name}}} */