From 7c6e35e7c079dfdd9b8f20629f4c6712cb520f79 Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 24 Oct 2018 15:03:29 +0900 Subject: [PATCH 1/8] Move iced#channel#... to iced#dicon#... --- autoload/iced/channel.vim | 13 -------- autoload/iced/dicon.vim | 35 ++++++++++++++++++++ autoload/iced/dicon/channel.vim | 13 ++++++++ autoload/iced/{ => dicon}/channel/neovim.vim | 2 +- autoload/iced/{ => dicon}/channel/vim.vim | 2 +- 5 files changed, 50 insertions(+), 15 deletions(-) delete mode 100644 autoload/iced/channel.vim create mode 100644 autoload/iced/dicon.vim create mode 100644 autoload/iced/dicon/channel.vim rename autoload/iced/{ => dicon}/channel/neovim.vim (96%) rename autoload/iced/{ => dicon}/channel/vim.vim (91%) diff --git a/autoload/iced/channel.vim b/autoload/iced/channel.vim deleted file mode 100644 index cedafc0ce..000000000 --- a/autoload/iced/channel.vim +++ /dev/null @@ -1,13 +0,0 @@ -let s:save_cpo = &cpo -set cpo&vim - -function! iced#channel#new() abort - if has('nvim') - return iced#channel#neovim#new() - else - return iced#channel#vim#new() - endif -endfunction - -let &cpo = s:save_cpo -unlet s:save_cpo diff --git a/autoload/iced/dicon.vim b/autoload/iced/dicon.vim new file mode 100644 index 000000000..97a55593a --- /dev/null +++ b/autoload/iced/dicon.vim @@ -0,0 +1,35 @@ +let s:save_cpo = &cpo +set cpo&vim + +let s:container = {} + +function! s:default_builder(name) abort + let l:res = '' + exe printf('let l:res = iced#dicon#%s#build()', a:name) + return l:res +endfunction + +function! s:value(name) abort + return a:name.'.value' +endfunction + +function! iced#dicon#register(name, builder) abort + let s:container[a:name] = a:builder + if has_key(s:container, s:value(a:name)) + unlet s:container[s:value(a:name)] + endif +endfunction + +function! iced#dicon#build(name) abort + let Builder = get(s:container, a:name, function('s:default_builder', [a:name])) + let value_name = s:value(a:name) + let s:container[value_name] = Builder() + return s:container[value_name] +endfunction + +function! iced#dicon#get(name) abort + return get(s:container, s:value(a:name), iced#dicon#build(a:name)) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/autoload/iced/dicon/channel.vim b/autoload/iced/dicon/channel.vim new file mode 100644 index 000000000..7f0e10f4d --- /dev/null +++ b/autoload/iced/dicon/channel.vim @@ -0,0 +1,13 @@ +let s:save_cpo = &cpo +set cpo&vim + +function! iced#dicon#channel#build() abort + if has('nvim') + return iced#dicon#channel#neovim#build() + else + return iced#dicon#channel#vim#build() + endif +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/autoload/iced/channel/neovim.vim b/autoload/iced/dicon/channel/neovim.vim similarity index 96% rename from autoload/iced/channel/neovim.vim rename to autoload/iced/dicon/channel/neovim.vim index b6d8a1950..486189470 100644 --- a/autoload/iced/channel/neovim.vim +++ b/autoload/iced/dicon/channel/neovim.vim @@ -52,7 +52,7 @@ function! s:ch.sendraw(handle, string) abort return ret endfunction -function! iced#channel#neovim#new() abort +function! iced#dicon#channel#neovim#build() abort return s:ch endfunction diff --git a/autoload/iced/channel/vim.vim b/autoload/iced/dicon/channel/vim.vim similarity index 91% rename from autoload/iced/channel/vim.vim rename to autoload/iced/dicon/channel/vim.vim index b263e17c2..a004cbfbf 100644 --- a/autoload/iced/channel/vim.vim +++ b/autoload/iced/dicon/channel/vim.vim @@ -21,7 +21,7 @@ function! s:ch.sendraw(handle, string) abort return ch_sendraw(a:handle, a:string) endfunction -function! iced#channel#vim#new() abort +function! iced#dicon#channel#vim#build() abort return s:ch endfunction From cc9d3fa183845d0ad149011453690078ebc02f94 Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 24 Oct 2018 15:04:44 +0900 Subject: [PATCH 2/8] Update codes to use iced#dicon#channel --- autoload/iced/nrepl.vim | 13 ++++--------- test/format.vim | 2 +- test/helper/autoload/themis/helper/iced_channel.vim | 6 +++--- test/nrepl.vim | 12 ++++++------ test/nrepl_ns_util.vim | 4 ++-- test/paredit.vim | 2 +- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/autoload/iced/nrepl.vim b/autoload/iced/nrepl.vim index 62063c19e..bddf8182f 100644 --- a/autoload/iced/nrepl.vim +++ b/autoload/iced/nrepl.vim @@ -17,7 +17,6 @@ endfunction let s:nrepl = s:initialize_nrepl() let s:handlers = {} -let s:ch = iced#channel#new() let s:messages = {} let s:response_buffer = '' @@ -31,10 +30,6 @@ function! iced#nrepl#id() abort return res endfunction -function! iced#nrepl#inject_channel(ch) abort - let s:ch = a:ch -endfunction - " SESSIONS {{{ function! iced#nrepl#set_session(k, v) abort if a:k =~# '\(cljs\?\|repl\)' @@ -225,7 +220,7 @@ function! iced#nrepl#send(data) abort let s:messages[id] = message endif - call s:ch.sendraw(s:nrepl['channel'], iced#nrepl#bencode#encode(data)) + call iced#dicon#get('channel').sendraw(s:nrepl['channel'], iced#nrepl#bencode#encode(data)) endfunction function! iced#nrepl#is_op_running(op) abort " {{{ @@ -248,7 +243,7 @@ endfunction function! s:status(ch) abort try - return s:ch.status(a:ch) + return iced#dicon#get('channel').status(a:ch) catch return 'fail' endtry @@ -285,7 +280,7 @@ function! iced#nrepl#connect(port) abort if ! iced#nrepl#is_connected() let address = printf('%s:%d', g:iced#nrepl#host, a:port) let s:nrepl['port'] = a:port - let s:nrepl['channel'] = s:ch.open(address, { + let s:nrepl['channel'] = iced#dicon#get('channel').open(address, { \ 'mode': 'raw', \ 'callback': funcref('s:dispatcher'), \ 'drop': 'never', @@ -313,7 +308,7 @@ function! iced#nrepl#disconnect() abort " {{{ call iced#nrepl#sync#send({'op': 'interrupt', 'session': id}) call iced#nrepl#sync#close(id) endfor - call s:ch.close(s:nrepl['channel']) + call iced#dicon#get('channel').close(s:nrepl['channel']) call s:initialize_nrepl() call iced#cache#clear() endfunction " }}} diff --git a/test/format.vim b/test/format.vim index b71855c8f..48e01b0de 100644 --- a/test/format.vim +++ b/test/format.vim @@ -20,7 +20,7 @@ function! s:suite.form_test() abort \ '(list :foo)', \ '(list 123 456|)', \ ]) - call s:ch.inject_dummy({ + call s:ch.register_test_builder({ \ 'status_value': 'open', \ 'relay': {msg -> s:format_code_relay(msg, ':dummy-formatted')}}) diff --git a/test/helper/autoload/themis/helper/iced_channel.vim b/test/helper/autoload/themis/helper/iced_channel.vim index 095e5dd7f..9bfe73477 100644 --- a/test/helper/autoload/themis/helper/iced_channel.vim +++ b/test/helper/autoload/themis/helper/iced_channel.vim @@ -5,7 +5,7 @@ let s:helper = {} let s:Local = g:themis#vital.import('Vim.ScriptLocal') let s:funcs = s:Local.sfuncs('autoload/iced/nrepl.vim') -function! s:test_channel(opt) abort +function! s:build_test_channel(opt) abort let dummy = {'env': 'test', 'status_value': 'fail'} call extend(dummy, a:opt) @@ -53,8 +53,8 @@ function! s:test_channel(opt) abort return dummy endfunction -function! s:helper.inject_dummy(opt) abort - call iced#nrepl#inject_channel(s:test_channel(a:opt)) +function! s:helper.register_test_builder(opt) abort + call iced#dicon#register('channel', function('s:build_test_channel', [a:opt])) endfunction function! themis#helper#iced_channel#new(runner) abort diff --git a/test/nrepl.vim b/test/nrepl.vim index 815b4335e..c1c0bf3fe 100644 --- a/test/nrepl.vim +++ b/test/nrepl.vim @@ -45,10 +45,10 @@ function! s:suite.change_to_invalid_session_test() abort endfunction function! s:suite.is_connected_test() abort - call s:ch.inject_dummy({'status_value': 'open'}) + call s:ch.register_test_builder({'status_value': 'open'}) call s:assert.true(iced#nrepl#is_connected()) - call s:ch.inject_dummy({'status_value': 'fail'}) + call s:ch.register_test_builder({'status_value': 'fail'}) call s:assert.false(iced#nrepl#is_connected()) endfunction @@ -61,7 +61,7 @@ function! s:suite.connect_test() abort return {} endfunction - call s:ch.inject_dummy({ + call s:ch.register_test_builder({ \ 'status_value': 'open', \ 'relay': {msg -> test.relay(msg)}, \ }) @@ -77,7 +77,7 @@ function! s:suite.connect_test() abort endfunction function! s:suite.connect_failure_test() abort - call s:ch.inject_dummy({'status_value': 'fail'}) + call s:ch.register_test_builder({'status_value': 'fail'}) call s:assert.equals(iced#nrepl#connect(1234), v:false) endfunction @@ -94,7 +94,7 @@ function! s:suite.disconnect_test() abort return {'status': ['done']} endfunction - call s:ch.inject_dummy({ + call s:ch.register_test_builder({ \ 'status_value': 'open', \ 'relay': {msg -> test.relay(msg)}, \ }) @@ -123,7 +123,7 @@ function! s:suite.eval_test() abort let self['result'] = a:result endfunction - call s:ch.inject_dummy({ + call s:ch.register_test_builder({ \ 'status_value': 'open', \ 'relay_raw': {msg -> test.relay_raw(msg)}, \ }) diff --git a/test/nrepl_ns_util.vim b/test/nrepl_ns_util.vim index 913a46bd9..eb9314a3a 100644 --- a/test/nrepl_ns_util.vim +++ b/test/nrepl_ns_util.vim @@ -16,7 +16,7 @@ function! s:suite.replace_test() abort call s:buf.start_dummy([ \ '(ns foo.core)', \ 'nil|']) - call s:ch.inject_dummy({'status_value': 'open', 'relay': funcref('s:format_relay')}) + call s:ch.register_test_builder({'status_value': 'open', 'relay': funcref('s:format_relay')}) call s:assert.equals(line('.'), 2) call iced#nrepl#ns#util#replace("(ns bar.core\n (:require clojure.string))") @@ -93,7 +93,7 @@ function! s:suite.add_test() abort call s:buf.start_dummy([ \ '(ns foo.core)', \ 'nil|']) - call s:ch.inject_dummy({'status_value': 'open', 'relay': funcref('s:format_relay')}) + call s:ch.register_test_builder({'status_value': 'open', 'relay': funcref('s:format_relay')}) call s:assert.equals(line('.'), 2) diff --git a/test/paredit.vim b/test/paredit.vim index 5490a2f3c..317629267 100644 --- a/test/paredit.vim +++ b/test/paredit.vim @@ -19,7 +19,7 @@ function! s:format_code_relay(msg) abort endfunction function! s:suite.deep_slurp_test() abort - call s:ch.inject_dummy({ + call s:ch.register_test_builder({ \ 'status_value': 'open', \ 'relay': funcref('s:format_code_relay'), \ }) From 60ed52fff2ad79c0d4e42f55005204f586989ed9 Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 24 Oct 2018 15:36:18 +0900 Subject: [PATCH 3/8] Move iced#nrepl#bencode#... to iced#dicon#bencode#... --- autoload/iced/dicon/bencode.vim | 51 +++++++++++++++++ .../iced/{nrepl => dicon}/bencode/python.vim | 9 +-- .../iced/{nrepl => dicon}/bencode/vim.vim | 57 +++++++++++++++++-- autoload/iced/nrepl/bencode.vim | 57 ------------------- 4 files changed, 108 insertions(+), 66 deletions(-) create mode 100644 autoload/iced/dicon/bencode.vim rename autoload/iced/{nrepl => dicon}/bencode/python.vim (66%) rename autoload/iced/{nrepl => dicon}/bencode/vim.vim (61%) delete mode 100644 autoload/iced/nrepl/bencode.vim diff --git a/autoload/iced/dicon/bencode.vim b/autoload/iced/dicon/bencode.vim new file mode 100644 index 000000000..9d6d9070c --- /dev/null +++ b/autoload/iced/dicon/bencode.vim @@ -0,0 +1,51 @@ +let s:save_cpo = &cpo +set cpo&vim + +" function! s:encode_string(s) abort +" return printf('%d:%s', strlen(a:s), a:s) +" endfunction +" +" function! s:encode_number(i) abort +" return printf('i%de', a:i) +" endfunction +" +" function! s:encode_list(l) abort +" let result = [] +" for v in a:l +" call add(result, s:encode(v)) +" endfor +" return printf('l%se', join(result, '')) +" endfunction +" +" function! s:encode_dict(d) abort +" let result = [] +" for k in keys(a:d) +" call add(result, s:encode(k)) +" call add(result, s:encode(a:d[k])) +" endfor +" return printf('d%se', join(result, '')) +" endfunction +" +" function! s:encode(v) abort +" let t = type(a:v) +" if t == 0 +" return s:encode_number(a:v) +" elseif t == 1 +" return s:encode_string(a:v) +" elseif t == 3 +" return s:encode_list(a:v) +" elseif t == 4 +" return s:encode_dict(a:v) +" elseif t == 7 +" return s:encode_string('') +" endif +" endfunction + +function! iced#dicon#bencode#build() abort + return has('python3') + \ ? iced#dicon#bencode#python#build() + \ : iced#dicon#bencode#vim#build() +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/autoload/iced/nrepl/bencode/python.vim b/autoload/iced/dicon/bencode/python.vim similarity index 66% rename from autoload/iced/nrepl/bencode/python.vim rename to autoload/iced/dicon/bencode/python.vim index 19215a872..c4217e2be 100644 --- a/autoload/iced/nrepl/bencode/python.vim +++ b/autoload/iced/dicon/bencode/python.vim @@ -3,9 +3,8 @@ set cpo&vim python3 import vim py3file :h:h:h:h:h/python/bencode.py -let s:decoder = {} -function! s:decoder.decode(s) abort +function! s:decode_via_python(s) abort let ret = '' python3 < Date: Wed, 24 Oct 2018 15:37:11 +0900 Subject: [PATCH 4/8] Update codes to use bencode via dicon --- autoload/iced/nrepl.vim | 6 +- test/bencode.vim | 89 +++++++++++++++---- test/bencode_vim.vim | 50 ----------- .../autoload/themis/helper/iced_channel.vim | 6 +- test/nrepl.vim | 4 +- 5 files changed, 83 insertions(+), 72 deletions(-) delete mode 100644 test/bencode_vim.vim diff --git a/autoload/iced/nrepl.vim b/autoload/iced/nrepl.vim index bddf8182f..4ab3000d1 100644 --- a/autoload/iced/nrepl.vim +++ b/autoload/iced/nrepl.vim @@ -124,7 +124,7 @@ function! s:dispatcher(ch, resp) abort call iced#util#debug(text) try - let resp = iced#nrepl#bencode#decode(text) + let resp = iced#dicon#get('bencode').decode(text) catch /Failed to parse bencode/ let s:response_buffer = (len(text) > g:iced#nrepl#buffer_size) ? '' : text return @@ -220,7 +220,9 @@ function! iced#nrepl#send(data) abort let s:messages[id] = message endif - call iced#dicon#get('channel').sendraw(s:nrepl['channel'], iced#nrepl#bencode#encode(data)) + call iced#dicon#get('channel').sendraw( + \ s:nrepl['channel'], + \ iced#dicon#get('bencode').encode(data)) endfunction function! iced#nrepl#is_op_running(op) abort " {{{ diff --git a/test/bencode.vim b/test/bencode.vim index 8c16909d4..5ab2365d0 100644 --- a/test/bencode.vim +++ b/test/bencode.vim @@ -1,30 +1,89 @@ -let s:suite = themis#suite('iced.nrepl.bencode') +let s:suite = themis#suite('iced.dicon.bencode.vim') let s:assert = themis#helper('assert') +function! s:assert_parse_failure(f) abort + try + call a:f() + call s:assert.fail('must be errored') + catch /^Failed to parse/ + call s:assert.true(1) + catch + call s:assert.fail('unexpected error: ' . v:exception) + endtry +endfunction + "" ENCODING TEST function! s:suite.encode_string_test() abort - call s:assert.equals('5:hello', iced#nrepl#bencode#encode('hello')) - call s:assert.equals('0:', iced#nrepl#bencode#encode('')) - call s:assert.equals('0:', iced#nrepl#bencode#encode(v:none)) + call iced#dicon#register('bencode', function('iced#dicon#bencode#vim#build')) + + call s:assert.equals('5:hello', iced#dicon#get('bencode').encode('hello')) + call s:assert.equals('0:', iced#dicon#get('bencode').encode('')) + call s:assert.equals('0:', iced#dicon#get('bencode').encode(v:none)) endfunction function! s:suite.encode_number_test() abort - call s:assert.equals('i1024e', iced#nrepl#bencode#encode(1024)) + call iced#dicon#register('bencode', function('iced#dicon#bencode#vim#build')) + + call s:assert.equals('i1024e', iced#dicon#get('bencode').encode(1024)) endfunction function! s:suite.encode_list_test() abort - call s:assert.equals('l3:fooi123ee', iced#nrepl#bencode#encode(['foo', 123])) - call s:assert.equals('l3:fooli123eee', iced#nrepl#bencode#encode(['foo', [123]])) - call s:assert.equals('le', iced#nrepl#bencode#encode([])) - call s:assert.equals('l0:e', iced#nrepl#bencode#encode([''])) + call iced#dicon#register('bencode', function('iced#dicon#bencode#vim#build')) + + call s:assert.equals('l3:fooi123ee', iced#dicon#get('bencode').encode(['foo', 123])) + call s:assert.equals('l3:fooli123eee', iced#dicon#get('bencode').encode(['foo', [123]])) + call s:assert.equals('le', iced#dicon#get('bencode').encode([])) + call s:assert.equals('l0:e', iced#dicon#get('bencode').encode([''])) endfunction function! s:suite.encode_dict_test() abort - call s:assert.equals('d3:fooi123ee', iced#nrepl#bencode#encode({'foo': 123})) - call s:assert.equals('d3:fool3:bari123eee', iced#nrepl#bencode#encode({'foo': ['bar', 123]})) - call s:assert.equals('d3:food3:bari123eee', iced#nrepl#bencode#encode({'foo': {'bar': 123}})) - call s:assert.equals('de', iced#nrepl#bencode#encode({})) - call s:assert.equals('d3:foo0:e', iced#nrepl#bencode#encode({'foo': ''})) - call s:assert.equals('d3:foo0:e', iced#nrepl#bencode#encode({'foo': v:none})) + call iced#dicon#register('bencode', function('iced#dicon#bencode#vim#build')) + + call s:assert.equals('d3:fooi123ee', iced#dicon#get('bencode').encode({'foo': 123})) + call s:assert.equals('d3:fool3:bari123eee', iced#dicon#get('bencode').encode({'foo': ['bar', 123]})) + call s:assert.equals('d3:food3:bari123eee', iced#dicon#get('bencode').encode({'foo': {'bar': 123}})) + call s:assert.equals('de', iced#dicon#get('bencode').encode({})) + call s:assert.equals('d3:foo0:e', iced#dicon#get('bencode').encode({'foo': ''})) + call s:assert.equals('d3:foo0:e', iced#dicon#get('bencode').encode({'foo': v:none})) +endfunction + +"" DECODING TEST + +function! s:suite.decode_string_test() abort + call iced#dicon#register('bencode', function('iced#dicon#bencode#vim#build')) + + call s:assert.equals('hello', iced#dicon#get('bencode').decode('5:hello')) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('5:helloo')}) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('5hello')}) +endfunction + +function! s:suite.decode_integer_test() abort + call s:assert.equals(1024, iced#dicon#get('bencode').decode('i1024e')) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('i1024')}) +endfunction + +function! s:suite.decode_list_test() abort + call s:assert.equals(['foo', 123], iced#dicon#get('bencode').decode('l3:fooi123ee')) + call s:assert.equals(['foo', [123]], iced#dicon#get('bencode').decode('l3:fooli123eee')) + call s:assert.equals([], iced#dicon#get('bencode').decode('le')) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('li1024e')}) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('li1024')}) +endfunction + +function! s:suite.decode_dict_test() abort + call s:assert.equals({'foo': 123}, iced#dicon#get('bencode').decode('d3:fooi123ee')) + call s:assert.equals({'foo': ['bar', 123]}, iced#dicon#get('bencode').decode('d3:fool3:bari123eee')) + call s:assert.equals({'foo': {'bar': 123}}, iced#dicon#get('bencode').decode('d3:food3:bari123eee')) + call s:assert.equals({}, iced#dicon#get('bencode').decode('de')) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('d3:fooi123e')}) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('d3:fooi123')}) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('d3:foo')}) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('d3:fo')}) + call s:assert_parse_failure({-> iced#dicon#get('bencode').decode('d')}) +endfunction + +function! s:suite.decode_concated_test() abort + call s:assert.equals(['foo', 123], iced#dicon#get('bencode').decode('3:fooi123e')) + call s:assert.equals([{'foo': 123}, {'bar': 456}], iced#dicon#get('bencode').decode('d3:fooi123eed3:bari456ee')) endfunction diff --git a/test/bencode_vim.vim b/test/bencode_vim.vim deleted file mode 100644 index 9c191851c..000000000 --- a/test/bencode_vim.vim +++ /dev/null @@ -1,50 +0,0 @@ -let s:suite = themis#suite('iced.nrepl.bencode.vim') -let s:assert = themis#helper('assert') -let s:d = iced#nrepl#bencode#vim#new() - -function! s:assert_parse_failure(f) abort - try - call a:f() - call s:assert.fail('must be errored') - catch /^Failed to parse/ - call s:assert.true(1) - catch - call s:assert.fail('unexpected error: ' . v:exception) - endtry -endfunction - -function! s:suite.decode_string_test() abort - call s:assert.equals('hello', s:d.decode('5:hello')) - call s:assert_parse_failure({-> s:d.decode('5:helloo')}) - call s:assert_parse_failure({-> s:d.decode('5hello')}) -endfunction - -function! s:suite.decode_integer_test() abort - call s:assert.equals(1024, s:d.decode('i1024e')) - call s:assert_parse_failure({-> s:d.decode('i1024')}) -endfunction - -function! s:suite.decode_list_test() abort - call s:assert.equals(['foo', 123], s:d.decode('l3:fooi123ee')) - call s:assert.equals(['foo', [123]], s:d.decode('l3:fooli123eee')) - call s:assert.equals([], s:d.decode('le')) - call s:assert_parse_failure({-> s:d.decode('li1024e')}) - call s:assert_parse_failure({-> s:d.decode('li1024')}) -endfunction - -function! s:suite.decode_dict_test() abort - call s:assert.equals({'foo': 123}, s:d.decode('d3:fooi123ee')) - call s:assert.equals({'foo': ['bar', 123]}, s:d.decode('d3:fool3:bari123eee')) - call s:assert.equals({'foo': {'bar': 123}}, s:d.decode('d3:food3:bari123eee')) - call s:assert.equals({}, s:d.decode('de')) - call s:assert_parse_failure({-> s:d.decode('d3:fooi123e')}) - call s:assert_parse_failure({-> s:d.decode('d3:fooi123')}) - call s:assert_parse_failure({-> s:d.decode('d3:foo')}) - call s:assert_parse_failure({-> s:d.decode('d3:fo')}) - call s:assert_parse_failure({-> s:d.decode('d')}) -endfunction - -function! s:suite.decode_concated_test() abort - call s:assert.equals(['foo', 123], s:d.decode('3:fooi123e')) - call s:assert.equals([{'foo': 123}, {'bar': 456}], s:d.decode('d3:fooi123eed3:bari456ee')) -endfunction diff --git a/test/helper/autoload/themis/helper/iced_channel.vim b/test/helper/autoload/themis/helper/iced_channel.vim index 9bfe73477..3ce1a06ee 100644 --- a/test/helper/autoload/themis/helper/iced_channel.vim +++ b/test/helper/autoload/themis/helper/iced_channel.vim @@ -25,18 +25,18 @@ function! s:build_test_channel(opt) abort function! dummy.sendraw(handle, string) abort if has_key(self, 'relay') && type(self.relay) == 2 - let sent_data = iced#nrepl#bencode#decode(a:string) + let sent_data = iced#dicon#get('bencode').decode(a:string) let resp_data = self.relay(sent_data) if has_key(sent_data, 'id') && !has_key(resp_data, 'id') let resp_data['id'] = sent_data['id'] endif - let resp_data = iced#nrepl#bencode#encode(resp_data) + let resp_data = iced#dicon#get('bencode').encode(resp_data) let Cb = (has_key(self, 'callback') && type(self.callback) == 2) \ ? self.callback : s:funcs.dispatcher call Cb(self, resp_data) elseif has_key(self, 'relay_raw') && type(self.relay_raw) == 2 - let sent_data = iced#nrepl#bencode#decode(a:string) + let sent_data = iced#dicon#get('bencode').decode(a:string) let resp_data = self.relay_raw(sent_data) let Cb = (has_key(self, 'callback') && type(self.callback) == 2) \ ? self.callback : s:funcs.dispatcher diff --git a/test/nrepl.vim b/test/nrepl.vim index c1c0bf3fe..5baac73e9 100644 --- a/test/nrepl.vim +++ b/test/nrepl.vim @@ -114,8 +114,8 @@ function! s:suite.eval_test() abort function! test.relay_raw(msg) abort if a:msg['op'] !=# 'eval' | return '' | endif - let resp1 = iced#nrepl#bencode#encode({'id': 123, 'ns': 'foo.core', 'value': 6}) - let resp2 = iced#nrepl#bencode#encode({'id': 123, 'status': ['done']}) + let resp1 = iced#dicon#get('bencode').encode({'id': 123, 'ns': 'foo.core', 'value': 6}) + let resp2 = iced#dicon#get('bencode').encode({'id': 123, 'status': ['done']}) return (s:split_half(resp1) + s:split_half(resp2)) endfunction From 6221ea257c6f590910ea0119392f35b878ab2129 Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 24 Oct 2018 16:34:20 +0900 Subject: [PATCH 5/8] Update iced#message to allowing printf arguments --- autoload/iced/message.vim | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/autoload/iced/message.vim b/autoload/iced/message.vim index e3c0babec..2d8462fc5 100644 --- a/autoload/iced/message.vim +++ b/autoload/iced/message.vim @@ -33,24 +33,36 @@ function! iced#message#error_str(s) abort call s:echom('ErrorMsg', a:s) endfunction -function! iced#message#echom(k) abort - echom iced#message#get(a:k) +function! iced#message#echom(k, ...) abort + let msg = iced#message#get(a:k) + if !empty(a:000) + let msg = call('printf', [msg] + a:000) + endif + echom msg endfunction -function! iced#message#info(k) abort - call iced#message#info_str(iced#message#get(a:k)) +function! iced#message#info(k, ...) abort + let msg = iced#message#get(a:k) + if !empty(a:000) + let msg = call('printf', [msg] + a:000) + endif + call iced#message#info_str(msg) endfunction -function! iced#message#warning(k) abort - call iced#message#warning_str(iced#message#get(a:k)) +function! iced#message#warning(k, ...) abort + let msg = iced#message#get(a:k) + if !empty(a:000) + let msg = call('printf', [msg] + a:000) + endif + call iced#message#warning_str(msg) endfunction -function! iced#message#error(k) abort - call iced#message#error_str(iced#message#get(a:k)) -endfunction - -function! iced#message#test(k) abort - return s:msg.get(a:k) +function! iced#message#error(k, ...) abort + let msg = iced#message#get(a:k) + if !empty(a:000) + let msg = call('printf', [msg] + a:000) + endif + call iced#message#error_str(msg) endfunction let &cpo = s:save_cpo From fa6537231778cae288c9ff7aaf78183803cc703d Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 24 Oct 2018 16:35:10 +0900 Subject: [PATCH 6/8] Tweak codes that using iced#message --- autoload/iced/nrepl/eval.vim | 2 +- autoload/iced/nrepl/ns.vim | 2 +- autoload/iced/nrepl/refactor.vim | 16 ++++++---------- autoload/iced/nrepl/trace.vim | 4 ++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/autoload/iced/nrepl/eval.vim b/autoload/iced/nrepl/eval.vim index 90e6b5a1d..b052032b4 100644 --- a/autoload/iced/nrepl/eval.vim +++ b/autoload/iced/nrepl/eval.vim @@ -105,7 +105,7 @@ function! s:undefined(resp, symbol) abort call iced#message#error_str(get(a:resp, 'ex', 'undef-error')) endif else - call iced#message#info_str(printf(iced#message#get('undefined'), a:symbol)) + call iced#message#info('undefined', a:symbol) endif endfunction diff --git a/autoload/iced/nrepl/ns.vim b/autoload/iced/nrepl/ns.vim index 385c99393..2252e9be3 100644 --- a/autoload/iced/nrepl/ns.vim +++ b/autoload/iced/nrepl/ns.vim @@ -126,7 +126,7 @@ endfunction function! iced#nrepl#ns#in_repl_session_ns() abort if iced#nrepl#current_session_key() ==# 'cljs' - return iced#message#error_str(printf(iced#message#get('invalid_session'), 'clj')) + return iced#message#error('invalid_session', 'clj') endif let ns_name = s:ns_name_by_var(iced#nrepl#repl_session()) diff --git a/autoload/iced/nrepl/refactor.vim b/autoload/iced/nrepl/refactor.vim index 37edf9491..2b44d82ef 100644 --- a/autoload/iced/nrepl/refactor.vim +++ b/autoload/iced/nrepl/refactor.vim @@ -113,7 +113,7 @@ endfunction function! s:add_ns(ns_name, symbol_alias) abort call iced#nrepl#ns#util#add(a:ns_name, a:symbol_alias) - call iced#message#info_str(printf(iced#message#get('ns_added'), a:ns_name)) + call iced#message#info('ns_added', a:ns_name) endfunction function! s:add_all_ns_alias_candidates(candidates, symbol_alias) abort @@ -143,7 +143,7 @@ function! s:resolve_missing(symbol, resp) abort else let alias_dict = iced#nrepl#ns#alias_dict(iced#nrepl#ns#get()) if has_key(alias_dict, symbol_alias) - return iced#message#error_str(printf(iced#message#get('alias_exists'), symbol_alias)) + return iced#message#error('alias_exists', symbol_alias) endif let existing_ns = values(alias_dict) + ['clojure.core'] @@ -187,14 +187,10 @@ function! s:add(ns_name) abort endif call iced#nrepl#ns#util#add(a:ns_name, ns_alias) - - 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) + return (empty(ns_alias) + \ ? iced#message#info('ns_added', a:ns_name) + \ : iced#message#info('ns_added_as', a:ns_name, ns_alias) + \ ) endfunction function! s:ns_list(resp) abort diff --git a/autoload/iced/nrepl/trace.vim b/autoload/iced/nrepl/trace.vim index 5d548df17..c8d9d96ad 100644 --- a/autoload/iced/nrepl/trace.vim +++ b/autoload/iced/nrepl/trace.vim @@ -32,7 +32,7 @@ function! s:toggle_trace_var(resp, opts) abort endif endif - call iced#message#info_str(printf(iced#message#get(msg_key), var)) + call iced#message#info(msg_key, var) endfunction function! iced#nrepl#trace#toggle_var(symbol) abort @@ -53,7 +53,7 @@ function! s:toggle_trace_ns(resp, ns_name) abort endif let msg_key = (a:resp['ns-status'] ==# 'traced') ? 'start_to_trace' : 'stop_to_trace' - call iced#message#info_str(printf(iced#message#get(msg_key), a:ns_name)) + call iced#message#info(msg_key, a:ns_name) endfunction function! iced#nrepl#trace#toggle_ns(ns_name) abort From d124e2025c070068ecb89654e4efcfd953785f37 Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 24 Oct 2018 16:35:56 +0900 Subject: [PATCH 7/8] Fix navigate#jump_to_def not to jump if path is in JAR file --- autoload/iced/nrepl/navigate.vim | 4 ++++ message/iced/en.txt | 1 + 2 files changed, 5 insertions(+) diff --git a/autoload/iced/nrepl/navigate.vim b/autoload/iced/nrepl/navigate.vim index 10c01647e..b5c91e0ac 100644 --- a/autoload/iced/nrepl/navigate.vim +++ b/autoload/iced/nrepl/navigate.vim @@ -58,6 +58,10 @@ function! s:jump(resp) abort let line = a:resp['line'] let column = a:resp['column'] + if stridx(path, 'jar:') == 0 + return iced#message#error('jump_error', path) + endif + if expand('%:p') !=# path execute(printf(':edit %s', path)) endif diff --git a/message/iced/en.txt b/message/iced/en.txt index ccad3636d..5ec3a5a23 100644 --- a/message/iced/en.txt +++ b/message/iced/en.txt @@ -50,5 +50,6 @@ 'invalid_session': 'Session error. You should be in %s session.', 'grimoire_error': 'Invalid response from Grimoire.', 'no_set_hidden': 'You must add `set hidden` to your .vimrc.', + 'jump_error': 'Failed to jump: ''%s''.', } #vim:ft=ruby From ecf48123edcd51903a30461c721e61c285d31d97 Mon Sep 17 00:00:00 2001 From: liquidz Date: Wed, 24 Oct 2018 18:10:37 +0900 Subject: [PATCH 8/8] ver 0.7.1 --- doc/vim-iced.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/vim-iced.txt b/doc/vim-iced.txt index 45a68af97..1266b67fc 100644 --- a/doc/vim-iced.txt +++ b/doc/vim-iced.txt @@ -1,6 +1,6 @@ *vim-iced.txt* Clojure interactive development environment for Vim8/Neovim -Version: 0.7.0 +Version: 0.7.1 Author : Masashi Iizuka License: MIT LICENSE