From 6df7ec8c33d1b15f4d809aa4b7875c25dfaf8b41 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Wed, 20 Apr 2022 23:21:41 -0400 Subject: [PATCH] more editor shit, use repls for things, show docs in autocomplete --- editor/init.fnl | 11 +++++++---- editor/replsession.fnl | 7 +++++++ inspector/debug.fnl | 9 +++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/editor/init.fnl b/editor/init.fnl index 2f5d5b9..317bdd6 100644 --- a/editor/init.fnl +++ b/editor/init.fnl @@ -83,9 +83,12 @@ (fn replace-selected-symbol [text] (: (place-to-symbol (get-selection)) :replace-text text)) (fn autocomplete-results [text] - (var result []) - (: (replsession.session) :submit (.. ",complete " text) #(set result (or $1.vals [])) true) - result) + (var symbols []) + (: (replsession.session) :submit (.. ",complete " text) #(set symbols (or $1.vals [])) true) + (icollect [_ symbol (ipairs symbols)] + (let [item {:text symbol}] + (: (replsession.session) :submit (.. ",doc " symbol) #(when $1.vals (set item.info (. $1.vals 1)))) + item))) (fn autocomplete-symbol [callback ?starting-text] (fn fixup-result [text item] (callback (or (and item item.text) text))) @@ -96,7 +99,7 @@ (core.command_view:update_suggestions))) (command.add :core.docview { - "fennel:eval" #(submit nil (selected-form)) + "fennel:eval" #(submit (selected-form)) "fennel:go-to-definition-under-cursor" #(go-to-definition (selected-symbol)) "fennel:go-to-definition" #(autocomplete-symbol #(go-to-definition $1) (selected-symbol)) "fennel:autocomplete" #(autocomplete-symbol #(replace-selected-symbol $1) (selected-symbol)) diff --git a/editor/replsession.fnl b/editor/replsession.fnl index b0f3733..1ec8665 100644 --- a/editor/replsession.fnl +++ b/editor/replsession.fnl @@ -21,6 +21,13 @@ (fn replsession.new-session [] (replsession.restart-session {:submit replsession.submit})) +(fn replsession.current-session-id [] + (var session-id nil) + (let [coro (coroutine.running)] + (each [id session (pairs replsession.sessions)] + (when (= session.coro coro) (set session-id id))) + session-id)) + (fn replsession.submit [session chunk callback ?suppress-crash] (assert (= session.callback nil)) (set session.callback callback) diff --git a/inspector/debug.fnl b/inspector/debug.fnl index a8a0a66..c31351f 100644 --- a/inspector/debug.fnl +++ b/inspector/debug.fnl @@ -21,15 +21,16 @@ (set view.inspector-name name) (set view.title name) (view:append {:draw (fn [_ _ x y] (renderer.draw_text style.font name x y style.text) (+ (style.font:get_height) style.padding.y))}) - (view:append (repl.mk-result [?value])) - (node:add_view view) + (when ?value + (view:append (repl.mk-result [?value]))) + (node:split :right view) view)) -(lambda module.show [?name ?value] +(lambda module.show [?value ?name] (let [name (replsession.session-id ?name)] (or (find-existing-inspector-window name) (create-inspector-window name ?value)))) -(lambda module.submit [?name chunk] +(lambda module.submit [chunk ?name] (: (module.show ?name) :submit chunk)) module.hot