From 76b917f42662e5f7a19000951f12ea6bda01c454 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Wed, 30 Oct 2019 20:39:02 -0700 Subject: [PATCH 01/13] dojo: add tab completion This is initial support for type-aware tab completion. When you hit tab, it tries to complete the word you're in the middle of using a face or arm in the subject at that point in the code. It also shows all possible matches and their associated types. It's nearly instantaneous. Notes: - It advances to the longest common prefix, so if you hit tab on `ab` and the only possible results are `abcde` and `abcdz`, then it'll write `abcd` and print both out (with their types). - If there are fewer than ten matches, it prints the type along with the face. Printing types is too slow to use all the time, but with 10 it's essentially instantaneous. - The match closest in the subject to you (i.e. smallest axis number) is displayed lowest (closest to your focus). Examples below, where `` represents me hitting tab while my cursor is at that position (the line with the `` is not preserved in the actual output). ``` ~zod:dojo> eth ----- ethereum #t/<11.qcl {<3.ltb 27.ipf 7.ecf 36.uek 92.bjk 247.ows 51.mvt 126.xjf 41.mac 1.ane $141> <21.yeb 27.ipf 7.ecf 36.uek 92.bjk 247.ows 51.mvt 126.xjf 41.mac 1.ane $141>}> ethereum-types #t/<3.ltb 27.ipf 7.ecf 36.uek 92.bjk 247.ows 51.mvt 126.xjf 41.mac 1.ane $141> ~zod:dojo> ethereum ~zod:dojo> |= zong=@ud z ----- zing #t/<1.dqs {* <126.xjf 41.mac 1.ane $141>}> zap #t/<1.iot {tub/{p/{p/@ud q/@ud} q/""} <1.rff {daf/@t <247.ows 51.mvt 126.xjf 41.mac 1.ane $141>}>}> zuse #t/$309 zong #t/@ud ~zod:dojo> |= zong=@ud zo ----- zong #t/@ud ~zod:dojo> |= zong=@ud zong ~zod:dojo> hoon-version trel quip pole unit qual lone ... about 600 more lines ... unity html zuse eny now our ~zod:dojo> ``` Functionally, this is in a state where I'd be comfortable shipping it. It doesn't interfere with anything if you don't press tab, and it's perfectly OTA-able. I do think its output is a little verbose, but that can be tuned over time as people try it and determine what feels good in practice. Additional notes: - There are plenty of similar systems for other languages, but my most direct inspiration is Idris's editor tools. This is implemented for the dojo, but I actually want it in my editor, which is why the meat is all defind in a library. I've only tested on dojo one-liners, so I don't know the performance on large blocks of code. - The default type printer isn't great for this use case. In particular, - Cores should not print anything about their context - The `#t/` should go away - If it looks like a gate, we should print its return value - Maybe special handling for molds, but if the above is done, then for example `bone` is `* -> @ud`. - The worst part about our wing ordering is that it really screws up tab completion. You want to do `point.owner-address` instead of `owner-address.point` because that lets you type `point.ow`. I weakly prefer reading it how we do it now, but it's really not great. You could do an (dojo-specific?) alternate syntax of `point;owner-address`; this is a simple transformation. - Regardless of the above, this should handle the case where we're in the middle of defining a wing; it doesn't right now. - When a variable is shadowed, we show both of them. We should probably show the shadowed one with a `^`. - We probably shouldn't print out hundreds of results. Maybe just the closest 50 with ellipses. - This gets you any face in your subject, regardless of whether its type is reasonable. We could limit that some by copying the `gol` logic in mint, so that if the pseudo-backward-inference engine happens to know what type it should be, you can filter the tab results according to if they nest in that type. This would be "strongly type-aware". --- pkg/arvo/app/chat-cli.hoon | 1 + pkg/arvo/app/dojo.hoon | 110 ++++++++++++++--- pkg/arvo/app/talk.hoon | 1 + pkg/arvo/lib/auto.hoon | 238 ++++++++++++++++++++++++++++++++++++ pkg/arvo/lib/hood/drum.hoon | 4 + pkg/arvo/sur/sole.hoon | 13 +- 6 files changed, 342 insertions(+), 25 deletions(-) create mode 100644 pkg/arvo/lib/auto.hoon diff --git a/pkg/arvo/app/chat-cli.hoon b/pkg/arvo/app/chat-cli.hoon index f89e1910ac..662a3a9c1b 100644 --- a/pkg/arvo/app/chat-cli.hoon +++ b/pkg/arvo/app/chat-cli.hoon @@ -301,6 +301,7 @@ %det (edit +.act) %clr [~ this] %ret obey + %tab [~ this] == :: +edit: apply sole edit :: diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index 1c3b09e716..7aba7c4165 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -3,7 +3,7 @@ :: :: :: /? 309 :: arvo kelvin /- *sole, lens :: -/+ sole, pprint :: +/+ sole, pprint, auto :: :: :: :: :::: :: :::: :: :: :: @@ -678,6 +678,7 @@ $det (dy-edit +.act) $ret (dy-done (tufa buf.say)) $clr dy-stop + $tab +>+> == :: ++ dy-cage |=(num/@ud (~(got by rez) num)) :: known cage @@ -724,23 +725,6 @@ :+ %$ %noun ?~(b !>([~ ~]) (dy-vase p.u.b)) :: - ++ dy-hoon-head :: dynamic state - :: todo: how do i separate the toplevel 'dojo state' comment? - :: dojo state - :: - :: our: the name of this urbit - :: now: the current time - :: eny: a piece of random entropy - :: - ^- cage - :- %noun - =+ sloop=|=({a/vase b/vase} ?:(=(*vase a) b ?:(=(*vase b) a (slop a b)))) - %+ sloop - %- ~(rep by var) - |= {{a/term @ b/vase} c/vase} ^- vase - (sloop b(p face+[a p.b]) c) - !>([our=our now=now eny=eny]:hid) - :: ++ dy-made-dial :: dialog product |= cag/cage ^+ +>+> @@ -814,7 +798,7 @@ =+ too=(dy-hoon-mark gen) =- ?~(too - [%cast he-disc u.too -]) :+ %ride gen - :- [%$ dy-hoon-head] + :- [%$ he-hoon-head] :^ %plan he-rail `coin`blob+** `scaffold:ford`[he-rail zuse sur lib ~ ~] :: @@ -1112,6 +1096,76 @@ == == :: + ++ he-tab + |= pos=@ud + ^+ +> + =* res +> + =/ buf (tufa buf.say) + :: Find beg-pos by searching backward to where the current term + :: begins + =+ ^- [id=(unit term) *] + (scan `tape`(flop (scag pos buf)) ;~(plug (punt sym) (star prn))) + =/ beg-pos + ?~ id + pos + (sub pos (met 3 u.id)) + =/ txt=tape + ;: weld + (scag beg-pos buf) + "magic-spoon" + ?~ id + "" + "." + (slag beg-pos buf) + "\0a" + == + =+ vex=((full parse-command-line:he-parser) [1 1] txt) + ?. ?=([* ~ [* @ %ex *] *] vex) + res + =/ typ p:(slop q:he-hoon-head !>(..dawn)) + =/ tl (tablist:auto typ p.q.q.p.u.q.vex) + =/ advance (autoadvance:auto typ p.q.q.p.u.q.vex) + =? res ?=(^ advance) + =/ to-send (trip (rsh 3 (sub pos beg-pos) u.advance)) + =| fxs=(list sole-effect) + |- ^+ res + ?~ to-send + (he-diff %mor (flop fxs)) + =^ lic say (~(transmit sole say) %ins pos `@c`i.to-send) + $(to-send t.to-send, fxs [`sole-effect`det+lic fxs], pos +(pos)) + :: If couldn't search (eg cursor not in appropriate position), do + :: nothing. + :: + ?: ?=(~ tl) + res + :: If no options, ring the bell + :: + ?: =([~ ~] tl) + (he-diff %bel ~) + :: If only one option, don't print unless the option is already + :: typed in. + :: + ?: &(?=([* ~] u.tl) !=((met 3 (need advance)) (sub pos beg-pos))) + res + :: Else, print results + :: + =+ =/ lots (gth (lent u.tl) 10) + =/ long + ?: lots + 0 + (roll (turn u.tl |=([=term *] (met 3 term))) max) + %- (slog leaf/"-----" ~) + %+ turn u.tl + |= [=term =type] + ?: lots + %- (slog leaf+(trip term) ~) + ~ + =/ =tape + "{(trip term)} {(trip (fil 3 (sub long (met 3 term)) ' '))} {}" + %- (slog leaf+tape ~) + ~ + res + :: ++ he-type :: apply input |= act/sole-action ^+ +> @@ -1121,6 +1175,7 @@ $det (he-stir +.act) $ret (he-done (tufa buf.say)) $clr he-pine(buf "") + $tab (he-tab +.act) == :: ++ he-lame :: handle error @@ -1130,6 +1185,23 @@ ?^ poy he-pine:~(dy-amok dy u.poy) he-pine :: XX give mean to original keystroke + :: + ++ he-hoon-head :: dynamic state + :: todo: how do i separate the toplevel 'dojo state' comment? + :: dojo state + :: + :: our: the name of this urbit + :: now: the current time + :: eny: a piece of random entropy + :: + ^- cage + :- %noun + =+ sloop=|=({a/vase b/vase} ?:(=(*vase a) b ?:(=(*vase b) a (slop a b)))) + %+ sloop + %- ~(rep by var) + |= {{a/term @ b/vase} c/vase} ^- vase + (sloop b(p face+[a p.b]) c) + !>([our=our now=now eny=eny]:hid) -- :: ++ prep diff --git a/pkg/arvo/app/talk.hoon b/pkg/arvo/app/talk.hoon index bbfcea76e6..22bd5fbeb0 100644 --- a/pkg/arvo/app/talk.hoon +++ b/pkg/arvo/app/talk.hoon @@ -658,6 +658,7 @@ $det (sh-edit +.act) $clr ..sh-sole :: (sh-pact ~) :: XX clear to PM-to-self? $ret sh-obey + $tab ..sh-sole == :: ++ sh-edit diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon new file mode 100644 index 0000000000..bcb8b0031c --- /dev/null +++ b/pkg/arvo/lib/auto.hoon @@ -0,0 +1,238 @@ +:: Autocompletion for hoon. +:: +|% ++$ ids (list [=term =type]) +++ get-identifiers + |= ty=type + %- flop + |- ^- ids + ?- ty + %noun ~ + %void ~ + [%atom *] ~ + [%cell *] + %+ weld + $(ty p.ty) + $(ty q.ty) + :: + [%core *] + %- weld + :_ $(ty p.ty) + ^- (list (pair term type)) + %- zing + %+ turn ~(tap by q.r.q.ty) + |= [term =tome] + %+ turn + ~(tap by q.tome) + |= [name=term =hoon] + ^- (pair term type) + ~| term=term + [name ~(play ~(et ut ty) ~[name] ~)] + :: + [%face *] + ?^ p.ty + ~ + [p.ty q.ty]~ + :: + [%fork *] + ~| %find-fork + !! :: eh, fuse? + :: + [%hint *] $(ty q.ty) + [%hold *] $(ty ~(repo ut ty)) + == +:: +++ search-prefix + |= [sid=term =ids] + ^- (list [term type]) + %+ skim ids + |= [id=term ty=type] + =(sid (end 3 (met 3 sid) id)) +:: +++ longest-match + |= matches=(list [=term =type]) + ^- term + ?~ matches + '' + =/ n 1 + =/ last (met 3 term.i.matches) + |- ^- term + ?: (gth n last) + term.i.matches + =/ prefix (end 3 n term.i.matches) + ?: |- ^- ? + ?| ?=(~ t.matches) + ?& =(prefix (end 3 n term.i.t.matches)) + $(t.matches t.t.matches) + == == + $(n +(n)) + (end 3 (dec n) term.i.matches) +:: +++ find-type-mule + |= [sut=type gen=hoon] + ^- (unit [term type]) + =/ res (mule |.((find-type sut gen))) + ?- -.res + %& p.res + %| ((slog (flop (scag 1 p.res))) ~) + == +:: +:: Get the subject type of the wing where you've put the "magic-spoon". +:: +++ find-type + |= [sut=type gen=hoon] + =* loop $ + |^ + ^- (unit [term type]) + ?- gen + [%cnts [%magic-spoon ~] *] `['' sut] + [%cnts [%magic-spoon @ ~] *] `[i.t.p.gen sut] + [^ *] (both p.gen q.gen) + [%ktcn *] loop(gen p.gen) + [%brcn *] (grow q.gen) + [%brvt *] (grow q.gen) + [%cnts *] + |- ^- (unit [term type]) + =* inner-loop $ + ?~ q.gen + ~ + %+ replace + loop(gen q.i.q.gen) + |. inner-loop(q.gen t.q.gen) + :: + [%dtkt *] (spec-and-hoon p.gen q.gen) + [%dtls *] loop(gen p.gen) + [%rock *] ~ + [%sand *] ~ + [%tune *] ~ + [%dttr *] (both p.gen q.gen) + [%dtts *] (both p.gen q.gen) + [%dtwt *] loop(gen p.gen) + [%hand *] ~ + [%ktbr *] loop(gen p.gen) + [%ktls *] (both p.gen q.gen) + [%ktpd *] loop(gen p.gen) + [%ktsg *] loop(gen p.gen) + [%ktwt *] loop(gen p.gen) + [%note *] loop(gen q.gen) + [%sgzp *] (both p.gen q.gen) + [%sgbn *] loop(gen q.gen) :: should check for hoon in p.gen + [%tsbn *] (change p.gen q.gen) + [%tscm *] + %+ replace + loop(gen p.gen) + |.(loop(gen q.gen, sut (~(busk ut sut) p.gen))) + :: + [%wtcl *] (bell p.gen q.gen r.gen) + [%fits *] (both p.gen wing+q.gen) + [%wthx *] loop(gen wing+q.gen) + [%dbug *] loop(gen q.gen) + [%zpcm *] (both p.gen q.gen) + [%lost *] loop(gen p.gen) + [%zpmc *] (both p.gen q.gen) + [%zpts *] loop(gen p.gen) + [%zpvt *] !! + [%zpzp *] ~ + * + =+ doz=~(open ap gen) + ?: =(doz gen) + ~_ (show [%c 'hoon'] [%q gen]) + ~> %mean.'play-open' + !! + loop(gen doz) + == + :: + ++ replace + |= [a=(unit [term type]) b=(trap (unit [term type]))] + ^- (unit [term type]) + ?~(a $:b a) + :: + ++ both + |= [a=hoon b=hoon] + (replace loop(gen a) |.(loop(gen b))) + :: + ++ bell + |= [a=hoon b=hoon c=hoon] + (replace loop(gen a) |.((replace loop(gen b) |.(loop(gen c))))) + :: + ++ spec-and-hoon + |= [a=spec b=hoon] + (replace (find-type-in-spec sut a) |.(loop(gen b))) + :: + ++ change + |= [a=hoon b=hoon] + (replace loop(gen a) |.(loop(gen b, sut (~(play ut sut) a)))) + :: + ++ grow + |= m=(map term tome) + =/ tomes ~(tap by m) + |- ^- (unit [term type]) + =* outer-loop $ + ?~ tomes + ~ + =/ arms ~(tap by q.q.i.tomes) + |- ^- (unit [term type]) + =* inner-loop $ + ?~ arms + outer-loop(tomes t.tomes) + %+ replace + loop(gen q.i.arms, sut (~(play ut sut) gen)) + |. inner-loop(arms t.arms) + -- +:: +:: Not implemented yet. I wonder whether we should modify types found +:: in spec mode such that if it's a mold that produces a type, it +:: should just display the type and not that it's technically a +:: function. +:: +++ find-type-in-spec + |= [sut=type pec=spec] + ^- (unit [term type]) + !! +:: +++ replace-hax + |= code=tape + %+ scan code + %+ cook + |= res=(list $@(@ [~ (unit term)])) + %- trip + %- crip + %+ turn res + |= elem=$@(@ [~ (unit term)]) + ?@ elem + elem + ?~ +.elem + 'magic-spoon' + (cat 3 'magic-spoon.' u.+.elem) + %- star + ;~ pose + ;~ less + hax + prn + == + :: + (stag ~ ;~(pfix hax (punt sym))) + == +:: +++ autoadvance + |= [sut=type gen=hoon] + %+ bind (find-type-mule sut gen) + |= [id=term typ=type] + (longest-match (search-prefix id (get-identifiers typ))) +:: +++ auto-advance + |= [sut=type code=cord] + (autoadvance sut (scan (replace-hax (trip code)) vest)) +:: +++ tablist + |= [sut=type gen=hoon] + %+ bind (find-type-mule sut gen) + |= [id=term typ=type] + (search-prefix id (get-identifiers typ)) +:: +++ tab-list + |= [sut=type code=cord] + %+ bind (find-type sut (scan (replace-hax (trip code)) vest)) + |= [id=term typ=type] + (search-prefix id (get-identifiers typ)) +-- diff --git a/pkg/arvo/lib/hood/drum.hoon b/pkg/arvo/lib/hood/drum.hoon index 878b436ba0..351ae3862a 100644 --- a/pkg/arvo/lib/hood/drum.hoon +++ b/pkg/arvo/lib/hood/drum.hoon @@ -589,6 +589,7 @@ $f (ta-aro %r) $g ?~ ris ta-bel (ta-hom(pos.hit num.hit, ris ~) [%set ~]) + $i ta-tab $k =+ len=(lent buf.say.inp) ?: =(pos.inp len) ta-bel @@ -856,6 +857,9 @@ ++ ta-ret :: hear return (ta-act %ret ~) :: + ++ ta-tab :: hear tab + (ta-act %tab pos.inp) + :: ++ ta-ser :: reverse search |= ext/(list @c) ^+ +> diff --git a/pkg/arvo/sur/sole.hoon b/pkg/arvo/sur/sole.hoon index e19b086392..e01ebcfdda 100644 --- a/pkg/arvo/sur/sole.hoon +++ b/pkg/arvo/sur/sole.hoon @@ -6,8 +6,9 @@ ++ sole-action :: sole to app $% :: {$abo ~} :: reset interaction {$det sole-change} :: command line edit - {$ret ~} :: submit and clear - {$clr ~} :: exit context + {$ret ~} :: submit and clear + {$clr ~} :: exit context + {$tab pos=@ud} :: tab complete == :: ++ sole-buffer (list @c) :: command state ++ sole-change :: network change @@ -20,18 +21,18 @@ $% {$del p/@ud} :: delete one at {$ins p/@ud q/@c} :: insert at {$mor p/(list sole-edit)} :: combination - {$nop ~} :: no-op + {$nop ~} :: no-op {$set p/sole-buffer} :: discontinuity == :: ++ sole-effect :: app to sole - $% {$bel ~} :: beep + $% {$bel ~} :: beep {$blk p/@ud q/@c} :: blink+match char at - {$clr ~} :: clear screen + {$clr ~} :: clear screen {$det sole-change} :: edit command {$err p/@ud} :: error point {$klr p/styx} :: styled text line {$mor p/(list sole-effect)} :: multiple effects - {$nex ~} :: save clear command + {$nex ~} :: save clear command {$pro sole-prompt} :: set prompt {$sag p/path q/*} :: save to jamfile {$sav p/path q/@} :: save to file From 4d0e77a6b28d6769a652cbf9d5795210920942ca Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 13:55:48 -0700 Subject: [PATCH 02/13] dojo: add a better function printer It's useful to know what a function takes and produces, so this changes the autocomplete type prettyprinter to emphasize those. This also gives a nice syntax for molds. Examples: ``` ----- add {a/@ b/@} -> @ ~zod:dojo> add ----- term * -> @tas ~zod:dojo> term ----- sign-transaction {tx/{nonce/@ud gas-price/@ud gas/@ud to/@ux value/@ud data/@ux chain-id/@ux} pk/@} -> @ux ~zod:dojo> sign-transaction:key:ethereum ----- wind {a/(* -> *) b/(* -> *)} -> * -> ?({$give p/*} {$pass p// q/*} {$slip p/*}) ~zod:dojo> wind ``` --- pkg/arvo/app/dojo.hoon | 6 +- pkg/arvo/lib/auto.hoon | 2 +- pkg/arvo/lib/easy-print.hoon | 481 +++++++++++++++++++++++++++++++++++ 3 files changed, 486 insertions(+), 3 deletions(-) create mode 100644 pkg/arvo/lib/easy-print.hoon diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index 7aba7c4165..62e8f4dcae 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -3,7 +3,7 @@ :: :: :: /? 309 :: arvo kelvin /- *sole, lens :: -/+ sole, pprint, auto :: +/+ sole, pprint, auto, easy-print :: :: :: :: :::: :: :::: :: :: :: @@ -1160,8 +1160,10 @@ ?: lots %- (slog leaf+(trip term) ~) ~ + =/ type-text ~(ram re ~(duck easy-print type)) + =/ spaces (trip (fil 3 (sub long (met 3 term)) ' ')) =/ =tape - "{(trip term)} {(trip (fil 3 (sub long (met 3 term)) ' '))} {}" + "{(trip term)} {spaces} {type-text}" %- (slog leaf+tape ~) ~ res diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index bcb8b0031c..341d93d4b3 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -131,7 +131,7 @@ [%lost *] loop(gen p.gen) [%zpmc *] (both p.gen q.gen) [%zpts *] loop(gen p.gen) - [%zpvt *] !! + [%zpvt *] (both q.gen r.gen) [%zpzp *] ~ * =+ doz=~(open ap gen) diff --git a/pkg/arvo/lib/easy-print.hoon b/pkg/arvo/lib/easy-print.hoon new file mode 100644 index 0000000000..5970e0373c --- /dev/null +++ b/pkg/arvo/lib/easy-print.hoon @@ -0,0 +1,481 @@ +:: Fast type printing that's easy on the eyes or your money back +:: +=> |% + ++ cape {p/(map @ud wine) q/wine} + ++ wine + $@ $? $noun + $path + $type + $void + $wall + $wool + $yarn + == + $% {$mato p/term} + {$gate p/hoon q/type r/wine} + {$core p/(list @ta) q/wine} + {$face p/term q/wine} + {$list p/term q/wine} + {$pear p/term q/@} + {$bswt p/(list wine)} + {$plot p/(list wine)} + {$stop p/@ud} + {$tree p/term q/wine} + {$unit p/term q/wine} + == + -- +|_ sut/type +++ dash + |= {mil/tape lim/char lam/tape} + ^- tape + =/ esc (~(gas in *(set @tD)) lam) + :- lim + |- ^- tape + ?~ mil [lim ~] + ?: ?| =(lim i.mil) + =('\\' i.mil) + (~(has in esc) i.mil) + == + ['\\' i.mil $(mil t.mil)] + ?: (lte ' ' i.mil) + [i.mil $(mil t.mil)] + ['\\' ~(x ne (rsh 2 1 i.mil)) ~(x ne (end 2 1 i.mil)) $(mil t.mil)] +:: +++ deal |=(lum/* (dish dole lum)) +++ dial + |= ham/cape + =+ gid=*(set @ud) + =| top-level=? :: don't need circumfix punctuation + =< `tank`-:$ + |% + ++ many + |= haz/(list wine) + ^- {(list tank) (set @ud)} + ?~ haz [~ gid] + =^ mor gid $(haz t.haz) + =^ dis gid ^$(q.ham i.haz) + [[dis mor] gid] + :: + ++ $ + ^- {tank (set @ud)} + ?- q.ham + $noun :_(gid [%leaf '*' ~]) + $path :_(gid [%leaf '/' ~]) + $type :_(gid [%leaf '#' 't' ~]) + $void :_(gid [%leaf '#' '!' ~]) + $wool :_(gid [%leaf '*' '"' '"' ~]) + $wall :_(gid [%leaf '*' '\'' '\'' ~]) + $yarn :_(gid [%leaf '"' '"' ~]) + {$mato *} :_(gid [%leaf '@' (trip p.q.ham)]) + {$gate *} + =^ sam gid + ?. ?=([%plot * * *] r.q.ham) + ?: ?=(%plot -.r.q.ham) + %- (slog -:$(q.ham r.q.ham) ~) + `gid + `gid + [`u=- +]:$(q.ham i.p.r.q.ham, top-level |) + :_ gid + :+ %rose + :- " -> " + ?: top-level + ["" ""] + ["(" ")"] + :+ ?~(sam leaf+"_" u.sam) + =/ res (mule |.((~(play ut q.q.ham) p.q.ham))) + ?- -.res + %& duck(sut p.res) + %| leaf+"###" + == + ~ + :: + {$core *} + =^ sam gid + ?. ?=([%plot * * ~] q.q.ham) + `gid + [`u=- +]:$(q.ham i.p.q.q.ham) + :_ gid + ?~ sam + :+ %rose + [[' ' ~] ['<' ~] ['>' ~]] + |- ^- (list tank) + ?~ p.q.ham ~ + [[%leaf (rip 3 i.p.q.ham)] $(p.q.ham t.p.q.ham)] + :+ %rose + [" -> " "" ""] + :+ u.sam + :+ %rose + [[' ' ~] ['<' ~] ['>' ~]] + |- ^- (list tank) + ?~ p.q.ham ~ + [[%leaf (rip 3 i.p.q.ham)] $(p.q.ham t.p.q.ham)] + ~ + :: + {$face *} + =^ cox gid $(q.ham q.q.ham) + :_(gid [%palm [['/' ~] ~ ~ ~] [%leaf (trip p.q.ham)] cox ~]) + :: + {$list *} + =^ cox gid $(q.ham q.q.ham) + :_(gid [%rose [" " (weld (trip p.q.ham) "(") ")"] cox ~]) + :: + {$bswt *} + =^ coz gid (many p.q.ham) + :_(gid [%rose [[' ' ~] ['?' '(' ~] [')' ~]] coz]) + :: + {$plot *} + =^ coz gid (many p.q.ham) + :_(gid [%rose [[' ' ~] ['{' ~] ['}' ~]] coz]) + :: + {$pear *} + :_(gid [%leaf '$' ~(rend co [%$ p.q.ham q.q.ham])]) + :: + {$stop *} + =+ num=~(rend co [%$ %ud p.q.ham]) + ?: (~(has in gid) p.q.ham) + :_(gid [%leaf '#' num]) + =^ cox gid + %= $ + gid (~(put in gid) p.q.ham) + q.ham (~(got by p.ham) p.q.ham) + == + :_(gid [%palm [['.' ~] ~ ~ ~] [%leaf ['^' '#' num]] cox ~]) + :: + {$tree *} + =^ cox gid $(q.ham q.q.ham) + :_(gid [%rose [" " (weld (trip p.q.ham) "(") ")"] cox ~]) + :: + {$unit *} + =^ cox gid $(q.ham q.q.ham) + :_(gid [%rose [" " (weld (trip p.q.ham) "(") ")"] cox ~]) + == + -- +:: +++ dish !: + |= {ham/cape lum/*} ^- tank + ~| [%dish-h ?@(q.ham q.ham -.q.ham)] + ~| [%lump lum] + ~| [%ham ham] + %- need + =| gil/(set {@ud *}) + |- ^- (unit tank) + ?- q.ham + $noun + %= $ + q.ham + ?: ?=(@ lum) + [%mato %$] + :- %plot + |- ^- (list wine) + [%noun ?:(?=(@ +.lum) [[%mato %$] ~] $(lum +.lum))] + == + :: + $path + :- ~ + :+ %rose + [['/' ~] ['/' ~] ~] + |- ^- (list tank) + ?~ lum ~ + ?@ lum !! + ?> ?=(@ -.lum) + [[%leaf (rip 3 -.lum)] $(lum +.lum)] + :: + $type + =+ tyr=|.((dial dole)) + =+ vol=tyr(sut lum) + =+ cis=;;(tank .*(vol [%9 2 %0 1])) + :^ ~ %palm + [~ ~ ~ ~] + [[%leaf '#' 't' '/' ~] cis ~] + :: + $wall + :- ~ + :+ %rose + [[' ' ~] ['<' '|' ~] ['|' '>' ~]] + |- ^- (list tank) + ?~ lum ~ + ?@ lum !! + [[%leaf (trip ;;(@ -.lum))] $(lum +.lum)] + :: + $wool + :- ~ + :+ %rose + [[' ' ~] ['<' '<' ~] ['>' '>' ~]] + |- ^- (list tank) + ?~ lum ~ + ?@ lum !! + [(need ^$(q.ham %yarn, lum -.lum)) $(lum +.lum)] + :: + $yarn + [~ %leaf (dash (tape lum) '"' "\{")] + :: + $void + ~ + :: + {$mato *} + ?. ?=(@ lum) + ~ + :+ ~ + %leaf + ?+ (rash p.q.ham ;~(sfix (cook crip (star low)) (star hig))) + ~(rend co [%$ p.q.ham lum]) + $$ ~(rend co [%$ %ud lum]) + $t (dash (rip 3 lum) '\'' ~) + $tas ['%' ?.(=(0 lum) (rip 3 lum) ['$' ~])] + == + :: + {$gate *} + !! + :: + {$core *} + :: XX needs rethinking for core metal + :: ?. ?=(^ lum) ~ + :: => .(lum `*`lum) + :: =- ?~(tok ~ [~ %rose [[' ' ~] ['<' ~] ['>' ~]] u.tok]) + :: ^= tok + :: |- ^- (unit (list tank)) + :: ?~ p.q.ham + :: =+ den=^$(q.ham q.q.ham) + :: ?~(den ~ [~ u.den ~]) + :: =+ mur=$(p.q.ham t.p.q.ham, lum +.lum) + :: ?~(mur ~ [~ [[%leaf (rip 3 i.p.q.ham)] u.mur]]) + [~ (dial ham)] + :: + {$face *} + =+ wal=$(q.ham q.q.ham) + ?~ wal + ~ + [~ %palm [['=' ~] ~ ~ ~] [%leaf (trip p.q.ham)] u.wal ~] + :: + {$list *} + ?: =(~ lum) + [~ %leaf '~' ~] + =- ?~ tok + ~ + [~ %rose [[' ' ~] ['~' '[' ~] [']' ~]] u.tok] + ^= tok + |- ^- (unit (list tank)) + ?: ?=(@ lum) + ?.(=(~ lum) ~ [~ ~]) + =+ [for=^$(q.ham q.q.ham, lum -.lum) aft=$(lum +.lum)] + ?. &(?=(^ for) ?=(^ aft)) + ~ + [~ u.for u.aft] + :: + {$bswt *} + |- ^- (unit tank) + ?~ p.q.ham + ~ + =+ wal=^$(q.ham i.p.q.ham) + ?~ wal + $(p.q.ham t.p.q.ham) + wal + :: + {$plot *} + =- ?~ tok + ~ + [~ %rose [[' ' ~] ['[' ~] [']' ~]] u.tok] + ^= tok + |- ^- (unit (list tank)) + ?~ p.q.ham + ~ + ?: ?=({* ~} p.q.ham) + =+ wal=^$(q.ham i.p.q.ham) + ?~(wal ~ [~ [u.wal ~]]) + ?@ lum + ~ + =+ gim=^$(q.ham i.p.q.ham, lum -.lum) + ?~ gim + ~ + =+ myd=$(p.q.ham t.p.q.ham, lum +.lum) + ?~ myd + ~ + [~ u.gim u.myd] + :: + {$pear *} + ?. =(lum q.q.ham) + ~ + =. p.q.ham + (rash p.q.ham ;~(sfix (cook crip (star low)) (star hig))) + =+ fox=$(q.ham [%mato p.q.ham]) + ?> ?=({~ $leaf ^} fox) + ?: ?=(?($n $tas) p.q.ham) + fox + [~ %leaf '%' p.u.fox] + :: + {$stop *} + ?: (~(has in gil) [p.q.ham lum]) ~ + =+ kep=(~(get by p.ham) p.q.ham) + ?~ kep + ~|([%stop-loss p.q.ham] !!) + $(gil (~(put in gil) [p.q.ham lum]), q.ham u.kep) + :: + {$tree *} + =- ?~ tok + ~ + [~ %rose [[' ' ~] ['{' ~] ['}' ~]] u.tok] + ^= tok + =+ tuk=*(list tank) + |- ^- (unit (list tank)) + ?: =(~ lum) + [~ tuk] + ?. ?=({n/* l/* r/*} lum) + ~ + =+ rol=$(lum r.lum) + ?~ rol + ~ + =+ tim=^$(q.ham q.q.ham, lum n.lum) + ?~ tim + ~ + $(lum l.lum, tuk [u.tim u.rol]) + :: + {$unit *} + ?@ lum + ?.(=(~ lum) ~ [~ %leaf '~' ~]) + ?. =(~ -.lum) + ~ + =+ wal=$(q.ham q.q.ham, lum +.lum) + ?~ wal + ~ + [~ %rose [[' ' ~] ['[' ~] [']' ~]] [%leaf '~' ~] u.wal ~] + == +:: +++ doge + |= ham/cape + =- ?+ woz woz + {$list * {$mato $'ta'}} %path + {$list * {$mato $'t'}} %wall + {$list * {$mato $'tD'}} %yarn + {$list * $yarn} %wool + == + ^= woz + ^- wine + ?. ?=({$stop *} q.ham) + ?: ?& ?= {$bswt {$pear $n $0} {$plot {$pear $n $0} {$face *} ~} ~} + q.ham + =(1 (met 3 p.i.t.p.i.t.p.q.ham)) + == + [%unit =<([p q] i.t.p.i.t.p.q.ham)] + q.ham + =+ may=(~(get by p.ham) p.q.ham) + ?~ may + q.ham + =+ nul=[%pear %n 0] + ?. ?& ?=({$bswt *} u.may) + ?=({* * ~} p.u.may) + |(=(nul i.p.u.may) =(nul i.t.p.u.may)) + == + q.ham + =+ din=?:(=(nul i.p.u.may) i.t.p.u.may i.p.u.may) + ?: ?& ?=({$plot {$face *} {$face * $stop *} ~} din) + =(p.q.ham p.q.i.t.p.din) + =(1 (met 3 p.i.p.din)) + =(1 (met 3 p.i.t.p.din)) + == + :+ %list + (cat 3 p.i.p.din p.i.t.p.din) + q.i.p.din + ?: ?& ?= $: $plot + {$face *} + {$face * $stop *} + {{$face * $stop *} ~} + == + din + =(p.q.ham p.q.i.t.p.din) + =(p.q.ham p.q.i.t.t.p.din) + =(1 (met 3 p.i.p.din)) + =(1 (met 3 p.i.t.p.din)) + =(1 (met 3 p.i.t.t.p.din)) + == + :+ %tree + %^ cat + 3 + p.i.p.din + (cat 3 p.i.t.p.din p.i.t.t.p.din) + q.i.p.din + q.ham +:: +++ dole + ^- cape + =+ gil=*(set type) + =+ dex=[p=*(map type @) q=*(map @ wine)] + =< [q.p q] + |- ^- {p/{p/(map type @) q/(map @ wine)} q/wine} + =- [p.tez (doge q.p.tez q.tez)] + ^= tez + ^- {p/{p/(map type @) q/(map @ wine)} q/wine} + ?: (~(meet ut sut) -:!>(*type)) + [dex %type] + ?- sut + $noun [dex sut] + $void [dex sut] + {$atom *} [dex ?~(q.sut [%mato p.sut] [%pear p.sut u.q.sut])] + {$cell *} + =+ hin=$(sut p.sut) + =+ yon=$(dex p.hin, sut q.sut) + :- p.yon + :- %plot + ?:(?=({$plot *} q.yon) [q.hin p.q.yon] [q.hin q.yon ~]) + :: + {$core *} + ?: ?=([[%$ * [[%$ @ *] ~ ~]] ~ ~] q.r.q.sut) + =/ dad $(sut p.sut) + :- p.dad + ~! q.r.q.sut + [%gate q.n.q.q.n.q.r.q.sut sut(r.p.q %gold) q.dad] + =+ yad=$(sut p.sut) + :- p.yad + =+ ^= doy ^- {p/(list @ta) q/wine} + ?: ?=({$core *} q.yad) + [p.q.yad q.q.yad] + [~ q.yad] + :- %core + :_ q.doy + :_ p.doy + %^ cat 3 + %~ rent co + :+ %$ %ud + %- ~(rep by (~(run by q.r.q.sut) |=(tome ~(wyt by q.+<)))) + |=([[@ a=@u] b=@u] (add a b)) + %^ cat 3 + ?-(r.p.q.sut $gold '.', $iron '|', $lead '?', $zinc '&') + =+ gum=(mug q.r.q.sut) + %+ can 3 + :~ [1 (add 'a' (mod gum 26))] + [1 (add 'a' (mod (div gum 26) 26))] + [1 (add 'a' (mod (div gum 676) 26))] + == + :: + {$hint *} + $(sut q.sut) + :: + {$face *} + =+ yad=$(sut q.sut) + ?^(p.sut yad [p.yad [%face p.sut q.yad]]) + :: + {$fork *} + =+ yed=(sort ~(tap in p.sut) aor) + =- [p [%bswt q]] + |- ^- {p/{p/(map type @) q/(map @ wine)} q/(list wine)} + ?~ yed + [dex ~] + =+ mor=$(yed t.yed) + =+ dis=^$(dex p.mor, sut i.yed) + [p.dis q.dis q.mor] + :: + {$hold *} + =+ hey=(~(get by p.dex) sut) + ?^ hey + [dex [%stop u.hey]] + ?: (~(has in gil) sut) + =+ dyr=+(~(wyt by p.dex)) + [[(~(put by p.dex) sut dyr) q.dex] [%stop dyr]] + =+ rom=$(gil (~(put in gil) sut), sut ~(repo ut sut)) + =+ rey=(~(get by p.p.rom) sut) + ?~ rey + rom + [[p.p.rom (~(put by q.p.rom) u.rey q.rom)] [%stop u.rey]] + == +:: +++ duck (dial dole) +-- From 4482997a16c53fa995ab4a8e3a7bfdc0ab58561d Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 14:24:37 -0700 Subject: [PATCH 03/13] dojo, drum: give tab completion as true output This stops slogging the tab completion and intead adds a +sole-effect for tab completion output. This is morally correct, and it lets dojo clients show tab completions how they want. For example, web dojo could implement this as a drop-down box. Another advantage is that this puts the rendering logic in drum, which knows the width of the terminal. Thus, we can make sure each match takes no more than one line by truncating with ellipses. If there's only one match and it's already fully typed, then we display the whole type. --- pkg/arvo/app/dojo.hoon | 21 ++------------------- pkg/arvo/lib/hood/drum.hoon | 34 +++++++++++++++++++++++++++++++++- pkg/arvo/sur/sole.hoon | 3 ++- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index 62e8f4dcae..db67b641b3 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -3,7 +3,7 @@ :: :: :: /? 309 :: arvo kelvin /- *sole, lens :: -/+ sole, pprint, auto, easy-print :: +/+ sole, pprint, auto :: :: :: :: :::: :: :::: :: :: :: @@ -1149,24 +1149,7 @@ res :: Else, print results :: - =+ =/ lots (gth (lent u.tl) 10) - =/ long - ?: lots - 0 - (roll (turn u.tl |=([=term *] (met 3 term))) max) - %- (slog leaf/"-----" ~) - %+ turn u.tl - |= [=term =type] - ?: lots - %- (slog leaf+(trip term) ~) - ~ - =/ type-text ~(ram re ~(duck easy-print type)) - =/ spaces (trip (fil 3 (sub long (met 3 term)) ' ')) - =/ =tape - "{(trip term)} {spaces} {type-text}" - %- (slog leaf+tape ~) - ~ - res + (he-diff %tab u.tl) :: ++ he-type :: apply input |= act/sole-action diff --git a/pkg/arvo/lib/hood/drum.hoon b/pkg/arvo/lib/hood/drum.hoon index 351ae3862a..6c28bf8cf7 100644 --- a/pkg/arvo/lib/hood/drum.hoon +++ b/pkg/arvo/lib/hood/drum.hoon @@ -3,7 +3,7 @@ :: :: :: /? 310 :: version /- *sole -/+ sole +/+ sole, easy-print :: :: :: :::: :: :: :: :: :: @@ -393,6 +393,37 @@ (se-link gyl) +>.$ :: +++ se-tab :: print tab completions + |= tl/(list {=term =type}) + ^+ +> + =/ lots (gth (lent tl) 10) + =/ long + ?: lots + 0 + (roll (turn tl |=([=term *] (met 3 term))) max) + + %- se-dump + %- flop + ^- (list tank) + :- leaf+"-----" + %+ turn tl + |= [=term =type] + ?: lots + leaf+(trip term) + =/ type-tank ~(duck easy-print type) + =/ type-text ~(ram re type-tank) + =/ spaces (trip (fil 3 (sub long (met 3 term)) ' ')) + =/ =tape "{(trip term)} {spaces} {type-text}" + :: If type is too long and not the only result, abbreviate + :: + ?: (gth (lent type-text) edg) + ?: ?=([* ~] tl) + :+ %rose + ["" "" ""] + ~[leaf+(trip term) type-tank] + leaf+(weld (scag (sub edg 3) tape) "...") + leaf+tape +:: ++ se-dump :: print tanks |= tac/(list tank) ^+ +> @@ -650,6 +681,7 @@ $(p.fec t.p.fec, +>.^$ ^$(fec i.p.fec)) {$nex *} ta-nex {$pro *} (ta-pro +.fec) + {$tab *} +>(..ta (se-tab p.fec)) {$tan *} +>(..ta (se-dump p.fec)) {$sag *} +>(..ta (se-blit fec)) {$sav *} +>(..ta (se-blit fec)) diff --git a/pkg/arvo/sur/sole.hoon b/pkg/arvo/sur/sole.hoon index e01ebcfdda..eef99d5eb2 100644 --- a/pkg/arvo/sur/sole.hoon +++ b/pkg/arvo/sur/sole.hoon @@ -8,7 +8,7 @@ {$det sole-change} :: command line edit {$ret ~} :: submit and clear {$clr ~} :: exit context - {$tab pos=@ud} :: tab complete + {$tab pos/@ud} :: tab complete == :: ++ sole-buffer (list @c) :: command state ++ sole-change :: network change @@ -36,6 +36,7 @@ {$pro sole-prompt} :: set prompt {$sag p/path q/*} :: save to jamfile {$sav p/path q/@} :: save to file + {$tab p/(list {=term =type})} :: tab-complete list {$tan p/(list tank)} :: classic tank :: {$taq p/tanq} :: modern tank {$txt p/tape} :: text line From ee63e122ea5019cfdd837841466c2d1fa10acb6b Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 14:56:54 -0700 Subject: [PATCH 04/13] dojo, auto: move insert-magic logic to lib/auto This changes the entry-points in lib/auto so that clients never have to handle magic-spoon. You can specify either a tape of code with a position index or a preparsed hoon (presumably you ran +insert-magic before parsing). --- pkg/arvo/app/dojo.hoon | 24 ++---------- pkg/arvo/lib/auto.hoon | 89 +++++++++++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index db67b641b3..a5592ffe33 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -1100,31 +1100,13 @@ |= pos=@ud ^+ +> =* res +> - =/ buf (tufa buf.say) - :: Find beg-pos by searching backward to where the current term - :: begins - =+ ^- [id=(unit term) *] - (scan `tape`(flop (scag pos buf)) ;~(plug (punt sym) (star prn))) - =/ beg-pos - ?~ id - pos - (sub pos (met 3 u.id)) - =/ txt=tape - ;: weld - (scag beg-pos buf) - "magic-spoon" - ?~ id - "" - "." - (slag beg-pos buf) - "\0a" - == + =+ [beg-pos=@ud txt=tape]=(insert-magic:auto pos (tufa buf.say)) =+ vex=((full parse-command-line:he-parser) [1 1] txt) ?. ?=([* ~ [* @ %ex *] *] vex) res =/ typ p:(slop q:he-hoon-head !>(..dawn)) - =/ tl (tablist:auto typ p.q.q.p.u.q.vex) - =/ advance (autoadvance:auto typ p.q.q.p.u.q.vex) + =/ tl (tab-list-hoon:auto typ p.q.q.p.u.q.vex) + =/ advance (advance-hoon:auto typ p.q.q.p.u.q.vex) =? res ?=(^ advance) =/ to-send (trip (rsh 3 (sub pos beg-pos) u.advance)) =| fxs=(list sole-effect) diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index 341d93d4b3..0fa75ef3ef 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -2,6 +2,9 @@ :: |% +$ ids (list [=term =type]) +:: +:: Get all the identifiers accessible if this type is your subject. +:: ++ get-identifiers |= ty=type %- flop @@ -42,6 +45,8 @@ [%hold *] $(ty ~(repo ut ty)) == :: +:: Get all the identifiers that start with sid. +:: ++ search-prefix |= [sid=term =ids] ^- (list [term type]) @@ -49,6 +54,8 @@ |= [id=term ty=type] =(sid (end 3 (met 3 sid) id)) :: +:: Get the longest prefix of a list of identifiers. +:: ++ longest-match |= matches=(list [=term =type]) ^- term @@ -68,6 +75,9 @@ $(n +(n)) (end 3 (dec n) term.i.matches) :: +:: Run +find-type safely, printing the first line of the stack trace on +:: error. +:: ++ find-type-mule |= [sut=type gen=hoon] ^- (unit [term type]) @@ -190,49 +200,66 @@ ^- (unit [term type]) !! :: -++ replace-hax - |= code=tape - %+ scan code - %+ cook - |= res=(list $@(@ [~ (unit term)])) - %- trip - %- crip - %+ turn res - |= elem=$@(@ [~ (unit term)]) - ?@ elem - elem - ?~ +.elem - 'magic-spoon' - (cat 3 'magic-spoon.' u.+.elem) - %- star - ;~ pose - ;~ less - hax - prn - == +:: Insert magic marker in hoon source at the given position. +:: +++ insert-magic + |= [pos=@ud txt=tape] + ^- [beg-pos=@ud txt=tape] + :: Find beg-pos by searching backward to where the current term + :: begins :: - (stag ~ ;~(pfix hax (punt sym))) + =+ ^- [id=(unit term) *] + (scan `tape`(flop (scag pos txt)) ;~(plug (punt sym) (star prn))) + =/ beg-pos + ?~ id + pos + (sub pos (met 3 u.id)) + :- beg-pos + :: Insert "magic-spoon" marker so +find-type can identify where to + :: stop. + :: + ;: weld + (scag beg-pos txt) + "magic-spoon" + ?~ id + "" + "." + (slag beg-pos txt) + "\0a" == :: -++ autoadvance +:: Produce the longest possible advance without choosing between +:: matches. +:: +:: Takes a +hoon which has already has a magic-spoon marker. Useful if +:: you want to handle your own parsing. +:: +++ advance-hoon |= [sut=type gen=hoon] %+ bind (find-type-mule sut gen) |= [id=term typ=type] (longest-match (search-prefix id (get-identifiers typ))) :: -++ auto-advance - |= [sut=type code=cord] - (autoadvance sut (scan (replace-hax (trip code)) vest)) +:: Same as +advance-hoon, but takes a position and text directly. :: -++ tablist +++ advance-tape + |= [sut=type pos=@ud code=tape] + (advance-hoon sut (scan txt:(insert-magic pos code) vest)) +:: +:: Produce a list of matches. +:: +:: Takes a +hoon which has already has a magic-spoon marker. Useful if +:: you want to handle your own parsing. +:: +++ tab-list-hoon |= [sut=type gen=hoon] %+ bind (find-type-mule sut gen) |= [id=term typ=type] (search-prefix id (get-identifiers typ)) :: -++ tab-list - |= [sut=type code=cord] - %+ bind (find-type sut (scan (replace-hax (trip code)) vest)) - |= [id=term typ=type] - (search-prefix id (get-identifiers typ)) +:: Same as +advance-hoon, but takes a position and text directly. +:: +++ tab-list-tape + |= [sut=type pos=@ud code=tape] + (tab-list-hoon sut (scan txt:(insert-magic pos code) vest)) -- From 9487481128bb91ae59ede23ed7d786091f9bb1ea Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 15:14:41 -0700 Subject: [PATCH 05/13] dojo, drum: change %tab sole-effect to use tanks It should be general-purpose for tab-completing things in other apps, types are inappropriate. --- pkg/arvo/app/dojo.hoon | 7 +++++-- pkg/arvo/lib/hood/drum.hoon | 7 +++---- pkg/arvo/sur/sole.hoon | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index a5592ffe33..cf1a570470 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -3,7 +3,7 @@ :: :: :: /? 309 :: arvo kelvin /- *sole, lens :: -/+ sole, pprint, auto :: +/+ sole, pprint, auto, easy-print :: :: :: :: :::: :: :::: :: :: :: @@ -1131,7 +1131,10 @@ res :: Else, print results :: - (he-diff %tab u.tl) + %+ he-diff %tab + %+ turn u.tl + |= [=term =type] + [term ~(duck easy-print type)] :: ++ he-type :: apply input |= act/sole-action diff --git a/pkg/arvo/lib/hood/drum.hoon b/pkg/arvo/lib/hood/drum.hoon index 6c28bf8cf7..7487a35f11 100644 --- a/pkg/arvo/lib/hood/drum.hoon +++ b/pkg/arvo/lib/hood/drum.hoon @@ -3,7 +3,7 @@ :: :: :: /? 310 :: version /- *sole -/+ sole, easy-print +/+ sole :: :: :: :::: :: :: :: :: :: @@ -394,7 +394,7 @@ +>.$ :: ++ se-tab :: print tab completions - |= tl/(list {=term =type}) + |= tl/(list {=cord =tank}) ^+ +> =/ lots (gth (lent tl) 10) =/ long @@ -407,10 +407,9 @@ ^- (list tank) :- leaf+"-----" %+ turn tl - |= [=term =type] + |= [=term =type=tank] ?: lots leaf+(trip term) - =/ type-tank ~(duck easy-print type) =/ type-text ~(ram re type-tank) =/ spaces (trip (fil 3 (sub long (met 3 term)) ' ')) =/ =tape "{(trip term)} {spaces} {type-text}" diff --git a/pkg/arvo/sur/sole.hoon b/pkg/arvo/sur/sole.hoon index eef99d5eb2..6663d9f0bd 100644 --- a/pkg/arvo/sur/sole.hoon +++ b/pkg/arvo/sur/sole.hoon @@ -36,7 +36,7 @@ {$pro sole-prompt} :: set prompt {$sag p/path q/*} :: save to jamfile {$sav p/path q/@} :: save to file - {$tab p/(list {=term =type})} :: tab-complete list + {$tab p/(list {=cord =tank})} :: tab-complete list {$tan p/(list tank)} :: classic tank :: {$taq p/tanq} :: modern tank {$txt p/tape} :: text line From 8e66d84c8340fce18cf2c3004947937d23ef1b49 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 15:53:43 -0700 Subject: [PATCH 06/13] easy-print: don't crash if type-check crashes also don't render all the types if there's more than 10. --- pkg/arvo/app/dojo.hoon | 3 ++- pkg/arvo/lib/easy-print.hoon | 5 ++++- pkg/arvo/lib/hood/drum.hoon | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index cf1a570470..d4c19d7e6f 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -1131,10 +1131,11 @@ res :: Else, print results :: + =/ lots (gth (lent u.tl) 10) %+ he-diff %tab %+ turn u.tl |= [=term =type] - [term ~(duck easy-print type)] + [term ?:(lots *tank ~(duck easy-print type))] :: ++ he-type :: apply input |= act/sole-action diff --git a/pkg/arvo/lib/easy-print.hoon b/pkg/arvo/lib/easy-print.hoon index 5970e0373c..baa1035754 100644 --- a/pkg/arvo/lib/easy-print.hoon +++ b/pkg/arvo/lib/easy-print.hoon @@ -404,7 +404,10 @@ =- [p.tez (doge q.p.tez q.tez)] ^= tez ^- {p/{p/(map type @) q/(map @ wine)} q/wine} - ?: (~(meet ut sut) -:!>(*type)) + =/ type-meet (mule |.((~(meet ut sut) -:!>(*type)))) + ?: ?=(%| -.type-meet) + [dex %void] + ?: ?=(%& p.type-meet) [dex %type] ?- sut $noun [dex sut] diff --git a/pkg/arvo/lib/hood/drum.hoon b/pkg/arvo/lib/hood/drum.hoon index 7487a35f11..a121571c2d 100644 --- a/pkg/arvo/lib/hood/drum.hoon +++ b/pkg/arvo/lib/hood/drum.hoon @@ -401,7 +401,6 @@ ?: lots 0 (roll (turn tl |=([=term *] (met 3 term))) max) - %- se-dump %- flop ^- (list tank) From e4a89b072ce88b6d34621268052f87e9f995d68a Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 16:38:47 -0700 Subject: [PATCH 07/13] auto: don't look in context of non-gold cores --- pkg/arvo/lib/auto.hoon | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index 0fa75ef3ef..49a765c5dd 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -20,7 +20,9 @@ :: [%core *] %- weld - :_ $(ty p.ty) + :_ ?. ?=(%gold r.p.q.ty) + ~ + $(ty p.ty) ^- (list (pair term type)) %- zing %+ turn ~(tap by q.r.q.ty) From f3626e17e6a49dcb5165e94a50dabde364dc1474 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 20:54:00 -0700 Subject: [PATCH 08/13] auto: support multiline tab completion --- pkg/arvo/app/dojo.hoon | 9 ++++++--- pkg/arvo/lib/auto.hoon | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index d4c19d7e6f..b263c45a83 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -1100,7 +1100,9 @@ |= pos=@ud ^+ +> =* res +> - =+ [beg-pos=@ud txt=tape]=(insert-magic:auto pos (tufa buf.say)) + =+ ^- [beg-pos=@ud txt=tape] + (insert-magic:auto (add (lent buf) pos) :(weld buf (tufa buf.say))) + =/ pos-diff (sub (add (lent buf) pos) beg-pos) =+ vex=((full parse-command-line:he-parser) [1 1] txt) ?. ?=([* ~ [* @ %ex *] *] vex) res @@ -1108,7 +1110,8 @@ =/ tl (tab-list-hoon:auto typ p.q.q.p.u.q.vex) =/ advance (advance-hoon:auto typ p.q.q.p.u.q.vex) =? res ?=(^ advance) - =/ to-send (trip (rsh 3 (sub pos beg-pos) u.advance)) + =/ to-send + (trip (rsh 3 pos-diff u.advance)) =| fxs=(list sole-effect) |- ^+ res ?~ to-send @@ -1127,7 +1130,7 @@ :: If only one option, don't print unless the option is already :: typed in. :: - ?: &(?=([* ~] u.tl) !=((met 3 (need advance)) (sub pos beg-pos))) + ?: &(?=([* ~] u.tl) !=((met 3 (need advance)) pos-diff)) res :: Else, print results :: diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index 49a765c5dd..118564ad5f 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -211,7 +211,8 @@ :: begins :: =+ ^- [id=(unit term) *] - (scan `tape`(flop (scag pos txt)) ;~(plug (punt sym) (star prn))) + %+ scan `tape`(flop (scag pos txt)) + ;~(plug (punt sym) (star ;~(pose prn (just `@`10)))) =/ beg-pos ?~ id pos From 0014d1cf2b9a7b34a346801d91057fa50eccbab2 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 21:37:24 -0700 Subject: [PATCH 09/13] auto: fix some crashes on strange wet gates --- bin/solid.pill | 4 ++-- pkg/arvo/app/dojo.hoon | 10 +++++++++- pkg/arvo/lib/auto.hoon | 2 +- pkg/arvo/lib/easy-print.hoon | 10 +++++----- pkg/arvo/sys/hoon.hoon | 8 +++++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bin/solid.pill b/bin/solid.pill index 86c75573b0..2439245337 100644 --- a/bin/solid.pill +++ b/bin/solid.pill @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:58606e40eb62beb0c811e77529211913e3b66e4e824f8efdb55c92c27746fd49 -size 9082848 +oid sha256:11e608f3e5f0dd4860d19131c6c91550514f1e65a2229f9ee6ba0146e9ea7229 +size 9093157 diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index b263c45a83..0ce981bae4 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -1138,7 +1138,15 @@ %+ he-diff %tab %+ turn u.tl |= [=term =type] - [term ?:(lots *tank ~(duck easy-print type))] + ~| term + :- term + ?: lots + *tank + :: +perk is broken because *perk crashes. + :: + ?: =(%perk term) + *tank + ~(duck easy-print type) :: ++ he-type :: apply input |= act/sole-action diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index 118564ad5f..a394494d3e 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -1,4 +1,4 @@ -:: Autocompletion for hoon. +:: Autocomplete for hoon. :: |% +$ ids (list [=term =type]) diff --git a/pkg/arvo/lib/easy-print.hoon b/pkg/arvo/lib/easy-print.hoon index baa1035754..f4d6e94f11 100644 --- a/pkg/arvo/lib/easy-print.hoon +++ b/pkg/arvo/lib/easy-print.hoon @@ -77,7 +77,10 @@ [`u=- +]:$(q.ham i.p.r.q.ham, top-level |) :_ gid :+ %rose - :- " -> " + :- ?> ?=(%core -.q.q.ham) + ?: ?=(%dry q.p.q.q.q.ham) + " -> " + " ~> " ?: top-level ["" ""] ["(" ")"] @@ -404,10 +407,7 @@ =- [p.tez (doge q.p.tez q.tez)] ^= tez ^- {p/{p/(map type @) q/(map @ wine)} q/wine} - =/ type-meet (mule |.((~(meet ut sut) -:!>(*type)))) - ?: ?=(%| -.type-meet) - [dex %void] - ?: ?=(%& p.type-meet) + ?: (~(meet ut sut) -:!>(*type)) [dex %type] ?- sut $noun [dex sut] diff --git a/pkg/arvo/sys/hoon.hoon b/pkg/arvo/sys/hoon.hoon index afac856508..4b11fe2fbe 100644 --- a/pkg/arvo/sys/hoon.hoon +++ b/pkg/arvo/sys/hoon.hoon @@ -5178,7 +5178,7 @@ :: ++ pfix :: discard first rule ~/ %pfix - |* sam=* + |* sam={vex/edge sab/rule} %. sam (comp |*({a/* b/*} b)) :: @@ -5210,7 +5210,7 @@ :: ++ sfix :: discard second rule ~/ %sfix - |* sam=* + |* sam={vex/edge sab/rule} %. sam (comp |*({a/* b/*} a)) :: @@ -9915,10 +9915,12 @@ %+ turn hag.$ |= {p/type q/foot} - :- %hold ?. ?=({$core *} p) ~_ (dunk %fire-type) + ~_ leaf+"expected-fork-to-be-core" + ~_ (dunk(sut p) %fork-type) ~>(%mean.'fire-core' !!) + :- %hold =+ dox=[%core q.q.p q.p(r.p %gold)] ?: ?=($dry -.q) :: ~_ (dunk(sut [%cell q.q.p p.p]) %fire-dry) From 1fe453ee93f484eae27566dffe789961ab6def6a Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 22:43:50 -0700 Subject: [PATCH 10/13] auto: support autocomplete inside wings --- pkg/arvo/lib/auto.hoon | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index a394494d3e..0874f7e8ad 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -99,6 +99,15 @@ ?- gen [%cnts [%magic-spoon ~] *] `['' sut] [%cnts [%magic-spoon @ ~] *] `[i.t.p.gen sut] + [%cnts [%magic-spoon @ *] *] + %= $ + sut (~(play ut sut) wing+t.t.p.gen) + t.p.gen t.p.gen(t ~) + == + :: + [%cnts [%magic-fork @ ~] *] + `['' (~(play ut sut) wing+t.p.gen)] + :: [^ *] (both p.gen q.gen) [%ktcn *] loop(gen p.gen) [%brcn *] (grow q.gen) @@ -223,6 +232,8 @@ :: ;: weld (scag beg-pos txt) + ?: &(?=(~ id) ?=([%'.' *] (slag pos txt))) + "magic-fork" "magic-spoon" ?~ id "" From ad4f0c3ea3977f72ab2b69096a53ff10e25975e8 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Thu, 31 Oct 2019 23:21:10 -0700 Subject: [PATCH 11/13] auto: support forks --- pkg/arvo/lib/auto.hoon | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index 0874f7e8ad..5488e1f198 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -40,8 +40,16 @@ [p.ty q.ty]~ :: [%fork *] - ~| %find-fork - !! :: eh, fuse? + %= $ + ty + =/ tines ~(tap in p.ty) + ?~ tines + %void + |- ^- type + ?~ t.tines + i.tines + (~(fuse ut $(tines t.tines)) i.tines) + == :: [%hint *] $(ty q.ty) [%hold *] $(ty ~(repo ut ty)) From ce6efe0a6af0b6070e8a13ac3a48d84e04f3d656 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Fri, 1 Nov 2019 00:18:34 -0700 Subject: [PATCH 12/13] auto: handle tab in middle of symbol --- pkg/arvo/app/dojo.hoon | 19 +++++++++++++++---- pkg/arvo/lib/auto.hoon | 35 +++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/pkg/arvo/app/dojo.hoon b/pkg/arvo/app/dojo.hoon index 0ce981bae4..fc96738905 100644 --- a/pkg/arvo/app/dojo.hoon +++ b/pkg/arvo/app/dojo.hoon @@ -1100,9 +1100,10 @@ |= pos=@ud ^+ +> =* res +> - =+ ^- [beg-pos=@ud txt=tape] + =+ ^- [back-pos=@ud fore-pos=@ud txt=tape] (insert-magic:auto (add (lent buf) pos) :(weld buf (tufa buf.say))) - =/ pos-diff (sub (add (lent buf) pos) beg-pos) + =/ id-len (sub fore-pos back-pos) + =/ fore-pos-diff (sub fore-pos pos) =+ vex=((full parse-command-line:he-parser) [1 1] txt) ?. ?=([* ~ [* @ %ex *] *] vex) res @@ -1111,8 +1112,18 @@ =/ advance (advance-hoon:auto typ p.q.q.p.u.q.vex) =? res ?=(^ advance) =/ to-send - (trip (rsh 3 pos-diff u.advance)) + (trip (rsh 3 (sub pos back-pos) u.advance)) =| fxs=(list sole-effect) + =. . + |- ^+ +.$ + ?. (gth fore-pos-diff 0) + +.$ + =^ lic say (~(transmit sole say) %del pos) + %= $ + fxs [det+lic fxs] + fore-pos-diff (dec fore-pos-diff) + == + :: =. pos (add pos fore-pos-diff) |- ^+ res ?~ to-send (he-diff %mor (flop fxs)) @@ -1130,7 +1141,7 @@ :: If only one option, don't print unless the option is already :: typed in. :: - ?: &(?=([* ~] u.tl) !=((met 3 (need advance)) pos-diff)) + ?: &(?=([* ~] u.tl) !=((met 3 (need advance)) id-len)) res :: Else, print results :: diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index 5488e1f198..391d17906b 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -223,30 +223,45 @@ :: ++ insert-magic |= [pos=@ud txt=tape] - ^- [beg-pos=@ud txt=tape] + ^- [back-pos=@ud fore-pos=@ud txt=tape] :: Find beg-pos by searching backward to where the current term :: begins :: - =+ ^- [id=(unit term) *] - %+ scan `tape`(flop (scag pos txt)) - ;~(plug (punt sym) (star ;~(pose prn (just `@`10)))) - =/ beg-pos - ?~ id + =/ forward=(unit term) + %+ scan `tape`(slag pos txt) + ;~(sfix (punt sym) (star ;~(pose prn (just `@`10)))) + =/ backward=(unit term) + %+ scan `tape`(flop (scag pos txt)) + ;~(sfix (punt sym) (star ;~(pose prn (just `@`10)))) + =/ id=(unit term) + ?~ forward + ?~ backward + ~ + `u.backward + ?~ backward + `u.forward + `(cat 3 u.backward u.forward) + =/ back-pos + ?~ backward pos - (sub pos (met 3 u.id)) - :- beg-pos + (sub pos (met 3 u.backward)) + =/ fore-pos + ?~ forward + pos + (add pos (met 3 u.forward)) + :+ back-pos fore-pos :: Insert "magic-spoon" marker so +find-type can identify where to :: stop. :: ;: weld - (scag beg-pos txt) + (scag back-pos txt) ?: &(?=(~ id) ?=([%'.' *] (slag pos txt))) "magic-fork" "magic-spoon" ?~ id "" "." - (slag beg-pos txt) + (slag back-pos txt) "\0a" == :: From ec3ab084c7646fdbeb751dcfc9826548ff00fdd4 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Fri, 1 Nov 2019 18:02:20 -0700 Subject: [PATCH 13/13] auto: gain and lose types on ?: --- pkg/arvo/lib/auto.hoon | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/arvo/lib/auto.hoon b/pkg/arvo/lib/auto.hoon index 391d17906b..7db5f533db 100644 --- a/pkg/arvo/lib/auto.hoon +++ b/pkg/arvo/lib/auto.hoon @@ -182,7 +182,9 @@ :: ++ bell |= [a=hoon b=hoon c=hoon] - (replace loop(gen a) |.((replace loop(gen b) |.(loop(gen c))))) + %+ replace loop(gen a) + |. %+ replace loop(gen b, sut (~(gain ut sut) a)) + |. loop(gen c, sut (~(lose ut sut) a)) :: ++ spec-and-hoon |= [a=spec b=hoon]