Skip to content

Commit

Permalink
breaking: Remove IcedExtractFunction command
Browse files Browse the repository at this point in the history
cf. #419
  • Loading branch information
liquidz committed Aug 22, 2022
1 parent 8ff5a00 commit 3dba540
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 92 deletions.
45 changes: 0 additions & 45 deletions autoload/iced/nrepl/refactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -47,51 +47,6 @@ let g:iced#ns#favorites
\ = get(g:, 'iced#ns#favorites', s:default_ns_favorites) " }}}
let g:iced#ns#class_map = get(g:, 'iced#ns#class_map', {})

" iced#nrepl#refactor#extract_function {{{
function! s:found_used_locals(resp) abort
if !has_key(a:resp, 'used-locals')
let msg = get(a:resp, 'error', 'Unknown error')
return iced#message#error('used_locals_error', msg)
endif

let view = winsaveview()
let reg_save = @@

try
let locals = a:resp['used-locals']
let func_name = trim(iced#system#get('io').input('Function name: '))
if empty(func_name)
return iced#message#echom('canceled')
endif

let func_body = iced#paredit#get_outer_list_raw()

let @@ = empty(locals)
\ ? printf('(%s)', func_name)
\ : printf('(%s %s)', func_name, join(locals, ' '))
silent normal! gv"0p

let code = printf("(defn- %s [%s]\n %s)\n\n",
\ func_name, join(locals, ' '),
\ iced#util#add_indent(2, func_body))
let codes = split(code, '\r\?\n')

call iced#paredit#move_to_prev_top_element()
call append(line('.')-1, codes)
let view['lnum'] = view['lnum'] + len(codes)
finally
let @@ = reg_save
call winrestview(view)
endtry
endfunction

function! iced#nrepl#refactor#extract_function() abort
let path = expand('%:p')
let pos = getcurpos()
call iced#nrepl#op#refactor#find_used_locals(
\ path, pos[1], pos[2], funcref('s:found_used_locals'))
endfunction " }}}

" iced#nrepl#refactor#clean_ns {{{
function! s:clean_ns(resp) abort
if has_key(a:resp, 'error')
Expand Down
2 changes: 1 addition & 1 deletion autoload/iced/palette.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let s:default_palette = [
\ 'BrowseRelatedNamespace', 'BrowseSpec', 'BrowseTestUnderCursor',
\ 'BrowseReferences', 'BrowseDependencies',
\ 'CleanNs', 'CleanAll', 'AddNs', 'AddMissing',
\ 'ExtractFunction', 'AddArity', 'MoveToLet',
\ 'AddArity', 'MoveToLet',
\ 'RenameSymbol', 'YankNsName',
\ 'BrowseTapped', 'DeleteTapped', 'ClearTapped',
\ 'ToggleWarnOnReflection', 'ToggleTraceVar', 'ToggleTraceNs',
Expand Down
3 changes: 0 additions & 3 deletions ftplugin/clojure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ command! IcedCleanNs call iced#nrepl#refactor#clean_ns()
command! IcedCleanAll call iced#nrepl#refactor#clean_all()
command! -nargs=? IcedAddMissing call iced#nrepl#refactor#add_missing_ns(<q-args>)
command! -nargs=? IcedAddNs call iced#nrepl#refactor#add_ns(<q-args>)
command! IcedExtractFunction call iced#nrepl#refactor#extract_function()
command! IcedAddArity call iced#nrepl#refactor#add_arity()
command! IcedMoveToLet call iced#let#move_to_let()
command! -nargs=? IcedRenameSymbol call iced#nrepl#refactor#rename_symbol(<q-args>)
Expand Down Expand Up @@ -286,7 +285,6 @@ nnoremap <silent> <Plug>(iced_clean_ns) :<C-u>IcedCleanNs<CR>
nnoremap <silent> <Plug>(iced_clean_all) :<C-u>IcedCleanAll<CR>
nnoremap <silent> <Plug>(iced_add_missing) :<C-u>IcedAddMissing<CR>
nnoremap <silent> <Plug>(iced_add_ns) :<C-u>IcedAddNs<CR>
nnoremap <silent> <Plug>(iced_extract_function) :<C-u>IcedExtractFunction<CR>
nnoremap <silent> <Plug>(iced_add_arity) :<C-u>IcedAddArity<CR>
nnoremap <silent> <Plug>(iced_move_to_let) :<C-u>IcedMoveToLet<CR>
nnoremap <silent> <Plug>(iced_rename_symbol) :<C-u>IcedRenameSymbol<CR>
Expand Down Expand Up @@ -425,7 +423,6 @@ function! s:default_key_mappings() abort
call s:define_mapping('nmap', '<Leader>rca', '<Plug>(iced_clean_all)')
call s:define_mapping('nmap', '<Leader>ram', '<Plug>(iced_add_missing)')
call s:define_mapping('nmap', '<Leader>ran', '<Plug>(iced_add_ns)')
call s:define_mapping('nmap', '<Leader>ref', '<Plug>(iced_extract_function)')
call s:define_mapping('nmap', '<Leader>raa', '<Plug>(iced_add_arity)')
call s:define_mapping('nmap', '<Leader>rml', '<Plug>(iced_move_to_let)')
call s:define_mapping('nmap', '<Leader>rrs', '<Plug>(iced_rename_symbol)')
Expand Down
43 changes: 0 additions & 43 deletions test/nrepl_refactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,6 @@ let g:iced_enable_clj_kondo_analysis = v:false
let g:iced_enable_clj_kondo_local_analysis = v:false
let g:iced_cache_directory = ''

" extract_function {{{
function! s:extract_function_relay(locals, msg) abort
if a:msg['op'] ==# 'find-used-locals'
return {'status': ['done'], 'used-locals': a:locals}
endif
return {'status': ['done']}
endfunction

function! s:suite.extract_function_test() abort
call s:ch.mock({'status_value': 'open', 'relay': function('s:extract_function_relay', [['a', 'b']])})
call s:io.mock({'input': 'extracted'})
call s:buf.start_dummy(['(foo (bar a b|))'])

call iced#nrepl#refactor#extract_function()

call s:assert.equals(s:buf.get_lines(), [
\ '(defn- extracted [a b]',
\ ' (bar a b))',
\ '',
\ '(foo (extracted a b))',
\ ])

call s:buf.stop_dummy()
endfunction

function! s:suite.extract_function_with_no_args_test() abort
call s:ch.mock({'status_value': 'open', 'relay': function('s:extract_function_relay', [[]])})
call s:io.mock({'input': 'extracted'})
call s:buf.start_dummy(['(foo (bar|))'])

call iced#nrepl#refactor#extract_function()

call s:assert.equals(s:buf.get_lines(), [
\ '(defn- extracted []',
\ ' (bar))',
\ '',
\ '(foo (extracted))',
\ ])

call s:buf.stop_dummy()
endfunction
" }}}

" clean_ns {{{
function! s:clean_ns_relay(msg) abort
if a:msg['op'] ==# 'clean-ns'
Expand Down

0 comments on commit 3dba540

Please sign in to comment.