Skip to content

Commit 317e12e

Browse files
committed
fix(vim): work with autocmds defined in vim9script
Define code eval functions in legacy script file. Closes #5320
1 parent 6db73ac commit 317e12e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

autoload/coc/api.vim

+7-17
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,6 @@ export def DetachListener(bufnr: number): bool
372372
endif
373373
return false
374374
enddef
375-
376-
# Call the legacy execute, use silent to avoid vim block
377-
function Execute(command, ...) abort
378-
legacy return execute(a:command, get(a:, 1, 'silent'))
379-
endfunction
380-
381-
# Call the legacy win_execute, use silent to avoid vim block
382-
function Win_execute(winid, cmds, ...) abort
383-
legacy return win_execute(a:winid, a:cmds, get(a:, 1, 'silent'))
384-
endfunction
385375
# }}"
386376

387377
# nvim client methods {{
@@ -475,11 +465,11 @@ enddef
475465
# Not return on notification for possible void function call.
476466
export def Call_function(method: string, args: list<any>, notify: bool = false): any
477467
if method ==# 'execute'
478-
return call(Execute, args)
468+
return call('coc#compat#execute', args)
479469
elseif method ==# 'eval'
480470
return Eval(args[0])
481471
elseif method ==# 'win_execute'
482-
return call(Win_execute, args)
472+
return call('coc#compat#win_execute', args)
483473
elseif !notify
484474
return call(method, args)
485475
endif
@@ -496,7 +486,7 @@ enddef
496486

497487
# Use the legacy eval, could be called by Call
498488
export function Eval(expr) abort
499-
legacy return eval(a:expr)
489+
legacy return coc#compat#eval(a:expr)
500490
endfunction
501491

502492
export def Command(command: string): any
@@ -505,7 +495,7 @@ export def Command(command: string): any
505495
DeferExecute(command)
506496
else
507497
# Use legacy command not work for command like autocmd
508-
Execute(command)
498+
coc#compat#execute(command)
509499
# The error is set by python script, since vim not give error on python command failure
510500
if strpart(command, 0, 2) ==# 'py'
511501
const errmsg: string = get(g:, 'errmsg', '')
@@ -541,14 +531,14 @@ export def List_runtime_paths(): list<string>
541531
enddef
542532

543533
export def Command_output(cmd: string): string
544-
return trim(Execute(cmd, 'silent'), "\r\n")
534+
return trim(coc#compat#execute(cmd, 'silent'), "\r\n")
545535
enddef
546536

547537
export def Exec(code: string, output: bool): string
548538
if output
549539
return Command_output(code)
550540
endif
551-
Execute(code)
541+
coc#compat#execute(code)
552542
return ''
553543
enddef
554544

@@ -667,7 +657,7 @@ export def Set_keymap(mode: string, lhs: string, rhs: string, opts: dict<any>):
667657
const modekey: string = CreateModePrefix(mode, opts)
668658
const arguments: string = CreateArguments(opts)
669659
const escaped: string = empty(rhs) ? '<Nop>' : EscapeSpace(rhs)
670-
Execute($'{modekey} {arguments} {EscapeSpace(lhs)} {escaped}')
660+
coc#compat#execute($'{modekey} {arguments} {EscapeSpace(lhs)} {escaped}')
671661
return null
672662
enddef
673663

autoload/coc/compat.vim

+12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ function! coc#compat#list_runtime_paths() abort
8383
return coc#compat#call('list_runtime_paths', [])
8484
endfunction
8585

86+
function coc#compat#execute(command, ...) abort
87+
return execute(a:command, get(a:, 1, 'silent'))
88+
endfunction
89+
90+
function! coc#compat#eval(expr) abort
91+
return eval(a:expr)
92+
endfunction
93+
94+
function coc#compat#win_execute(id, command, ...) abort
95+
return win_execute(a:id, a:command, get(a:, 1, 'silent'))
96+
endfunction
97+
8698
" call api function on vim or neovim
8799
function! coc#compat#call(fname, args) abort
88100
if s:is_vim

0 commit comments

Comments
 (0)