Commits

ZyX_I committed 41d7305

@/fwc: Partially added `run' completion (only user functions are supported)

Comments (0)

Files changed (5)

plugin/frawor/fwc/intfuncs.vim

     return s:F.recupglob(filter(glist, 's:_r.os.path.isdir(v:val)'),
                 \        a:fragments, a:i+1)
 endfunction
+"▶1 getuserfunctions :: () → [String]
+" TODO cache results
+function s:F.getuserfunctions()
+    redir => funlist
+    silent function
+    redir END
+    return map(map(filter(split(funlist, "\n"), 'v:val[0] is "f"'),
+                \'split(v:val[9:-2], "(")'),
+                \'[v:val[0]]+split(v:val[1], ", ")')
+endfunction
+" TODO get internal functions (from help?)
 "▲1
 "Filters/checkers --------------------------------------------------------------
 "▶1 `func', `eval'
     let self.typechanged=1
     return self
 endfunction
+function s:r.run.complete(desc, idx, type)
+    let getuserfunctionsstr=self.getfunstatvar('completers',
+                \                              s:F.getuserfunctions,
+                \                              'userfunctions').'()'
+    if a:desc[1][0] is 'list'
+        " XXX a:desc[1] contains one more items then required, as well as output 
+        " of getuserfunctions
+        let ldescr=len(a:desc[1])
+        return self.addmatches('map(filter('.getuserfunctionsstr.
+                    \          ', "len(v:val)=='.ldescr.' || '.
+                    \             '(len(v:val)<='.(ldescr+1).' && '.
+                    \              'v:val[-1] is ''...'')"), "v:val[0]")',
+                    \          type([]))
+    endif
+    return self.addmatches('map('.getuserfunctionsstr.', "v:val[0]")', type([]))
+endfunction
 "▶1 `earg'
 " Replaces {argument} with the result of evaluating itself
 let s:r.earg={'args': []}

test/fwccomplete-redir.in

+:let &rtp.=",".escape($TESTDIR, ',\').'/rtp'
+:let g:testfile="plugin/".g:curtest.".vim"
+:source test-redir.vim

test/fwccompletetests-withredir.dat

+!complete
+#▶1 run
+`run []
+  @W
+  WriteFile
+
+`run [1]
+  @W
+  WriteFile
+
+  @T
+  ToList
+
+  @f
+  frawor#Reload
+
+`run [1 2 3]
+  @f
+  frawor#Setup
+
+# vim: cms=#%s fmr=▶,▲ sw=2 ts=2 sts=2 et

test/rtp/plugin/fwccomplete-redir.vim

+execute frawor#Setup('0.0', {'@/fwc/compiler': '0.0',
+            \                '@/os':           '0.0'}, 1)
+let os=s:_r.os
+let i=1
+let j=1
+let sections=[]
+let prevsections=[]
+let toexecute=''
+let args=[]
+let FWC=''
+let FWCtype=''
+function ToList(line)
+    if a:line[0] is '='
+        return eval(a:line[1:])
+    else
+        if a:line[-1:] is '+'
+            return split(a:line[:-2])+['']
+        else
+            return split(a:line)
+        endif
+    endif
+endfunction
+for line in readfile('fwccompletetests-withredir.dat')
+    let line=substitute(line, '^\s*', '', '')
+    if empty(line)
+        continue
+    elseif line[0] is '#'
+        if char2nr(line[1:])==0x25b6
+            let level=+line[4:]
+            if level<=len(sections)
+                call remove(sections, level-1, -1)
+            endif
+            call add(sections, line[4+len(level)+1:])
+            let i=1
+        endif
+        continue
+    elseif line[0] is ':'
+        execute toexecute."\n".line[1:]
+        let toexecute=''
+        continue
+    elseif line[0] is '\'
+        let toexecute.="\n".line[1:]
+        continue
+    elseif line[0] is '@'
+        let args=[ToList(line[1:])]
+        continue
+    elseif line[0] is '`'
+        let FWC=line[1:]
+        continue
+    elseif line[0] is '+'
+        let FWC.=line[1:]
+        continue
+    elseif line[0] is '!'
+        let FWCtype=line[1:]
+        continue
+    elseif       (!empty($DEBUGTEST) && j!=$DEBUGTEST) ||
+                \(!empty($STARTFROM) && j<$STARTFROM)
+        let i+=1
+        let j+=1
+        continue
+    endif
+    if prevsections!=#sections
+        let prevsections=copy(sections)
+        echom '::: Section <'.join(sections, '/').'>'
+    endif
+    let compargs=[FWC, FWCtype]
+    let result=ToList(line)
+    if !empty($DEBUGTEST)
+        debug let ChFunc=call(s:_f.fwc_compile, compargs, {})
+        debug let realres=call(ChFunc, copy(args), {})
+    else
+        let ChFunc=call(s:_f.fwc_compile, compargs, {})
+        let realres=call(ChFunc, copy(args), {})
+    endif
+    if type(realres)!=type(result) || realres!=result
+        echom '[[[ Test #'.i.'('.j.') '.
+                    \'in section <'.join(sections, '/').'> failed:'
+        echom 'expected '.string(result).','
+        echom 'but got  '.string(realres)
+        echom 'Checked arguments: '.string(args)
+        echom 'FWC string: '.compargs[0]
+        echom 'Check type: '.compargs[1]
+        function g:.ChFunc
+        echom ']]]'
+        break
+    endif
+    let i+=1
+    let j+=1
+    unlet realres result
+endfor
+" vim: fmr=▶,▲

test/test-redir.vim

+if !exists('g:testcmd')
+    let s:testcmd='call FraworLoad(g:testfile[:-5])'
+else
+    let s:testcmd=g:testcmd.' '.fnameescape(g:testfile)
+endif
+let s:testprefix=substitute(g:testfile,
+            \'^\Vplugin/'.escape(g:curtest,'\'), '', '')[:-5]
+if !empty(s:testprefix)
+    let s:testprefix.=': '
+endif
+let s:exception=""
+try
+    execute s:testcmd
+catch /^Frawor:/
+    let s:exception=v:exception
+    call WriteFile(s:testprefix.PurgeFrawor(v:exception))
+endtry
+redir => s:var
+messages
+redir END
+let s:messages=split(s:var, "\n")[1:]
+if !empty(s:messages) && s:messages!=#[s:exception]
+    call map(s:messages, 'PurgeFrawor(v:val)')
+    call WriteFile(['>>> '.s:testprefix.'messages']+s:messages+['<<< messages'])
+endif
+unlet s:messages s:var s:exception s:testprefix