Skip to content

Commit 4f5f801

Browse files
committed
Add Unix Domain Socket support
1 parent 05861fe commit 4f5f801

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
com.sun.jmdk/jmxtools
1313
com.sun.jmx/jmxri]]
1414
[clj-logging-config "1.9.12"]
15-
[clojure-msgpack "1.2.0"]]
15+
[clojure-msgpack "1.2.0"]
16+
[uk.co.caprica/juds "0.94.1"]]
1617
:repl-options {:init-ns neovim-client.nvim}
1718
:target-path "target/%s")

src/neovim_client/nvim.clj

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
[clojure.tools.logging :as log]
55
[neovim-client.message :as message :refer [->request-msg]]
66
[neovim-client.rpc :as rpc])
7-
(:import (java.net Socket)))
7+
(:import (java.net Socket)
8+
(com.etsy.net UnixDomainSocketClient JUDS)))
89

910
(defmacro defvim
1011
[fn-name vim-command & args]
@@ -117,19 +118,24 @@
117118
(def stop rpc/stop)
118119

119120
(defn new*
120-
[input output debug]
121+
[input output update-nvim-channel?]
121122
(let [component (rpc/new input output)]
122-
;; Each time you connect to the same nvim instance using a tcp socket, nvim
123+
;; Each time you connect to the same nvim instance using a socket, nvim
123124
;; allocates a new channel.
124-
(when debug
125-
(let [api-info (vim-get-api-info component)]
126-
(vim-command component (format "let g:nvim_tcp_plugin_channel = %s"
127-
(first api-info)))))
125+
(when update-nvim-channel?
126+
(async/thread
127+
(let [api-info (vim-get-api-info component)]
128+
(vim-command component (format "let g:nvim_tcp_plugin_channel = %s"
129+
(first api-info))))))
128130
component))
129131

130132
(defn new
131-
"Connect to msgpack-rpc channel via standard io or TCP socket."
132-
([] (new* System/in System/out false))
133+
"Connect to msgpack-rpc channel via standard io, TCP socket, Unix domain
134+
sockets."
135+
([] (new* System/in System/out true))
136+
([uds-filepath]
137+
(let [socket (UnixDomainSocketClient. uds-filepath JUDS/SOCK_STREAM)]
138+
(new* (.getInputStream socket) (.getOutputStream socket) true)))
133139
([host port]
134140
(log/info "plugin host connecting to nvim at " host ":" port)
135141
(let [socket (java.net.Socket. host port)]

src/user.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[neovim-client.nvim :as nvim]
44
[clojure.tools.namespace.repl :refer [refresh]]))
55

6-
(defn connection
6+
(defn tcp-connection
77
"Get an nvim connection."
88
[]
99
(nvim/new "localhost" 7777))

0 commit comments

Comments
 (0)