mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	Merge #4553
This commit is contained in:
		| @@ -157,6 +157,9 @@ endfunction | |||||||
|  |  | ||||||
| function! remote#define#FunctionOnChannel(channel, method, sync, name, opts) | function! remote#define#FunctionOnChannel(channel, method, sync, name, opts) | ||||||
|   let rpcargs = [a:channel, '"'.a:method.'"', 'a:000'] |   let rpcargs = [a:channel, '"'.a:method.'"', 'a:000'] | ||||||
|  |   if has_key(a:opts, 'range') | ||||||
|  |     call add(rpcargs, '[a:firstline, a:lastline]') | ||||||
|  |   endif | ||||||
|   call s:AddEval(rpcargs, a:opts) |   call s:AddEval(rpcargs, a:opts) | ||||||
|  |  | ||||||
|   let function_def = s:GetFunctionPrefix(a:name, a:opts) |   let function_def = s:GetFunctionPrefix(a:name, a:opts) | ||||||
| @@ -218,7 +221,11 @@ endfunction | |||||||
|  |  | ||||||
|  |  | ||||||
| function! s:GetFunctionPrefix(name, opts) | function! s:GetFunctionPrefix(name, opts) | ||||||
|   return "function! ".a:name."(...)\n" |   let res = "function! ".a:name."(...)" | ||||||
|  |   if has_key(a:opts, 'range') | ||||||
|  |     let res = res." range" | ||||||
|  |   endif | ||||||
|  |   return res."\n" | ||||||
| endfunction | endfunction | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -64,8 +64,7 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|         args = args..', "RpcCommand"' |         args = args..', "RpcCommand"' | ||||||
|       end) |       end) | ||||||
|  |  | ||||||
|       describe('without options', function() |       it('without options', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {}') |         call(fn, args..', {}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('RpcCommand') |           command('RpcCommand') | ||||||
| @@ -78,10 +77,8 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with nargs', function() |       it('with nargs', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {"nargs": "*"}') |         call(fn, args..', {"nargs": "*"}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('RpcCommand arg1 arg2 arg3') |           command('RpcCommand arg1 arg2 arg3') | ||||||
| @@ -95,10 +92,8 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with range', function() |       it('with range', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn,args..', {"range": ""}') |         call(fn,args..', {"range": ""}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('1,1RpcCommand') |           command('1,1RpcCommand') | ||||||
| @@ -112,10 +107,8 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with nargs/range', function() |       it('with nargs/range', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {"nargs": "1", "range": ""}') |         call(fn, args..', {"nargs": "1", "range": ""}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('1,1RpcCommand arg') |           command('1,1RpcCommand arg') | ||||||
| @@ -130,10 +123,8 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with nargs/count', function() |       it('with nargs/count', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {"nargs": "1", "range": "5"}') |         call(fn, args..', {"nargs": "1", "range": "5"}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('5RpcCommand arg') |           command('5RpcCommand arg') | ||||||
| @@ -148,10 +139,8 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with nargs/count/bang', function() |       it('with nargs/count/bang', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {"nargs": "1", "range": "5", "bang": ""}') |         call(fn, args..', {"nargs": "1", "range": "5", "bang": ""}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('5RpcCommand! arg') |           command('5RpcCommand! arg') | ||||||
| @@ -167,10 +156,8 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with nargs/count/bang/register', function() |       it('with nargs/count/bang/register', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. |         call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. | ||||||
|         ' "register": ""}') |         ' "register": ""}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
| @@ -188,10 +175,8 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with nargs/count/bang/register/eval', function() |       it('with nargs/count/bang/register/eval', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. |         call(fn, args..', {"nargs": "1", "range": "5", "bang": "",'.. | ||||||
|         ' "register": "", "eval": "@<reg>"}') |         ' "register": "", "eval": "@<reg>"}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
| @@ -213,7 +198,6 @@ local function command_specs_for(fn, sync, first_arg_factory, init) | |||||||
|       end) |       end) | ||||||
|     end) |     end) | ||||||
|   end) |   end) | ||||||
|   end) |  | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -236,8 +220,7 @@ local function autocmd_specs_for(fn, sync, first_arg_factory, init) | |||||||
|         args = args..', "BufEnter"' |         args = args..', "BufEnter"' | ||||||
|       end) |       end) | ||||||
|  |  | ||||||
|       describe('without options', function() |       it('without options', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {}') |         call(fn, args..', {}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('doautocmd BufEnter x.c') |           command('doautocmd BufEnter x.c') | ||||||
| @@ -250,10 +233,8 @@ local function autocmd_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with eval', function() |       it('with eval', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..[[, {'eval': 'expand("<afile>")'}]]) |         call(fn, args..[[, {'eval': 'expand("<afile>")'}]]) | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           command('doautocmd BufEnter x.c') |           command('doautocmd BufEnter x.c') | ||||||
| @@ -269,7 +250,6 @@ local function autocmd_specs_for(fn, sync, first_arg_factory, init) | |||||||
|       end) |       end) | ||||||
|     end) |     end) | ||||||
|   end) |   end) | ||||||
|   end) |  | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -292,8 +272,7 @@ local function function_specs_for(fn, sync, first_arg_factory, init) | |||||||
|         args = args..', "TestFunction"' |         args = args..', "TestFunction"' | ||||||
|       end) |       end) | ||||||
|  |  | ||||||
|       describe('without options', function() |       it('without options', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..', {}') |         call(fn, args..', {}') | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           if sync then |           if sync then | ||||||
| @@ -311,10 +290,8 @@ local function function_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|       end) |  | ||||||
|  |  | ||||||
|       describe('with eval', function() |       it('with eval', function() | ||||||
|         it('ok', function() |  | ||||||
|         call(fn, args..[[, {'eval': '2 + 2'}]]) |         call(fn, args..[[, {'eval': '2 + 2'}]]) | ||||||
|         local function on_setup() |         local function on_setup() | ||||||
|           if sync then |           if sync then | ||||||
| @@ -332,6 +309,40 @@ local function function_specs_for(fn, sync, first_arg_factory, init) | |||||||
|  |  | ||||||
|         runx(sync, handler, on_setup) |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|  |  | ||||||
|  |       it('with range', function() | ||||||
|  |         helpers.insert([[ | ||||||
|  |           foo | ||||||
|  |           bar | ||||||
|  |           baz | ||||||
|  |           zub]]) | ||||||
|  |         call(fn, args..[[, {'range': ''}]]) | ||||||
|  |         local function on_setup() | ||||||
|  |           command('2,3call TestFunction(1, "a", ["b", "c"])') | ||||||
|  |         end | ||||||
|  |  | ||||||
|  |         local function handler(method, arguments) | ||||||
|  |           eq('test-handler', method) | ||||||
|  |           eq({{1, 'a', {'b', 'c'}}, {2, 3}}, arguments) | ||||||
|  |           return 'rv' | ||||||
|  |         end | ||||||
|  |  | ||||||
|  |         runx(sync, handler, on_setup) | ||||||
|  |       end) | ||||||
|  |  | ||||||
|  |       it('with eval/range', function() | ||||||
|  |         call(fn, args..[[, {'eval': '4', 'range': ''}]]) | ||||||
|  |         local function on_setup() | ||||||
|  |           command('%call TestFunction(1, "a", ["b", "c"])') | ||||||
|  |         end | ||||||
|  |  | ||||||
|  |         local function handler(method, arguments) | ||||||
|  |           eq('test-handler', method) | ||||||
|  |           eq({{1, 'a', {'b', 'c'}}, {1, 1}, 4}, arguments) | ||||||
|  |           return 'rv' | ||||||
|  |         end | ||||||
|  |  | ||||||
|  |         runx(sync, handler, on_setup) | ||||||
|       end) |       end) | ||||||
|     end) |     end) | ||||||
|   end) |   end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes