-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinit.lua
54 lines (41 loc) · 1.35 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- luacheck: globals vim
--- Frontend module with most relevant functions
-- @module acid
local core = require("acid.core")
local connections = require("acid.connections")
local utils = require("acid.utils")
local sessions = require("acid.sessions")
local acid = {}
--- Checks whether a connection exists for supplied path or not.
-- @tparam[opt] string pwd Path bound to connection.
-- Will call `getcwd` on neovim if not supplied
-- @treturn boolean Whether a connection exists or not.
acid.connected = function(pwd)
pwd = pwd or vim.api.nvim_call_function("getcwd", {})
if not utils.ends_with(pwd, "/") then
pwd = pwd .. "/"
end
return connections.current[pwd] ~= nil
end
--- Façade to core.send
-- @param cmd A command (op + payload + handler) to be executed.
-- @param conn A connection where this command will be run.
acid.run = function(cmd, conn)
local filtered = cmd:update_payload(sessions.filter)
return core.send(conn, filtered:build())
end
--- Callback proxy for handling command responses
-- @param ret The response from nrepl
acid.callback = function(ret)
local proxy = core.indirection[ret.id]
--if proxy == nil then
----TODO log
--end
local new_ret = proxy.fn(ret)
if type(new_ret) == "table" and new_ret.type == "command" then
core.send(proxy.conn, new_ret:build())
else
return new_ret
end
end
return acid