Skip to content

Commit

Permalink
Merge pull request #51 from liquidz/dev
Browse files Browse the repository at this point in the history
ver 0.7.0
  • Loading branch information
liquidz authored Oct 23, 2018
2 parents 40a3458 + bb3c852 commit f80441c
Show file tree
Hide file tree
Showing 35 changed files with 628 additions and 569 deletions.
3 changes: 2 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

* Vim 8.1 or later, Neovim 0.3.1 or later
** Neovim support is *VERY EXPERIMENTAL*
* Clojure & Java
* Clojure 1.8 or later
** 1.9 is recommended
* No python! (boost possible with `if_python3`)

== Features
Expand Down
2 changes: 1 addition & 1 deletion autoload/iced.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endfunction

function! iced#eval_and_read(code, ...) abort
let msg = {
\ 'id': iced#nrepl#eval#id(),
\ 'id': iced#nrepl#id(),
\ 'op': 'eval',
\ 'code': a:code,
\ 'session': iced#nrepl#current_session(),
Expand Down
2 changes: 1 addition & 1 deletion autoload/iced/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function! iced#complete#omni(findstart, base) abort
endif

" namespace aliases
let alias_dict = iced#nrepl#ns#alias#dict(iced#nrepl#ns#get())
let alias_dict = iced#nrepl#ns#alias_dict(iced#nrepl#ns#get())
if !empty(alias_dict)
let candidates = candidates + s:ns_alias_candidates(keys(alias_dict), a:base)
endif
Expand Down
4 changes: 2 additions & 2 deletions autoload/iced/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let s:M = s:V.import('Vim.Message')
let s:last_warnings = []

let s:enabled = v:true
let g:iced#lint#linters = get(g:, 'iced#lint#linters', [])
let g:iced#eastwood#linters = get(g:, 'iced#eastwood#linters', [])

function! s:lint(warnings) abort
let s:last_warnings = a:warnings
Expand All @@ -24,7 +24,7 @@ function! iced#lint#current_file() abort
let s:last_warnings = []
call iced#sign#unplace_all()
let file = expand('%:p')
call iced#nrepl#op#iced#lint_file(file, g:iced#lint#linters, funcref('s:lint'))
call iced#nrepl#op#iced#lint_file(file, g:iced#eastwood#linters, funcref('s:lint'))
endfunction

function! iced#lint#echo_message() abort
Expand Down
124 changes: 60 additions & 64 deletions autoload/iced/nrepl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ let s:response_buffer = ''
let g:iced#nrepl#host = get(g:, 'iced#nrepl#host', '127.0.0.1')
let g:iced#nrepl#buffer_size = get(g:, 'iced#nrepl#buffer_size', 1048576)

let s:id_counter = 1
function! iced#nrepl#id() abort
let res = s:id_counter
let s:id_counter = (res < 100) ? res + 1 : 1
return res
endfunction

function! iced#nrepl#inject_channel(ch) abort
let s:ch = a:ch
endfunction

"" ---------
"" =SESSIONS
"" ---------

" SESSIONS {{{
function! iced#nrepl#set_session(k, v) abort
if a:k =~# '\(cljs\?\|repl\)'
let s:nrepl['sessions'][a:k] = a:v
Expand Down Expand Up @@ -81,11 +85,9 @@ function! iced#nrepl#check_session_validity() abort

return v:true
endfunction
" }}}

"" --------
"" =HANDLER
"" --------

" HANDLER {{{
function! s:get_message_id(x) abort
let x = a:x
if type(x) == type([])
Expand All @@ -98,21 +100,18 @@ function! s:get_message_id(x) abort
endif
endfunction

function! s:merge_response_handler(resp) abort
let id = s:get_message_id(a:resp)
let result = get(s:messages[id], 'result', {})

function! s:merge_response_handler(resp, last_result) abort
let result = empty(a:last_result) ? {} : a:last_result
for resp in iced#util#ensure_array(a:resp)
for k in keys(resp)
let result[k] = resp[k]
endfor
endfor

let s:messages[id]['result'] = result
return result
endfunction

function! s:default_handler(resp) abort
function! s:default_handler(resp, _) abort
return a:resp
endfunction

Expand All @@ -122,11 +121,9 @@ function! iced#nrepl#register_handler(op, handler) abort
endif
let s:handlers[a:op] = a:handler
endfunction
" }}}

"" -----------
"" =DISPATCHER
"" -----------

" DISPATCHER {{{
function! s:dispatcher(ch, resp) abort
let text = printf('%s%s', s:response_buffer, a:resp)
call iced#util#debug(text)
Expand Down Expand Up @@ -161,14 +158,15 @@ function! s:dispatcher(ch, resp) abort
endif

if has_key(s:messages, id)
let handler_result = ''
let last_handler_result = get(s:messages[id], 'handler_result', '')
let Handler = get(s:handlers, s:messages[id]['op'], funcref('s:default_handler'))
if iced#util#is_function(Handler)
let handler_result = Handler(resp)
let s:messages[id]['handler_result'] = Handler(resp, last_handler_result)
endif

if iced#util#has_status(resp, 'done')
let Callback = get(s:messages[id], 'callback')
let handler_result = get(s:messages[id], 'handler_result')
unlet s:messages[id]
call iced#nrepl#debug#quit()

Expand All @@ -183,11 +181,9 @@ function! s:dispatcher(ch, resp) abort
call iced#nrepl#debug#start(resp)
endif
endfunction
" }}}

"" -----
"" =SEND
"" -----

" SEND {{{
function! s:auto_connect() abort
call iced#message#echom('auto_connect')
if ! iced#nrepl#connect#auto()
Expand Down Expand Up @@ -232,10 +228,17 @@ function! iced#nrepl#send(data) abort
call s:ch.sendraw(s:nrepl['channel'], iced#nrepl#bencode#encode(data))
endfunction

"" --------
"" =CONNECT
"" --------
function! iced#nrepl#is_op_running(op) abort " {{{
for id in keys(s:messages)
if s:messages[id]['op'] ==# a:op
return v:true
endif
endfor
return v:false
endfunction " }}}
" }}}

" CONNECT {{{
function! s:warm_up() abort
" FIXME init-debugger does not return response immediately
call iced#nrepl#op#cider#debug#init()
Expand Down Expand Up @@ -299,11 +302,11 @@ function! iced#nrepl#connect(port) abort
return v:true
endfunction

function! iced#nrepl#is_connected() abort
function! iced#nrepl#is_connected() abort " {{{
return (s:status(s:nrepl['channel']) ==# 'open')
endfunction
endfunction " }}}

function! iced#nrepl#disconnect() abort
function! iced#nrepl#disconnect() abort " {{{
if !iced#nrepl#is_connected() | return | endif

for id in iced#nrepl#sync#session_list()
Expand All @@ -313,38 +316,19 @@ function! iced#nrepl#disconnect() abort
call s:ch.close(s:nrepl['channel'])
call s:initialize_nrepl()
call iced#cache#clear()
endfunction
endfunction " }}}

function! iced#nrepl#reconnect() abort
function! iced#nrepl#reconnect() abort " {{{
if !iced#nrepl#is_connected() | return | endif

let port = s:nrepl['port']
call iced#nrepl#disconnect()
sleep 500m
call iced#nrepl#connect(port)
endfunction

function! s:interrupted() abort
let s:messages = {}
call iced#message#info('interrupted')
endfunction

function! iced#nrepl#interrupt(...) abort
if ! iced#nrepl#is_connected() | return iced#message#warning('not_connected') | endif
let session = get(a:, 1, iced#nrepl#current_session())
" NOTE: ignore reading error
let s:response_buffer = ''
call iced#nrepl#send({
\ 'op': 'interrupt',
\ 'session': session,
\ 'callback': {_ -> s:interrupted()},
\ })
endfunction

"" -----
"" =EVAL
"" -----
endfunction " }}}
" }}}

" EVAL {{{
function! iced#nrepl#is_evaluating() abort
return !empty(s:messages)
endfunction
Expand All @@ -361,7 +345,7 @@ function! iced#nrepl#eval(code, ...) abort
let pos = getcurpos()

call iced#nrepl#send({
\ 'id': get(option, 'id', iced#nrepl#eval#id()),
\ 'id': get(option, 'id', iced#nrepl#id()),
\ 'op': 'eval',
\ 'code': a:code,
\ 'session': session,
Expand All @@ -372,33 +356,45 @@ function! iced#nrepl#eval(code, ...) abort
\ })
endfunction

function! iced#nrepl#load_file(callback) abort
function! iced#nrepl#load_file(callback) abort " {{{
if !iced#nrepl#is_connected() && !s:auto_connect()
return
endif

call iced#nrepl#send({
\ 'id': iced#nrepl#eval#id(),
\ 'id': iced#nrepl#id(),
\ 'op': 'load-file',
\ 'session': iced#nrepl#current_session(),
\ 'file': join(getline(1, '$'), "\n"),
\ 'file-name': expand('%'),
\ 'file-path': expand('%:p'),
\ 'callback': a:callback,
\ })
endfunction " }}}
" }}}

" INTERRUPT {{{
function! s:interrupted() abort
let s:messages = {}
call iced#message#info('interrupted')
endfunction

function! iced#nrepl#is_op_running(op) abort
for id in keys(s:messages)
if s:messages[id]['op'] ==# a:op
return v:true
endif
endfor
return v:false
function! iced#nrepl#interrupt(...) abort
if ! iced#nrepl#is_connected() | return iced#message#warning('not_connected') | endif
let session = get(a:, 1, iced#nrepl#current_session())
" NOTE: ignore reading error
let s:response_buffer = ''
call iced#nrepl#send({
\ 'op': 'interrupt',
\ 'session': session,
\ 'callback': {_ -> s:interrupted()},
\ })
endfunction
" }}}

call iced#nrepl#register_handler('eval', funcref('s:merge_response_handler'))
call iced#nrepl#register_handler('load-file', funcref('s:merge_response_handler'))

let &cpo = s:save_cpo
unlet s:save_cpo
" vim:fdm=marker:fdl=0
4 changes: 2 additions & 2 deletions autoload/iced/nrepl/cljs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function! iced#nrepl#cljs#switch_session(resp) abort
endif
endfunction

let g:iced#nrepl#cljs#default_env = get(g:, 'iced#nrepl#cljs#default_env', 'figwheel')
let g:iced#cljs#default_env = get(g:, 'iced#cljs#default_env', 'figwheel')
let s:using_env_key = ''

let s:env = {
Expand All @@ -40,7 +40,7 @@ let s:env = {
\ }

function! iced#nrepl#cljs#repl(env_key) abort
let env_key = iced#compat#trim(empty(a:env_key) ? g:iced#nrepl#cljs#default_env : a:env_key)
let env_key = iced#compat#trim(empty(a:env_key) ? g:iced#cljs#default_env : a:env_key)
if !has_key(s:env, env_key)
return iced#message#error('invalid_cljs_env')
endif
Expand Down
12 changes: 6 additions & 6 deletions autoload/iced/nrepl/cljs/custom.vim
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
let s:save_cpo = &cpo
set cpo&vim

let g:iced#nrepl#cljs#custom#start_code = get(g:, 'iced#nrepl#cljs#custom#start_code', '')
let g:iced#nrepl#cljs#custom#stop_code = get(g:, 'iced#nrepl#cljs#custom#stop_code', '')
let g:iced#cljs#custom#start_code = get(g:, 'iced#cljs#custom#start_code', '')
let g:iced#cljs#custom#stop_code = get(g:, 'iced#cljs#custom#stop_code', '')

function! s:custom_start() abort
if !empty(g:iced#nrepl#cljs#custom#start_code)
call iced#nrepl#eval#repl(g:iced#nrepl#cljs#custom#start_code)
if !empty(g:iced#cljs#custom#start_code)
call iced#nrepl#eval#repl(g:iced#cljs#custom#start_code)
endif
endfunction

function! s:custom_stop() abort
if !empty(g:iced#nrepl#cljs#custom#stop_code)
call iced#nrepl#eval#repl(g:iced#nrepl#cljs#custom#stop_code)
if !empty(g:iced#cljs#custom#stop_code)
call iced#nrepl#eval#repl(g:iced#cljs#custom#stop_code)
endif
endfunction

Expand Down
45 changes: 0 additions & 45 deletions autoload/iced/nrepl/definition.vim

This file was deleted.

2 changes: 1 addition & 1 deletion autoload/iced/nrepl/document.vim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function! s:expand_ns_alias(symbol) abort
return a:symbol
endif

let alias_dict = iced#nrepl#ns#alias#dict(iced#nrepl#ns#get())
let alias_dict = iced#nrepl#ns#alias_dict(iced#nrepl#ns#get())
let ns = a:symbol[0:i-1]
let ns = get(alias_dict, ns, ns)

Expand Down
Loading

0 comments on commit f80441c

Please sign in to comment.