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
27 changes: 27 additions & 0 deletions autoload/pdv.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 *(.*"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions templates/variable.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** @var {{type}}{{^type}}mixed{{/type}} {{name}} */
1 change: 1 addition & 0 deletions templates_snip/variable.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** @var ${2:{{type}}{{^type}}mixed{{/type}}} ${1:{{name}}} */