ZyX_I avatar ZyX_I committed 0b69f42

@/fwc: Optimized actions completion compiler for null action case

Comments (0)

Files changed (3)


     "▶2 Length checks, lagsstr and nextsub variables
     if !empty(self.subs)
         let largsstr=self.getlargsstr()
-        if self.type is 'check' || self.type is 'pipe'
+        if type is 'check' || type is 'pipe'
             if !has_key(a:adescr, 'minimum')
                 call s:F.getlenrange(a:adescr)
                 let idx=''
-            if self.type is 'complete' && !self.o.only
+            if type is 'complete' && !self.o.only
                 call self.addif(largsstr.'-1 == '.self.getlastsub())
             call self.compilearg(arg, idx)
             call self.incsub()
-            if self.type is 'complete' && !self.o.only
+            if type is 'complete' && !self.o.only
                 call self.up()
+            if self.onlyfirst
+                return self
+            endif
         if !empty(self.subs)
             unlet nextsub
     "▶2 Check for processed argument length
     " XXX a:0 is checked here
-    if !a:0 && type(self.subs[-1])==type([]) && self.type isnot 'complete'
+    if !a:0 && type(self.subs[-1])==type([]) && type isnot 'complete'
         let largsstr=self.getlargsstr()
         let proclen=self.getlastsub()
         call self.addif(proclen.' isnot '.largsstr)
                 \ 'lavars': {},
                 \'defvals': [],
                 \'typechanged': 0,
+                \'onlyfirst': 0,
     if t.type is 'filter'
         let t.type='pipe'


 "▶1 `earg'
 " Replaces {argument} with the result of evaluating itself
+" TODO completion
 let s:r.earg={'args': []}
 function s:r.earg.pipe(desc, idx, type)
     let curargstr=self.argstr()


         let hasnext=s:F.hasnext(a:adescr, 'next')
         if !hasnext && len(a:adescr.optional)==1
             call self.compadescr(a:adescr.optional[0], a:idx.'.0(optional)')
+            let oldsub=self.getsub(self.subs[-1])
+            if oldsub isnot a:caidxstr
+                call self.let(a:caidxstr, oldsub)
+            endif
             return [[a:caidxstr], addedsavemsgs]
             " TODO
     return self.conclose()
+"▶2 optimizenullact :: &self
+" XXX low-level hacks here
+function s:r.actions.optimizenullact()
+    if len(self.l)==2 && self.l[1][0] is 'if'
+                \&& (len(self.l[1])==3 ||
+                \    (len(self.l[1])==4 && self.l[-1] is 'endif'))
+                \&& len(self.stack[-2])==3
+                \&& self.stack[-2][0] is 'if'
+                \&& self.l[1][1] is self.stack[-2][1]
+        call extend(self.l, self.l[1][2])
+        call remove(self.l, 1)
+    endif
+    return self
 "▶2 compile :: descr, idx, {rolvars}, {lvars} + self → {lvars}
 function s:r.actions.compile(adescr, idx, caidxstr, largsstr, purgemax, type,
             \                nextsub, addedsavemsgs)
                         \.addmatches(fsastr, type([]))
         let savedsub=copy(self.subs[-1])
         if noact isnot 0 && len(noact)>1
-            " FIXME This produces much more code then required. Add a way to add 
-            " completion for the first argument only
-            call self.compadescr(noact[1], idx.'.nullact')
+            let self.onlyfirst+=1
+            call self.compadescr(noact[1], idx.'.nullact').out()
+            call call(s:r.actions.optimizenullact, [], self)
+            let self.onlyfirst-=1
         let self.subs[-1]=savedsub
         call self.up().else()
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.