Skip to content

Commit 8ae11e0

Browse files
committed
Add sessions
1 parent 81c0709 commit 8ae11e0

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

API.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ Dissociates the connection for the given path
2222
pwd **(string)**: path (usually project root).
2323

2424

25+
## `acid.connections.peek([pwd])`
26+
Return active connection for the given path
27+
28+
*pwd* **(string)**: path (usually project root).
29+
30+
31+
**({string,string})** Connection tuple with ip and port or nil.
32+
33+
2534
## `acid.connections.get(pwd)`
2635
Return active connection for the given path
2736

lua/acid/connections.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ connections.unselect = function(pwd)
6363
connections.current[pwd] = nil
6464
end
6565

66+
--- Return active connection for the given path
67+
-- @tparam[opt] string pwd path (usually project root).
68+
-- @treturn {string,string} Connection tuple with ip and port or nil.
69+
connections.peek = function(pwd)
70+
pwd = pwd_to_key(pwd or vim.api.nvim_call_function("getcwd", {}))
71+
return connections.current[pwd]
72+
end
73+
6674
--- Return active connection for the given path
6775
-- @tparam string pwd path (usually project root).
6876
-- @treturn {string,string} Connection tuple with ip and port or nil.

lua/acid/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
local core = require("acid.core")
77
local connections = require("acid.connections")
88
local utils = require("acid.utils")
9+
local sessions = require("acid.sessions")
910

1011
local acid = {}
1112

@@ -27,7 +28,8 @@ end
2728
-- @param cmd A command (op + payload + handler) to be executed.
2829
-- @param conn A connection where this command will be run.
2930
acid.run = function(cmd, conn)
30-
return core.send(conn, cmd:build())
31+
local filtered = cmd:update_payload(sessions.filter)
32+
return core.send(conn, filtered:build())
3133
end
3234

3335

plugin/acid.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ augroup acid
9090
autocmd!
9191
autocmd BufWritePost *.clj call s:require()
9292

93+
autocmd User AcidConnected lua require("acid.sessions").new_session()
9394
autocmd User AcidConnected lua require("acid.features").preload()
9495
autocmd User AcidConnected lua require("acid.features").load_all_nss()
9596

0 commit comments

Comments
 (0)