fixup! feat(jobs): jobstart(…,{term:true}), deprecate termopen()

This commit is contained in:
Justin M. Keyes 2024-12-18 16:23:24 +01:00
parent 4c346f677e
commit f7890bb005
5 changed files with 37 additions and 12 deletions

View File

@ -293,6 +293,7 @@ TERMINAL
means that the |TermCursorNC| highlight group is no longer supported: an means that the |TermCursorNC| highlight group is no longer supported: an
unfocused terminal window will have no cursor at all (so there is nothing to unfocused terminal window will have no cursor at all (so there is nothing to
highlight). highlight).
• |jobstart()| gained the "term" flag.
TREESITTER TREESITTER

View File

@ -42,4 +42,3 @@ void f_termopen(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
tv_dict_free(argvars[1].vval.v_dict); tv_dict_free(argvars[1].vval.v_dict);
} }
} }

View File

@ -2,8 +2,8 @@
#include <stdbool.h> // for true #include <stdbool.h> // for true
#include "nvim/message.h" // for semsg
#include "nvim/eval/typval_defs.h" // IWYU pragma: keep #include "nvim/eval/typval_defs.h" // IWYU pragma: keep
#include "nvim/message.h" // for semsg
#include "nvim/types_defs.h" // IWYU pragma: keep #include "nvim/types_defs.h" // IWYU pragma: keep
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS

View File

@ -3992,6 +3992,14 @@ void f_jobstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
} }
} }
dictitem_T *const job_term = tv_dict_find(job_opts, S_LEN("term"));
if (job_term && VAR_BOOL != job_term->di_tv.v_type) {
// Restrict "term" field to boolean, in case we want to allow buffer numbers in the future.
semsg(_(e_invarg2), "'term' must Boolean");
shell_free_argv(argv);
return;
}
if (pty && rpc) { if (pty && rpc) {
semsg(_(e_invarg2), "job cannot have both 'pty' and 'rpc' options set"); semsg(_(e_invarg2), "job cannot have both 'pty' and 'rpc' options set");
shell_free_argv(argv); shell_free_argv(argv);
@ -4111,8 +4119,7 @@ void f_jobstart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
channel_terminal_open(curbuf, chan); channel_terminal_open(curbuf, chan);
channel_create_event(chan, NULL); channel_create_event(chan, NULL);
channel_decref(chan); channel_decref(chan);
} } else if (chan) {
else if (chan) {
channel_create_event(chan, NULL); channel_create_event(chan, NULL);
} }
} }

View File

@ -65,6 +65,31 @@ describe('jobs', function()
]]) ]])
end) end)
it('validation', function()
matches(
"E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set",
pcall_err(command, "let j = jobstart(['cat', '-'], { 'pty': v:true, 'rpc': v:true })")
)
matches(
'E475: Invalid argument: expected valid directory',
pcall_err(command, "let j = jobstart(['cat', '-'], { 'cwd': 1 })")
)
matches(
'E475: Invalid argument: expected valid directory',
pcall_err(command, "let j = jobstart(['cat', '-'], { 'cwd': 'bogusssssss/bogus' })")
)
matches(
"E475: Invalid argument: 'term' must Boolean",
pcall_err(command, "let j = jobstart(['cat', '-'], { 'term': 'bogus' })")
)
matches(
"E475: Invalid argument: 'term' must Boolean",
pcall_err(command, "let j = jobstart(['cat', '-'], { 'term': 1 })")
)
command("let j = jobstart(['cat', '-'], { 'term': v:true })")
command("let j = jobstart(['cat', '-'], { 'term': v:false })")
end)
it('must specify env option as a dict', function() it('must specify env option as a dict', function()
command('let g:job_opts.env = v:true') command('let g:job_opts.env = v:true')
local _, err = pcall(function() local _, err = pcall(function()
@ -969,13 +994,6 @@ describe('jobs', function()
eq({ 'notification', 'exit', { 0, 143 } }, next_msg()) eq({ 'notification', 'exit', { 0, 143 } }, next_msg())
end) end)
it('cannot have both rpc and pty options', function()
command('let g:job_opts.pty = v:true')
command('let g:job_opts.rpc = v:true')
local _, err = pcall(command, "let j = jobstart(['cat', '-'], g:job_opts)")
matches("E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set", err)
end)
it('does not crash when repeatedly failing to start shell', function() it('does not crash when repeatedly failing to start shell', function()
source([[ source([[
set shell=nosuchshell set shell=nosuchshell