Skip to content

Commit

Permalink
Merge pull request #34 from liquidz/dev
Browse files Browse the repository at this point in the history
ver 0.4.1
  • Loading branch information
liquidz authored Sep 27, 2018
2 parents b68c98f + 5ade198 commit c1cd92f
Show file tree
Hide file tree
Showing 36 changed files with 367 additions and 372 deletions.
8 changes: 3 additions & 5 deletions autoload/iced/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function! s:ns_var_candidates(ns_name, base, alias) abort
return result
endif

let resp = iced#nrepl#cider#sync#ns_vars(a:ns_name)
let resp = iced#nrepl#op#cider#sync#ns_vars(a:ns_name)
if empty(resp) || resp['status'][0] !=# 'done'
return []
endif
Expand Down Expand Up @@ -127,9 +127,7 @@ function! iced#complete#omni(findstart, base) abort
endif

" namespace aliases
let alias_dict = (iced#nrepl#current_session_key() ==# 'clj')
\ ? iced#nrepl#ns#alias#dict(ns)
\ : iced#nrepl#ns#alias#dict_from_code(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 All @@ -148,7 +146,7 @@ function! iced#complete#omni(findstart, base) abort

" cider completions
let ctx = s:context()
let resp = iced#nrepl#cider#sync#complete(a:base, ns, ctx)
let resp = iced#nrepl#op#cider#sync#complete(a:base, ns, ctx)
if type(resp) == type({}) && has_key(resp, 'completions')
let candidates = candidates + resp['completions']
endif
Expand Down
4 changes: 2 additions & 2 deletions autoload/iced/format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function! iced#format#form() abort
if empty(code)
call iced#message#warning('finding_code_error')
else
let resp = iced#nrepl#iced#sync#format_code(code, g:iced#format#rule)
let resp = iced#nrepl#op#iced#sync#format_code(code, g:iced#format#rule)
if has_key(resp, 'formatted') && !empty(resp['formatted'])
let @@ = resp['formatted']
silent normal! gvp
Expand Down Expand Up @@ -61,7 +61,7 @@ function! iced#format#minimal() abort
endif
let code = @@

let resp = iced#nrepl#iced#sync#format_code(code, g:iced#format#rule)
let resp = iced#nrepl#op#iced#sync#format_code(code, g:iced#format#rule)
if has_key(resp, 'formatted') && !empty(resp['formatted'])
let @@ = s:add_indent(ncol, resp['formatted'])
silent normal! gvp
Expand Down
4 changes: 2 additions & 2 deletions autoload/iced/grimoire.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ function! s:search(resp) abort
let symbol = a:resp['name']

echom printf('Connecting to grimoire ...')
call iced#nrepl#iced#grimoire(platform, ns_name, symbol, funcref('s:grimoire'))
call iced#nrepl#op#iced#grimoire(platform, ns_name, symbol, funcref('s:grimoire'))
else
echom printf('Invalid response from Grimoire.')
endif
endfunction

function! iced#grimoire#open(symbol) abort
let symbol = empty(a:symbol) ? expand('<cword>') : a:symbol
call iced#nrepl#cider#info(symbol, funcref('s:search'))
call iced#nrepl#op#cider#info(symbol, funcref('s:search'))
endfunction

let &cpo = s:save_cpo
Expand Down
5 changes: 3 additions & 2 deletions autoload/iced/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ let s:enabled = v:true
let g:iced#lint#linters = get(g:, 'iced#lint#linters', [])

function! s:lint(warnings) abort
call iced#sign#unplace_all()
let s:last_warnings = a:warnings
for warn in s:last_warnings
if !has_key(warn, 'line') || !has_key(warn, 'path') | continue | endif
Expand All @@ -22,8 +21,10 @@ function! iced#lint#current_file() abort
return
endif

let s:last_warnings = []
call iced#sign#unplace_all()
let file = expand('%:p')
call iced#nrepl#iced#lint_file(file, g:iced#lint#linters, funcref('s:lint'))
call iced#nrepl#op#iced#lint_file(file, g:iced#lint#linters, funcref('s:lint'))
endfunction

function! iced#lint#echo_message() abort
Expand Down
4 changes: 2 additions & 2 deletions autoload/iced/nrepl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ endfunction

function! s:warm_up() abort
" FIXME init-debugger does not return response immediately
call iced#nrepl#cider#debug#init()
call iced#nrepl#op#cider#debug#init()
sleep 100m
call iced#nrepl#cider#debug#init()
call iced#nrepl#op#cider#debug#init()
endfunction

function! s:status(ch) abort
Expand Down
2 changes: 1 addition & 1 deletion autoload/iced/nrepl/debug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function! iced#nrepl#debug#start(resp) abort
if type(input_type) == type({})
let in = ':'.get(input_type, in, 'quit')
endif
call iced#nrepl#cider#debug#input(resp['key'], in)
call iced#nrepl#op#cider#debug#input(resp['key'], in)
endfunction

function! iced#nrepl#debug#quit() abort
Expand Down
6 changes: 3 additions & 3 deletions autoload/iced/nrepl/document.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function! s:expand_ns_alias(symbol) abort
return a:symbol
endif

let alias_dict = iced#nrepl#ns#alias#dict_from_code(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 All @@ -110,7 +110,7 @@ function! iced#nrepl#document#open(symbol) abort
let symbol = s:expand_ns_alias(symbol)
endif

call iced#nrepl#cider#info(symbol, funcref('s:view_doc'))
call iced#nrepl#op#cider#info(symbol, funcref('s:view_doc'))
endfunction

function! s:one_line_doc(resp) abort
Expand Down Expand Up @@ -152,7 +152,7 @@ function! iced#nrepl#document#current_form() abort
if iced#nrepl#current_session_key() ==# 'cljs'
let symbol = s:expand_ns_alias(symbol)
endif
call iced#nrepl#cider#info(symbol, funcref('s:one_line_doc'))
call iced#nrepl#op#cider#info(symbol, funcref('s:one_line_doc'))
endif
endif
finally
Expand Down
4 changes: 2 additions & 2 deletions autoload/iced/nrepl/eval.vim
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function! iced#nrepl#eval#undef(symbol) abort
if !iced#nrepl#is_connected() | return iced#message#error('not_connected') | endif

let symbol = empty(a:symbol) ? expand('<cword>') : a:symbol
call iced#nrepl#cider#undef(symbol, {resp -> s:undefined(resp, symbol)})
call iced#nrepl#op#cider#undef(symbol, {resp -> s:undefined(resp, symbol)})
endfunction

function! s:print_last(resp) abort
Expand All @@ -114,7 +114,7 @@ function! s:print_last(resp) abort
endfunction

function! iced#nrepl#eval#print_last() abort
call iced#nrepl#cider#pprint_eval('*1', funcref('s:print_last'))
call iced#nrepl#op#cider#pprint_eval('*1', funcref('s:print_last'))
endfunction

function! iced#nrepl#eval#outer_top_list() abort
Expand Down
2 changes: 1 addition & 1 deletion autoload/iced/nrepl/everywhere.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function! s:everywhere(candidates) abort
endfunction

function! iced#nrepl#everywhere#search() abort
call iced#nrepl#iced#everywhere(funcref('s:everywhere'))
call iced#nrepl#op#iced#everywhere(funcref('s:everywhere'))
endfunction

let &cpo = s:save_cpo
Expand Down
4 changes: 2 additions & 2 deletions autoload/iced/nrepl/function.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function! s:open(mode, resp) abort
endfunction

function! s:resolve(mode, func_name) abort
call iced#nrepl#cider#info(a:func_name, {resp -> s:open(a:mode, resp)})
call iced#nrepl#op#cider#info(a:func_name, {resp -> s:open(a:mode, resp)})
endfunction

function! s:select(functions) abort
Expand All @@ -41,7 +41,7 @@ function! iced#nrepl#function#list() abort
" call ctrlp#iced#start({'candidates': lines, 'accept': funcref('s:resolve')})
" else
call iced#message#info('fetching')
call iced#nrepl#iced#project_functions(funcref('s:select'))
call iced#nrepl#op#iced#project_functions(funcref('s:select'))
" endif
endfunction

Expand Down
2 changes: 1 addition & 1 deletion autoload/iced/nrepl/jump.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function! iced#nrepl#jump#jump(symbol) abort
call s:L.push(s:tagstack, pos)

let kw = empty(a:symbol) ? expand('<cword>') : a:symbol
call iced#nrepl#cider#info(kw, function('s:jump'))
call iced#nrepl#op#cider#info(kw, function('s:jump'))
endfunction

function! iced#nrepl#jump#back() abort
Expand Down
4 changes: 2 additions & 2 deletions autoload/iced/nrepl/macro.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ function! s:view(resp) abort
endfunction

function! iced#nrepl#macro#expand(code) abort
call iced#nrepl#cider#macroexpand_all(a:code, funcref('s:view'))
call iced#nrepl#op#cider#macroexpand_all(a:code, funcref('s:view'))
endfunction

function! iced#nrepl#macro#expand_1(code) abort
call iced#nrepl#cider#macroexpand_1(a:code, funcref('s:view'))
call iced#nrepl#op#cider#macroexpand_1(a:code, funcref('s:view'))
endfunction

function! iced#nrepl#macro#expand_outer_list() abort
Expand Down
113 changes: 2 additions & 111 deletions autoload/iced/nrepl/ns.vim
Original file line number Diff line number Diff line change
@@ -1,77 +1,13 @@
let s:save_cpo = &cpo
set cpo&vim

let s:default_ns_favorites = {
\ 'clj': {
\ 'clojure.edn': 'edn',
\ 'clojure.java.io': 'io',
\ 'clojure.set': 'set',
\ 'clojure.spec.alpha': 's',
\ 'clojure.spec.gen.alpha': 'sgen',
\ 'clojure.string': 'str',
\ 'clojure.walk': 'walk',
\ 'clojure.zip': 'zip',
\ },
\ 'cljs': {
\ 'cljs.reader': 'reader',
\ 'cljs.spec.alpha': 's',
\ 'cljs.spec.gen.alpha': 'sgen',
\ 'clojure.set': 'set',
\ 'clojure.string': 'str',
\ 'clojure.walk': 'walk',
\ 'clojure.zip': 'zip',
\ },
\ }
let g:iced#nrepl#ns#favorites = get(g:, 'iced#nrepl#ns#favorites', s:default_ns_favorites)

function! s:search_ns() abort
call cursor(1, 1)
let line = trim(getline('.'))
if line !=# '(ns' && line[0:3] !=# '(ns '
return search('(ns[ \r\n]')
endif
return 1
endfunction

function! iced#nrepl#ns#replace(new_ns) abort
let view = winsaveview()
let reg_save = @@

try
if s:search_ns() == 0
call iced#message#error('ns_not_found')
return
endif
silent normal! dab

let new_ns = trim(a:new_ns)
let before_lnum = len(split(@@, '\r\?\n'))
let after_lnum = len(split(new_ns, '\r\?\n'))
let view['lnum'] = view['lnum'] + (after_lnum - before_lnum)

if before_lnum == 1
call deletebufline('%', line('.'), 1)
endif

let lnum = line('.') - 1
call append(lnum, split(new_ns, '\r\?\n'))
finally
let @@ = reg_save
if s:search_ns() != 0
call iced#format#form()
call iced#nrepl#ns#eval(v:none)
endif
call winrestview(view)
endtry
endfunction

function! iced#nrepl#ns#get() abort
let view = winsaveview()
let reg_save = @@
let code = v:none

try
if s:search_ns() == 0
if iced#nrepl#ns#util#search() == 0
return v:none
endif
silent normal! va(y
Expand Down Expand Up @@ -103,7 +39,7 @@ function! iced#nrepl#ns#name() abort
let reg_save = @@

try
if s:search_ns() == 0
if iced#nrepl#ns#util#search() == 0
let ns_name = s:ns_name_by_var()
if empty(ns_name)
call iced#message#error('ns_not_found')
Expand Down Expand Up @@ -194,50 +130,5 @@ function! iced#nrepl#ns#in_repl_session_ns() abort
call iced#nrepl#eval#code(code)
endfunction

function! s:add_ns(ns_name) abort
let favorites = get(g:iced#nrepl#ns#favorites, iced#nrepl#current_session_key(), {})
if has_key(favorites, a:ns_name)
let ns_alias = favorites[a:ns_name]
else
let candidate = iced#nrepl#ns#alias#find_existing_alias(a:ns_name)
if empty(candidate)
let candidate = ''
endif
let ns_alias = trim(input('Alias: ', candidate))
endif

let code = iced#nrepl#ns#get()
let code = iced#nrepl#ns#util#add_require_form(code)
let code = iced#nrepl#ns#util#add_namespace_to_require(code, a:ns_name, ns_alias)
call iced#nrepl#ns#replace(code)

let msg = ''
if empty(ns_alias)
let msg = printf(iced#message#get('ns_added'), a:ns_name)
else
let msg = printf(iced#message#get('ns_added_as'), a:ns_name, ns_alias)
endif
call iced#message#info_str(msg)
endfunction

function! s:project_namespaces(namespaces) abort
let namespaces = (empty(a:namespaces) ? [] : a:namespaces)
let favorites = get(g:iced#nrepl#ns#favorites, iced#nrepl#current_session_key(), {})
call extend(namespaces, keys(favorites))

call ctrlp#iced#start({
\ 'candidates': namespaces,
\ 'accept': {_, ns_name -> s:add_ns(ns_name)}
\ })
endfunction

function! iced#nrepl#ns#add(ns_name) abort
if empty(a:ns_name)
call iced#nrepl#iced#project_namespaces(funcref('s:project_namespaces'))
else
call s:add_ns(a:ns_name)
endif
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
32 changes: 4 additions & 28 deletions autoload/iced/nrepl/ns/alias.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,13 @@ set cpo&vim
let s:V = vital#iced#new()
let s:D = s:V.import('Data.Dict')

function! s:parse_to_alias_dict(resp) abort
if !has_key(a:resp, 'value') || a:resp['value'][0] !=# '{'
return {}
endif

let value = a:resp['value']
let value = value[1:len(value)-2]

let ls = split(value, ',\? ')
let ls = map(ls, {i, v -> (i % 2) == 0 ? v : iced#nrepl#ns#util#extract_ns(v)})
return s:D.from_list(ls)
endfunction

function! iced#nrepl#ns#alias#dict(ns) abort
let code = printf('(ns-aliases ''%s)', a:ns)
let resp = iced#nrepl#sync#send({
\ 'op': 'eval',
\ 'code': code,
\ 'session': iced#nrepl#current_session(),
\ 'verbose': v:false,
\ })
return s:parse_to_alias_dict(resp)
endfunction

function! iced#nrepl#ns#alias#dict_from_code(code) abort
let resp = iced#nrepl#refactor#ns_parser#aliases(a:code)
return s:parse_to_alias_dict(resp)
function! iced#nrepl#ns#alias#dict(code) abort
let resp = iced#nrepl#op#iced#sync#ns_aliases(a:code)
return has_key(resp, 'aliases') ? resp['aliases'] : {}
endfunction

function! iced#nrepl#ns#alias#find_existing_alias(ns_name) abort
let aliases = iced#nrepl#refactor#sync#all_ns_aliases()
let aliases = iced#nrepl#op#refactor#sync#all_ns_aliases()
let aliases = get(aliases, iced#nrepl#current_session_key(), {})

for k in keys(aliases)
Expand Down
Loading

0 comments on commit c1cd92f

Please sign in to comment.