Skip to content

Commit 6faf14a

Browse files
committed
Separate prod & dev config
1 parent 4ebbd5e commit 6faf14a

File tree

10 files changed

+122
-43
lines changed

10 files changed

+122
-43
lines changed

project.clj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:dependencies [[org.clojure/clojure "1.9.0-alpha12"]
7-
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
8-
;; TODO: upgrade to this
9-
;; [org.clojure/core.async "0.2.391"]
7+
[org.clojure/core.async "0.2.391"]
108
[org.clojure/tools.logging "0.3.1"]
119
[clj-logging-config "1.9.12"]
1210
[clojure-msgpack "1.0.0"]]
1311
:repl-options {:init-ns neovim-client.nvim}
14-
;; TODO: remove this
15-
;;:jvm-opts ["-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl}"]
1612
:main ^:skip-aot neovim-client.socket-repl-plugin
1713
:target-path "target/%s"
1814
:profiles {:uberjar {:aot :all}})

socket-repl-plugin/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/jeb/source/neovim-client/socket-repl-plugin/test:/home/jeb/source/neovim-client/socket-repl-plugin/src:/home/jeb/source/neovim-client/socket-repl-plugin/dev-resources:/home/jeb/source/neovim-client/socket-repl-plugin/resources:/home/jeb/source/neovim-client/socket-repl-plugin/target/base+system+user+dev/classes:/home/jeb/source/neovim-client/socket-repl-plugin/checkouts/neovim-client/src:/home/jeb/source/neovim-client/socket-repl-plugin/checkouts/neovim-client/test:/home/jeb/source/neovim-client/socket-repl-plugin/checkouts/neovim-client/dev-resources:/home/jeb/source/neovim-client/socket-repl-plugin/checkouts/neovim-client/resources:/home/jeb/source/neovim-client/socket-repl-plugin/checkouts/neovim-client/target/base+system+user+dev/classes:/home/jeb/.m2/repository/clojure-complete/clojure-complete/0.2.3/clojure-complete-0.2.3.jar:/home/jeb/.m2/repository/org/clojure-grimoire/lib-grimoire/0.6.4/lib-grimoire-0.6.4.jar:/home/jeb/.m2/repository/org/tcrawley/dynapath/0.2.3/dynapath-0.2.3.jar:/home/jeb/.m2/repository/org/clojure/clojure/1.9.0-alpha12/clojure-1.9.0-alpha12.jar:/home/jeb/.m2/repository/ring/ring-codec/1.0.0/ring-codec-1.0.0.jar:/home/jeb/.m2/repository/org/clojure/tools.analyzer.jvm/0.6.10/tools.analyzer.jvm-0.6.10.jar:/home/jeb/.m2/repository/grimvim/grimvim/0.1.0/grimvim-0.1.0.jar:/home/jeb/.m2/repository/org/clojure/tools.analyzer/0.6.9/tools.analyzer-0.6.9.jar:/home/jeb/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar:/home/jeb/.m2/repository/org/clojure/core.async/0.2.391/core.async-0.2.391.jar:/home/jeb/.m2/repository/com/taoensso/encore/1.8.1/encore-1.8.1.jar:/home/jeb/.m2/repository/clojure-msgpack/clojure-msgpack/1.0.0/clojure-msgpack-1.0.0.jar:/home/jeb/.m2/repository/io/aviso/pretty/0.1.12/pretty-0.1.12.jar:/home/jeb/.m2/repository/org/clojure/core.memoize/0.5.9/core.memoize-0.5.9.jar:/home/jeb/.m2/repository/clj-logging-config/clj-logging-config/1.9.12/clj-logging-config-1.9.12.jar:/home/jeb/.m2/repository/org/clojure/tools.namespace/0.2.7/tools.namespace-0.2.7.jar:/home/jeb/.m2/repository/org/clojure/tools.logging/0.3.1/tools.logging-0.3.1.jar:/home/jeb/.m2/repository/com/taoensso/timbre/3.3.1/timbre-3.3.1.jar:/home/jeb/.m2/repository/commons-codec/commons-codec/1.6/commons-codec-1.6.jar:/home/jeb/.m2/repository/org/ow2/asm/asm-all/4.2/asm-all-4.2.jar:/home/jeb/.m2/repository/version-clj/version-clj/0.1.0/version-clj-0.1.0.jar:/home/jeb/.m2/repository/org/clojure/data.priority-map/0.0.7/data.priority-map-0.0.7.jar:/home/jeb/.m2/repository/ring-mock/ring-mock/0.1.5/ring-mock-0.1.5.jar:/home/jeb/.m2/repository/neovim-client/neovim-client/0.1.0-SNAPSHOT/neovim-client-0.1.0-SNAPSHOT.jar:/home/jeb/.m2/repository/org/clojure/tools.nrepl/0.2.10/tools.nrepl-0.2.10.jar:/home/jeb/.m2/repository/org/clojure/core.cache/0.6.5/core.cache-0.6.5.jar:/home/jeb/.m2/repository/org/clojure/tools.reader/0.8.8/tools.reader-0.8.8.jar:/home/jeb/.m2/repository/cider/cider-nrepl/0.10.0-SNAPSHOT/cider-nrepl-0.10.0-SNAPSHOT.jar

socket-repl-plugin/TODO

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ TODO alpha
1010
show the contents of the temp file in the current buffer
1111
make it autoread
1212
[X] Name vim functions correctly
13-
[_] create prod & debug plugin.vim
14-
both should start the plugin the same way, w/
15-
a bash script that specifies JVM options
16-
eliminate lein
17-
don't use a jar yet, just java -cp clojure.jar <clj-file> if possible
18-
[_] add debug switch (var) to socket-repl-plugin.clj
13+
[X] create prod & debug plugin.vim
14+
[X] add debug switch (var) to socket-repl-plugin.clj
1915
[_] implement doc (word under cursor)
2016
[_] Pass host, port in connect
17+
[_] Update README
18+
Move NVIM_LISTEN... stuff to a debug section
2119

2220
TODO final
2321
[_] Rather than explicit repl output logging, can we intercept
@@ -47,21 +45,28 @@ Goals
4745
Accessible from vim buffer `:call ShowClojurePluginRepl()`
4846
-Not a way of life
4947
Does not include paredit, syntax highlight, etc
48+
-Architecture Diagram
49+
nvim <--msgpack/stdio--> plugin (jar) <--localhost:5555--> socket repl
5050

5151
Questions
5252
Figwheel cljs-repl support
5353

5454
Usage/Installation
55-
if we ship jar, should be no install steps
55+
no other install outside of normal plugin (pathogen, vundle, etc)
56+
** except the rtp thing **
5657
add command line args to your project, so it starts socket repl
57-
on :Connect specify port (and host) to connect to
58+
-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"
59+
on `:Connect` specify port (and host) to connect to
60+
split a pane, `:ReplLog`
5861

5962
Debugging notes
6063
vim
61-
rpcrequest(1, ...) <-- use channel 1, w/ tcp
62-
don't do rpcstart
64+
start vim w/ NVIM_LISTEN_ADDRESS
65+
`:so` plugin/socket-repl.vim.debug script
6366
clj
64-
connect! add localhost 7777
65-
vim blocks if you make a synchronous call to clj which makes a sync
66-
call back to vim -- use async!
67+
start plugin w/ `run.sh`
68+
this also starts a socket repl on 5555
69+
note: use async!
70+
: vim blocks if you make a synchronous call to clj which makes a sync
71+
: call back to vim -- use async!
6772

socket-repl-plugin/deploy-local.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lein uberjar
2+
cp target/uberjar/socket-repl-plugin-0.1.0-SNAPSHOT-standalone.jar .
3+
rm -rf ~/.vim/bundle/neovim-client
4+
cd ../..
5+
cp -rf neovim-client ~/.vim/bundle

socket-repl-plugin/plugin/socketrepl.vim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,38 @@ function! StartIfNotRunning()
88
"TODO - This is a dirty hack. We should launch things without changing
99
"the working directory.
1010
exec ':cd ' . s:p_dir
11-
let g:channel = rpcstart('lein', ['run'])
11+
exec ':cd ..'
12+
let g:channel = rpcstart('java', ['-jar', 'socket-repl-plugin-0.1.0-SNAPSHOT-standalone.jar'])
1213
let g:is_running = 1
1314
endif
1415
endfunction
1516

1617
function! Connect()
17-
"call StartIfNotRunning()
18-
let res = rpcrequest(1, 'connect', [])
18+
call StartIfNotRunning()
19+
let res = rpcrequest(g:channel, 'connect', [])
1920
return res
2021
endfunction
2122
command! Connect call Connect()
2223

2324
function! EvalBuffer()
24-
"call StartIfNotRunning()
25-
let res = rpcrequest(1, 'eval-buffer', [])
25+
call StartIfNotRunning()
26+
let res = rpcrequest(g:channel, 'eval-buffer', [])
2627
return res
2728
endfunction
2829
command! EvalBuffer call EvalBuffer()
2930

3031
function! EvalCode()
31-
"call StartIfNotRunning()
32-
"let res = rpcrequest(g:channel, 'eval-code', [])
33-
let res = rpcrequest(1, 'eval-code', [])
32+
call StartIfNotRunning()
33+
let res = rpcrequest(g:channel, 'eval-code', [])
3434
return res
3535
endfunction
3636
command! EvalCode call EvalCode()
3737

3838
function! ReplLog()
39-
"call StartIfNotRunning()
40-
let res = rpcrequest(1, 'show-log', [])
39+
call StartIfNotRunning()
40+
let res = rpcrequest(g:channel, 'show-log', [])
4141
return res
4242
endfunction
4343
command! ReplLog call ReplLog()
4444

45-
echo 'socket repl plugin loaded!'
45+
echo 'prod socket repl plugin loaded!'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
let g:is_running = 0
2+
let g:channel = -1
3+
4+
function! Connect()
5+
let res = rpcrequest(1, 'connect', [])
6+
return res
7+
endfunction
8+
command! Connect call Connect()
9+
10+
function! EvalBuffer()
11+
let res = rpcrequest(1, 'eval-buffer', [])
12+
return res
13+
endfunction
14+
command! EvalBuffer call EvalBuffer()
15+
16+
function! EvalCode()
17+
let res = rpcrequest(1, 'eval-code', [])
18+
return res
19+
endfunction
20+
command! EvalCode call EvalCode()
21+
22+
function! ReplLog()
23+
let res = rpcrequest(1, 'show-log', [])
24+
return res
25+
endfunction
26+
command! ReplLog call ReplLog()
27+
28+
echo 'debug socket repl plugin loaded!'

socket-repl-plugin/run.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Development run script.
2+
3+
if [[ ! -e project.clj ]]; then
4+
echo "This script must be run from the top-level"
5+
exit 1
6+
fi
7+
8+
# Generate .classpath from Leiningen if project.clj has changed.
9+
if [[ project.clj -nt .classpath ]]; then
10+
lein classpath > .classpath
11+
fi
12+
13+
# Use server-daemon false, so socket repl server thread will block exit.
14+
exec java \
15+
-cp "$(cat .classpath)" \
16+
-Djava.awt.headless=true \
17+
-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl :server-daemon false}" \
18+
-XX:-OmitStackTraceInFastThrow \
19+
clojure.main \
20+
./src/socket_repl/socket_repl_plugin.clj --debug true
Binary file not shown.

socket-repl-plugin/src/socket_repl/socket_repl_plugin.clj

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[neovim-client.nvim :as nvim])
99
(:import
1010
(java.net Socket)
11-
(java.io PrintStream File)))
11+
(java.io PrintStream File))
12+
(:gen-class))
1213

1314
(def current-connection (atom nil))
1415

@@ -70,6 +71,11 @@
7071
[string]
7172
(write-output @current-connection string))
7273

74+
(defn update-last!
75+
"Update the last accessed time."
76+
[]
77+
(swap! current-connection assoc :last (System/currentTimeMillis)))
78+
7379
(defn connect!
7480
"Connect to a socket repl. Adds the connection to the `current-connection`
7581
atom. Creates `go-loop`s to delegate input from the socket to `handler` one
@@ -85,7 +91,8 @@
8591
:handler handler
8692
:chan chan
8793
:file file
88-
:file-stream (PrintStream. file)))
94+
:file-stream (PrintStream. file)
95+
:last (System/currentTimeMillis)))
8996

9097
;; input producer
9198
(go-loop []
@@ -100,14 +107,16 @@
100107
(recur))))
101108
"success")
102109

103-
(defn -main
104-
[& args]
105-
;; TODO: remove params for STDIO
106-
(nvim/connect! "localhost" 7777)
110+
(defn start
111+
[debug]
112+
(if debug
113+
(nvim/connect! "localhost" 7777)
114+
(nvim/connect!))
107115

108116
(nvim/register-method!
109117
"connect"
110118
(fn [msg]
119+
(update-last!)
111120
;; TODO: Get host/port from message
112121
(connect! "localhost" "5555"
113122
(fn [x]
@@ -118,6 +127,7 @@
118127
(nvim/register-method!
119128
"eval-code"
120129
(fn [msg]
130+
(update-last!)
121131
(nvim/get-cursor-location-async
122132
(fn [coords]
123133
(nvim/get-current-buffer-text-async
@@ -137,6 +147,7 @@
137147
(nvim/register-method!
138148
"eval-buffer"
139149
(fn [msg]
150+
(update-last!)
140151
(nvim/get-current-buffer-text-async
141152
(fn [x]
142153
(write-output! (str x "\n"))
@@ -145,7 +156,7 @@
145156
(nvim/register-method!
146157
"show-log"
147158
(fn [msg]
148-
159+
(update-last!)
149160
(nvim/run-command-async!
150161
(format ":term tail -f %s" (-> @current-connection
151162
:file
@@ -162,14 +173,19 @@
162173
":set updatetime=500 | au CursorHold <buffer> :e!"
163174
(fn [_] nil))))))
164175

165-
;; TODO: Rather than an arbitrary timeout, the plugin should shut down
166-
;; when it has received no input for some time.
167-
(comment
168-
(dotimes [n 60]
169-
(if (= 0 (mod n 10))
170-
(nvim/run-command! (str ":echo 'plugin alive for " n " seconds.'")))
171-
(Thread/sleep 1000))
176+
;; Don't need to do this in debug, socket repl will keep this alive.
177+
(when-not debug
178+
(loop []
179+
(Thread/sleep 30000)
180+
(let [elapsed-msec (- (System/currentTimeMillis)
181+
(:last @current-connection))]
182+
(when (< elapsed-msec 60000)
183+
(recur))))
172184

173185
;; Let nvim know we're shutting down.
174186
(nvim/run-command! ":let g:is_running=0")
175187
(nvim/run-command! ":echo 'plugin stopping.'")))
188+
189+
(defn -main
190+
[& args]
191+
(start false))

socket-repl-plugin/src/user.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(ns user
2+
(:require
3+
[socket-repl.socket-repl-plugin :as plugin]))
4+
5+
(defn go
6+
"Start the plugin."
7+
[]
8+
(plugin/start true))

0 commit comments

Comments
 (0)