Commits

ZyX_I committed cb363c4

@/fwc: Added possibility to filter completion results using next checks

Comments (0)

Files changed (4)

plugin/frawor/fwc/compiler.vim

                 call call(s:_r.FWC_intfuncs[dname].check, [desc,a:idx, 'pipe'],
                             \self)
             endif
-            if has_key(s:_r.FWC_intfuncs[dname], 'optimize')
-                call call(s:_r.FWC_intfuncs[dname].optimize, [a:idx], self)
-            endif
         elseif has_key(s:_r.FWC_intfuncs[dname], 'complete')
             call call(s:_r.FWC_intfuncs[dname].complete, [desc, a:idx, 'pipe'],
                         \self)
+        else
+            return self
+        endif
+        if has_key(s:_r.FWC_intfuncs[dname], 'optimize')
+            call call(s:_r.FWC_intfuncs[dname].optimize, [a:idx, a:type], self)
         endif
     endif
     "▲2
             endif
             call call(s:_r.FWC_intfuncs[dname].check, [desc, a:idx, 'check'],
                         \self)
-            if has_key(s:_r.FWC_intfuncs[dname], 'optimize')
-                call call(s:_r.FWC_intfuncs[dname].optimize, [a:idx], self)
-            endif
         elseif has_key(s:_r.FWC_intfuncs[dname], 'complete')
             call call(s:_r.FWC_intfuncs[dname].complete, [desc, a:idx, 'check'],
                         \self)
+        else
+            return self
+        endif
+        if has_key(s:_r.FWC_intfuncs[dname], 'optimize')
+            call call(s:_r.FWC_intfuncs[dname].optimize, [a:idx, a:type], self)
         endif
     endif
     "▲2
     endif
     return self
 endfunction
-"▶1 compilearg      :: &self(argcontext, idx[, defcomptype])
+"▶1 compilearg      :: &self(argcontext, idx[, type])
 function s:compiler.compilearg(argcon, idx, ...)
     let type=get(a:000, 0, self.type)
     if a:argcon[0] is 'arg'
     let msg=[]
     let i=0
     let savedonlystrings=self.o.onlystrings
+    if type is 'complete'
+        let addedcompletion=0
+        let addedcycle=0
+        let argidxstr=self.getlvarid('argidx')
+    endif
     for proc in arg
         let i+=1
         let compargs=[proc, a:idx.'.'.i, type]
         elseif comptype is 'defval'
             continue
         endif
-        if type is 'complete' && compargs[0][1][0] is 'intfunc' &&
-                    \get(s:_r.FWC_intfuncs[compargs[0][1][1]], 'breakscomp', 0)
-            break
+        if type is 'complete'
+            if addedcompletion && !addedcycle
+                let addedcycle=1
+                call self.let(argidxstr, 0)
+                            \.while(argidxstr.'<len(@-@)')
+                                \.try()
+                                    \.pushms('throwignore')
+                                    \.witharg(['@-@', [[argidxstr]]])
+            elseif compargs[0][1][0] is 'intfunc' &&
+                        \has_key(s:_r.FWC_intfuncs[compargs[0][1][1]],
+                        \        'breakscomp')
+                break
+            endif
+            if addedcycle
+                let comptype='check'
+                let compargs[2]=comptype
+            endif
         endif
         call call(self['compile'.comptype], compargs, self)
         if self.typechanged
             let self.o.onlystrings=0
             let self.typechanged=0
         endif
-        if type is 'complete' && compargs[0][1][0] is 'intfunc' &&
-                    \get(s:_r.FWC_intfuncs[compargs[0][1][1]], 'stopscomp', 0)
-            break
+        if comptype is 'complete'
+            if compargs[0][1][0] is 'intfunc' &&
+                        \has_key(s:_r.FWC_intfuncs[compargs[0][1][1]],
+                        \        'stopscomp')
+                break
+            endif
+            let addedcompletion=1
         endif
     endfor
     let self.o.onlystrings=savedonlystrings
     if len(self.msgs.own)>pmsgnum
         call remove(self.msgs.own, pmsgnum, -1)
     endif
+    if type is 'complete' && addedcycle
+        call self.without().popms()
+                    \.increment(argidxstr)
+                \.up().catch(s:cfreg)
+                    \.call('remove(@-@, '.argidxstr.')')
+                \.up()
+            \.up()
+    endif
     return self
 endfunction
 "▶1 compadescr      :: &self(adescr[, idx[, purgemax]])
             endif
         endfor
         if !empty(self.subs)
+            unlet nextsub
             let nextsub=copy(self.subs[-1])
         endif
     endif

plugin/frawor/fwc/intfuncs.vim

 let s:r.not={'args': ['arg'], 'breakscomp': 1}
 "▶2 optimize
 " XXX low-level hacks here
-function s:r.not.optimize(idx)
+function s:r.not.optimize(idx, type)
     if len(self.l[1])==2
                 \&& len(self.l[1][0])>2
                 \&& self.l[1][0][0] is 'if'
 "▶2 complete
 function s:r.path.complete(desc, idx, type)
     let spec=a:desc[1]
-    " TODO add filter based on previous/next checks
     let filter=''
     if spec[0] is 'd'
         let spec=spec[1:]

test/fwccomplete.ok

 ::: Section <Built-in completion functions/either>
 ::: Section <Built-in completion functions/first>
 ::: Section <Built-in completion functions/if>
+::: Section <Completion+check composition>
 ::: Section <Different sections/{required}>
 ::: Section <Different sections/{optional}>
 ::: Section <Different sections/{prefixes}>

test/fwccompletetests.dat

 
   @a
   =sort(keys(s:dict))
+#▶1 Completion+check composition
+`(in list match /^a/)
+  @+
+  =filter(copy(s:list), 'v:val[0] is "a"')
+`(in list match /^a/ match /d/)
+  @+
+  =filter(copy(s:list), 'v:val[0] is "a" && stridx(v:val, "d")!=-1')
 #▶1 Different sections
 #▶2 {required}
 `in list
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.