@@ -6,8 +6,9 @@ local nvim = vim.api
66local log = require (" acid.log" )
77local utils = require (" acid.utils" )
88local connections = require (" acid.connections" )
9+ local output = require (" acid.output" )
910
10- local pending = {}
11+ local job_mapping = {}
1112local nrepl = {}
1213
1314local deps = {
@@ -104,6 +105,7 @@ nrepl.default_middlewares = {'nrepl/nrepl', 'cider/cider-nrepl', 'refactor-nrepl
104105-- @tparam [opt] string obj.connect -c parameter for the nrepl process
105106-- @tparam [opt] string obj.bind -b parameter for the nrepl process
106107-- @tparam [opt] boolean obj.skip_autocmd don't fire an autocmd after starting this repl
108+ -- @tparam [opt] boolean obj.disable_output_capture disables output capturing.
107109-- @treturn boolean Whether it was possible to spawn a nrepl process
108110nrepl .start = function (obj )
109111 local pwd = obj .pwd or vim .api .nvim_call_function (" getcwd" , {})
@@ -148,25 +150,23 @@ nrepl.start = function(obj)
148150 addr = conn
149151 }
150152
151- local ix = connections .add (conn )
153+ local conn_id = connections .add (conn )
152154
153- pending [ret ] = {pwd = pwd , ix = ix }
155+ nrepl .cache [pwd ].id = conn_id
156+
157+ job_mapping [ret ] = {pwd = pwd , conn = conn_id , init = false }
158+ if obj .disable_output_capture == false then
159+ output .buffer (conn_id )
160+ end
154161 return true
155162end
156163
157164--- Stops a nrepl process managed by acid
158165-- @tparam table obj Configuration for the nrepl process to be stopped
159166-- @tparam string obj.pwd Path where the nrepl process was started
160167nrepl .stop = function (obj )
161- local pwd = obj .pwd
162-
163- if not utils .ends_with (pwd , " /" ) then
164- pwd = pwd .. " /"
165- end
166-
167- nvim .nvim_call_function (" jobstop" , {nrepl .cache [pwd ].job })
168- connections .unselect (pwd )
169- connections .remove (pwd , nrepl .cache [pwd ].addr )
168+ nvim .nvim_call_function (" jobstop" , {nrepl .cache [obj .pwd ].job })
169+ connections .remove (nrepl .cache [obj .pwd ].id )
170170 nrepl .cache [obj .pwd ] = nil
171171end
172172
@@ -185,21 +185,25 @@ nrepl.handle = {
185185 _store = {},
186186 stdout = function (dt , ch )
187187 nrepl .handle ._store [ch ] = nrepl .handle ._store [ch ] or {}
188- if pending [ch ] ~= nil then
188+ local job = job_mapping [ch ]
189+
190+ if not job .init then
189191 for _ , ln in ipairs (dt ) do
190192 if string.sub (ln , 1 , 20 ) == " nREPL server started" then
191- local opts = pending [ch ]
192193 local port = ln :match (" %d+" )
193- connections .store [opts . ix ][2 ] = port
194- connections .select (opts .pwd , opts . ix )
195- pending [ch ] = nil
196- if not nrepl .cache [opts .pwd ].skip_autocmd then
194+ connections .store [job . conn ][2 ] = port
195+ connections .select (job .pwd , job . conn )
196+ job_mapping [ch ]. init = true
197+ if not nrepl .cache [job .pwd ].skip_autocmd then
197198 log .msg (" Connected on port" , tostring (port ))
198199 vim .api .nvim_command (" doautocmd User AcidConnected" )
199200 end
201+ break
200202 end
201203 end
202204 end
205+
206+ output .draw (job .conn , dt )
203207 table.insert (nrepl .handle ._store [ch ], dt )
204208 end ,
205209 stderr = function (dt , ch )
0 commit comments