From dec30c4e77ef8c2a6c8110d134db73cb231b001b Mon Sep 17 00:00:00 2001 From: FlickerBean Date: Wed, 5 Nov 2014 11:26:38 +0000 Subject: [PATCH 1/2] Update pdv.vim to allow @var documentation Can now document variables (works nicely with phpcomplete.vim) --- autoload/pdv.vim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/autoload/pdv.vim b/autoload/pdv.vim index 777672a..62d9732 100644 --- a/autoload/pdv.vim +++ b/autoload/pdv.vim @@ -59,6 +59,9 @@ let s:regex["attribute"] = '^\(\s*\)\(\(private\s*\|public\s*\|protected\s*\|sta " [:spacce:]*(abstract|final|)[:space:]*(class|interface)+[:space:]+\(extends ([:identifier:])\)?[:space:]*\(implements ([:identifier:][, ]*)+\)? let s:regex["class"] = '^\(\s*\)\(\S*\)\s*\(interface\|class\)\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 *(.*" @@ -79,6 +82,9 @@ let s:mapping = [ \ {"regex": s:regex["class"], \ "function": function("pdv#ParseClassData"), \ "template": "class"}, + \ {"regex": s:regex["variable"], + \ "function": function("pdv#ParseVariableData"), + \ "template": "variable"}, \ ] func! pdv#DocumentCurrentLine() @@ -215,6 +221,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) From a48e719c55ef8d205e621e8f3e132a17432146c1 Mon Sep 17 00:00:00 2001 From: Leigh Date: Wed, 29 Jun 2016 11:28:54 +0100 Subject: [PATCH 2/2] Added default templates for @var doc functionality --- templates/variable.tpl | 1 + templates_snip/variable.tpl | 1 + 2 files changed, 2 insertions(+) create mode 100644 templates/variable.tpl create mode 100644 templates_snip/variable.tpl 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}}} */