Skip to content

Commit 163fe98

Browse files
committed
Prototype unit tests
1 parent 327b4b9 commit 163fe98

File tree

3 files changed

+78
-16
lines changed

3 files changed

+78
-16
lines changed

TODO

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
1-
global-state
2-
[X] finish refactoring nvim, rpc
3-
[X] from debug session, stop, then start (restart) should work
4-
[X] make sure sample plugins still work
5-
[_] clojure socket repl plugin refactor
1+
Versioning
2+
re: https://github.com/neovim/neovim/pull/5535
3+
re: https://github.com/neovim/neovim/pull/5386
4+
5+
[_] an we start writing tests for these things?
6+
[X] We'd have to start an nvim --embed, and maybe specify the NVIM_... ?
7+
[X] Then, we connect
8+
[X] Test version validation
9+
[_] Integration test
10+
-insert some text in current buffer
11+
-command split the a new buffer put some stuff in it
12+
-command switch back to the original buffer
13+
-get the text of current buffer
14+
15+
Tough to figure out exactly how to test against multiple version of
16+
Neovim's API. For now, let's just do this basic test, and document
17+
the version of Neovim used.
18+
19+
Following the philosophy described above, we need
20+
[_] Make the user specify required API level on `connect`
21+
22+
[_] Change the api to one function `exec`, pass the op as the first
23+
arg, and then use varargs, or a collection of args.
24+
Implementing `exec` and `exec-async` should include
25+
version-supported? check, maybe assume nvim_command will always
26+
be supported.
27+
28+
[_] On `connect`, intern dynamically created functions similar to the
29+
macros we use now.
30+
31+
[_] Change the existing samples to use this, maybe only support one
32+
sample.
33+
34+
[_] Make a `doc` function that basically does `ns-publics`
35+
36+
[_] Update the docs, including video?
37+
In terms of the docs, we'll take a similar approach that other
38+
AWS client libs have taken, we'll steer them heavily toward
39+
the *actual* docs, and using `nvim-get-api-info`.
40+
41+
[_] Tag the existing version, bump the version (project & github),
42+
and release.
43+
44+
Why aren't we doing anything statically?
45+
Although I'd prefer actual functions in source code, I don't like
46+
That I'd have to change code when they version the API
47+
But, more importantly, since the api_level supports a range of
48+
levels, I'd either
49+
have to support side-by-side versions
50+
but that would be easy with codegen & ns2, ns3, etc.
51+
make patches to all versions, if version by api-level

src/neovim_client/nvim.clj

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
(:import (java.net Socket)
88
(com.etsy.net UnixDomainSocketClient JUDS)))
99

10+
(declare exec)
11+
(declare exec-async)
12+
1013
(defmacro defvim
1114
[fn-name vim-command & args]
1215
`(do
@@ -117,27 +120,38 @@
117120
(def register-method! rpc/register-method!)
118121
(def stop rpc/stop)
119122

123+
(defn version-supported?
124+
[component]
125+
(let [desired-version (:version component)
126+
[channel api-info] @(:api-info component)
127+
{:strs [version]} api-info
128+
{:strs [api_prerelease api_level api_compatible]} version
129+
min-version api_compatible
130+
max-version (if api_prerelease (dec api_level) api_level)]
131+
(<= min-version desired-version max-version)))
132+
120133
(defn new*
121-
[input output update-nvim-channel?]
134+
[version input output update-nvim-channel?]
122135
(let [component (rpc/new input output)]
123136
;; Each time you connect to the same nvim instance using a socket, nvim
124137
;; allocates a new channel.
125-
(when update-nvim-channel?
126-
(async/thread
127-
(let [api-info (vim-get-api-info component)]
138+
(async/thread
139+
(let [api-info (vim-get-api-info component)]
140+
(deliver (:api-info component) api-info)
141+
(when update-nvim-channel?
128142
(vim-command component (format "let g:nvim_tcp_plugin_channel = %s"
129143
(first api-info))))))
130-
component))
144+
(assoc component :version version)))
131145

132146
(defn new
133147
"Connect to msgpack-rpc channel via standard io, TCP socket, Unix domain
134148
sockets."
135-
([] (new* System/in System/out true))
136-
([uds-filepath]
149+
([version] (new* version System/in System/out true))
150+
([version uds-filepath]
137151
(let [socket (UnixDomainSocketClient. uds-filepath JUDS/SOCK_STREAM)]
138-
(new* (.getInputStream socket) (.getOutputStream socket) true)))
139-
([host port]
152+
(new* version (.getInputStream socket) (.getOutputStream socket) true)))
153+
([version host port]
140154
(log/info "plugin host connecting to nvim at " host ":" port)
141155
(let [socket (java.net.Socket. host port)]
142156
(.setTcpNoDelay socket true)
143-
(new* (.getInputStream socket) (.getOutputStream socket) true))))
157+
(new* version (.getInputStream socket) (.getOutputStream socket) true))))

src/neovim_client/rpc.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
input-stream (DataInputStream. input-stream)
8383
message-table (atom {})
8484
method-table (atom {})
85-
component {:input-stream input-stream
85+
component {:version nil
86+
:api-info (promise)
87+
:input-stream input-stream
8688
:output-stream output-stream
8789
:out-chan (create-output-channel output-stream)
8890
:in-chan in-chan

0 commit comments

Comments
 (0)