2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2018-07-18 04:31:23 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-20 08:44:13 -07:00
|
|
|
local uv = vim.uv
|
2018-07-18 04:31:23 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local api = n.api
|
|
|
|
local feed = n.feed
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
|
|
|
local neq = t.neq
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
2024-04-08 02:03:20 -07:00
|
|
|
local ok = t.ok
|
2024-04-20 08:44:13 -07:00
|
|
|
local fn = n.fn
|
|
|
|
local nvim_prog = n.nvim_prog
|
2024-04-08 02:03:20 -07:00
|
|
|
local retry = t.retry
|
|
|
|
local write_file = t.write_file
|
|
|
|
local assert_log = t.assert_log
|
2024-04-20 08:44:13 -07:00
|
|
|
local check_close = n.check_close
|
2024-04-08 02:03:20 -07:00
|
|
|
local is_os = t.is_os
|
2023-09-24 12:19:01 -07:00
|
|
|
|
|
|
|
local testlog = 'Xtest-embed-log'
|
2018-07-18 04:31:23 -07:00
|
|
|
|
2018-09-28 05:19:37 -07:00
|
|
|
local function test_embed(ext_linegrid)
|
2018-09-20 10:19:38 -07:00
|
|
|
local screen
|
2018-07-18 04:31:23 -07:00
|
|
|
local function startup(...)
|
2019-04-16 16:38:59 -07:00
|
|
|
clear { args_rm = { '--headless' }, args = { ... } }
|
2018-07-18 04:31:23 -07:00
|
|
|
|
|
|
|
-- attach immediately after startup, for early UI
|
2024-11-11 14:15:19 -07:00
|
|
|
screen = Screen.new(60, 8, { ext_linegrid = ext_linegrid })
|
2024-11-09 06:14:29 -07:00
|
|
|
screen:add_extra_attr_ids {
|
|
|
|
[100] = { foreground = Screen.colors.NvimDarkCyan },
|
|
|
|
[101] = { foreground = Screen.colors.NvimDarkRed },
|
|
|
|
[102] = {
|
|
|
|
background = Screen.colors.NvimDarkGrey3,
|
|
|
|
foreground = Screen.colors.NvimLightGrey3,
|
|
|
|
},
|
|
|
|
}
|
2018-07-18 04:31:23 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it('can display errors', function()
|
|
|
|
startup('--cmd', 'echoerr invalid+')
|
|
|
|
screen:expect([[
|
2023-12-09 05:42:00 -07:00
|
|
|
|*4
|
2024-11-09 06:14:29 -07:00
|
|
|
{102: }|
|
|
|
|
{9:Error detected while processing pre-vimrc command line:} |
|
|
|
|
{9:E121: Undefined variable: invalid} |
|
|
|
|
{6:Press ENTER or type command to continue}^ |
|
2018-07-18 04:31:23 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
feed('<cr>')
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
2024-11-09 06:14:29 -07:00
|
|
|
{1:~ }|*6
|
2018-07-18 04:31:23 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2018-09-20 03:06:19 -07:00
|
|
|
it("doesn't erase output when setting color scheme", function()
|
2024-04-08 02:03:20 -07:00
|
|
|
if t.is_os('openbsd') then
|
2019-10-17 19:46:30 -07:00
|
|
|
pending('FIXME #10804')
|
2019-09-01 18:07:00 -07:00
|
|
|
end
|
2018-07-18 04:31:23 -07:00
|
|
|
startup('--cmd', 'echoerr "foo"', '--cmd', 'color default', '--cmd', 'echoerr "bar"')
|
|
|
|
screen:expect([[
|
2023-12-09 05:42:00 -07:00
|
|
|
|*3
|
2024-11-09 06:14:29 -07:00
|
|
|
{102: }|
|
|
|
|
{9:Error detected while processing pre-vimrc command line:} |
|
|
|
|
{9:foo} |
|
|
|
|
{101:bar} |
|
|
|
|
{100:Press ENTER or type command to continue}^ |
|
2018-07-18 04:31:23 -07:00
|
|
|
]])
|
|
|
|
end)
|
2018-09-20 03:06:19 -07:00
|
|
|
|
|
|
|
it("doesn't erase output when setting Normal colors", function()
|
|
|
|
startup('--cmd', 'echoerr "foo"', '--cmd', 'hi Normal guibg=Green', '--cmd', 'echoerr "bar"')
|
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2023-12-09 05:42:00 -07:00
|
|
|
|*3
|
2024-11-09 06:14:29 -07:00
|
|
|
{102: }|
|
|
|
|
{9:Error detected while processing pre-vimrc command line:} |
|
|
|
|
{9:foo} |
|
|
|
|
{9:bar} |
|
|
|
|
{6:Press ENTER or type command to continue}^ |
|
2018-09-20 03:06:19 -07:00
|
|
|
]],
|
|
|
|
condition = function()
|
|
|
|
eq(Screen.colors.Green, screen.default_colors.rgb_bg)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2018-09-28 05:19:37 -07:00
|
|
|
describe('--embed UI on startup (ext_linegrid=true)', function()
|
|
|
|
test_embed(true)
|
|
|
|
end)
|
|
|
|
describe('--embed UI on startup (ext_linegrid=false)', function()
|
|
|
|
test_embed(false)
|
|
|
|
end)
|
2022-04-22 11:56:31 -07:00
|
|
|
|
|
|
|
describe('--embed UI', function()
|
2023-09-24 12:19:01 -07:00
|
|
|
after_each(function()
|
2024-04-05 20:18:43 -07:00
|
|
|
check_close()
|
2023-09-24 12:19:01 -07:00
|
|
|
os.remove(testlog)
|
|
|
|
end)
|
|
|
|
|
2022-04-22 11:56:31 -07:00
|
|
|
it('can pass stdin', function()
|
|
|
|
local pipe = assert(uv.pipe())
|
|
|
|
|
|
|
|
local writer = assert(uv.new_pipe(false))
|
|
|
|
writer:open(pipe.write)
|
|
|
|
|
2023-09-24 12:19:01 -07:00
|
|
|
clear { args_rm = { '--headless' }, io_extra = pipe.read, env = { NVIM_LOG_FILE = testlog } }
|
2022-04-22 11:56:31 -07:00
|
|
|
|
|
|
|
-- attach immediately after startup, for early UI
|
2024-11-11 14:15:19 -07:00
|
|
|
-- rpc_async: Avoid hanging. #24888
|
|
|
|
local screen = Screen.new(40, 8, { stdin_fd = 3 }, false)
|
2023-10-09 01:14:37 -07:00
|
|
|
screen.rpc_async = true -- Avoid hanging. #24888
|
2024-11-11 14:15:19 -07:00
|
|
|
screen:attach()
|
2022-04-22 11:56:31 -07:00
|
|
|
|
|
|
|
writer:write 'hello nvim\nfrom external input\n'
|
|
|
|
writer:shutdown(function()
|
|
|
|
writer:close()
|
|
|
|
end)
|
|
|
|
|
2024-02-02 06:17:37 -07:00
|
|
|
screen:expect [[
|
2022-04-22 11:56:31 -07:00
|
|
|
^hello nvim |
|
|
|
|
from external input |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*5
|
2022-04-22 11:56:31 -07:00
|
|
|
|
|
2024-02-02 06:17:37 -07:00
|
|
|
]]
|
2022-04-22 11:56:31 -07:00
|
|
|
|
|
|
|
-- stdin (rpc input) still works
|
|
|
|
feed 'o'
|
2024-02-02 06:17:37 -07:00
|
|
|
screen:expect [[
|
2022-04-22 11:56:31 -07:00
|
|
|
hello nvim |
|
|
|
|
^ |
|
|
|
|
from external input |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*4
|
2024-11-09 06:14:29 -07:00
|
|
|
{5:-- INSERT --} |
|
2024-02-02 06:17:37 -07:00
|
|
|
]]
|
2023-09-24 12:19:01 -07:00
|
|
|
|
|
|
|
if not is_os('win') then
|
2024-04-08 02:03:20 -07:00
|
|
|
assert_log('Failed to get flags on descriptor 3: Bad file descriptor', testlog, 100)
|
2023-09-24 12:19:01 -07:00
|
|
|
end
|
2024-02-02 06:17:37 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can pass stdin to -q - #17523', function()
|
|
|
|
write_file(
|
|
|
|
'Xbadfile.c',
|
|
|
|
[[
|
|
|
|
/* some file with an error */
|
|
|
|
main() {
|
|
|
|
functionCall(arg; arg, arg);
|
|
|
|
return 666
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
finally(function()
|
|
|
|
os.remove('Xbadfile.c')
|
|
|
|
end)
|
|
|
|
|
|
|
|
local pipe = assert(uv.pipe())
|
|
|
|
|
|
|
|
local writer = assert(uv.new_pipe(false))
|
|
|
|
writer:open(pipe.write)
|
|
|
|
|
|
|
|
clear { args_rm = { '--headless' }, args = { '-q', '-' }, io_extra = pipe.read }
|
|
|
|
|
|
|
|
-- attach immediately after startup, for early UI
|
2024-11-11 14:15:19 -07:00
|
|
|
local screen = Screen.new(60, 8, { stdin_fd = 3 }, false)
|
2024-02-02 06:17:37 -07:00
|
|
|
screen.rpc_async = true -- Avoid hanging. #24888
|
2024-11-11 14:15:19 -07:00
|
|
|
screen:attach()
|
2024-02-02 06:17:37 -07:00
|
|
|
|
|
|
|
writer:write [[Xbadfile.c:4:12: error: expected ';' before '}' token]]
|
|
|
|
writer:shutdown(function()
|
|
|
|
writer:close()
|
|
|
|
end)
|
|
|
|
|
|
|
|
screen:expect [[
|
|
|
|
/* some file with an error */ |
|
|
|
|
main() { |
|
|
|
|
functionCall(arg; arg, arg); |
|
|
|
|
return 66^6 |
|
|
|
|
} |
|
|
|
|
{1:~ }|*2
|
|
|
|
(1 of 1): error: expected ';' before '}' token |
|
|
|
|
]]
|
|
|
|
|
|
|
|
-- stdin (rpc input) still works
|
|
|
|
feed 'A'
|
|
|
|
screen:expect [[
|
|
|
|
/* some file with an error */ |
|
|
|
|
main() { |
|
|
|
|
functionCall(arg; arg, arg); |
|
|
|
|
return 666^ |
|
|
|
|
} |
|
|
|
|
{1:~ }|*2
|
2024-11-09 06:14:29 -07:00
|
|
|
{5:-- INSERT --} |
|
2024-02-02 06:17:37 -07:00
|
|
|
]]
|
|
|
|
|
|
|
|
eq('-', api.nvim_get_option_value('errorfile', {}))
|
2022-04-22 11:56:31 -07:00
|
|
|
end)
|
2023-12-04 01:50:00 -07:00
|
|
|
|
|
|
|
it('only sets background colors once even if overridden', function()
|
|
|
|
local screen, current, seen
|
|
|
|
local function handle_default_colors_set(_, _, rgb_bg, _, _, _)
|
|
|
|
seen[rgb_bg] = true
|
|
|
|
current = rgb_bg
|
|
|
|
end
|
|
|
|
local function startup(...)
|
|
|
|
seen = {}
|
|
|
|
current = nil
|
|
|
|
clear { args_rm = { '--headless' }, args = { ... } }
|
|
|
|
|
|
|
|
-- attach immediately after startup, for early UI
|
|
|
|
screen = Screen.new(40, 8)
|
|
|
|
screen._handle_default_colors_set = handle_default_colors_set
|
|
|
|
end
|
|
|
|
|
|
|
|
startup()
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
|
|
|
eq(16777215, current)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
eq({ [16777215] = true }, seen)
|
|
|
|
|
2024-04-10 17:51:06 -07:00
|
|
|
-- NB: by accident how functional/testutil.lua currently handles the default color scheme, the
|
2023-12-04 01:50:00 -07:00
|
|
|
-- above is sufficient to test the behavior. But in case that workaround is removed, we need
|
|
|
|
-- a test with an explicit override like below, so do it to remain safe.
|
|
|
|
startup('--cmd', 'hi NORMAL guibg=#FF00FF')
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
|
|
|
eq(16711935, current)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
eq({ [16711935] = true }, seen) -- we only saw the last one, despite 16777215 was set internally earlier
|
|
|
|
end)
|
2024-01-19 13:51:10 -07:00
|
|
|
|
|
|
|
it('updates cwd of attached UI #21771', function()
|
|
|
|
clear { args_rm = { '--headless' } }
|
|
|
|
|
|
|
|
local screen = Screen.new(40, 8)
|
|
|
|
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
2024-04-08 02:03:20 -07:00
|
|
|
eq(t.paths.test_source_path, screen.pwd)
|
2024-01-19 13:51:10 -07:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Change global cwd
|
2024-04-20 08:44:13 -07:00
|
|
|
n.command(string.format('cd %s/src/nvim', t.paths.test_source_path))
|
2024-01-19 13:51:10 -07:00
|
|
|
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
2024-04-08 02:03:20 -07:00
|
|
|
eq(string.format('%s/src/nvim', t.paths.test_source_path), screen.pwd)
|
2024-01-19 13:51:10 -07:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Split the window and change the cwd in the split
|
2024-04-20 08:44:13 -07:00
|
|
|
n.command('new')
|
|
|
|
n.command(string.format('lcd %s/test', t.paths.test_source_path))
|
2024-01-19 13:51:10 -07:00
|
|
|
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
2024-04-08 02:03:20 -07:00
|
|
|
eq(string.format('%s/test', t.paths.test_source_path), screen.pwd)
|
2024-01-19 13:51:10 -07:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Move to the original window
|
2024-04-20 08:44:13 -07:00
|
|
|
n.command('wincmd p')
|
2024-01-19 13:51:10 -07:00
|
|
|
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
2024-04-08 02:03:20 -07:00
|
|
|
eq(string.format('%s/src/nvim', t.paths.test_source_path), screen.pwd)
|
2024-01-19 13:51:10 -07:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Change global cwd again
|
2024-04-20 08:44:13 -07:00
|
|
|
n.command(string.format('cd %s', t.paths.test_source_path))
|
2024-01-19 13:51:10 -07:00
|
|
|
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
2024-04-08 02:03:20 -07:00
|
|
|
eq(t.paths.test_source_path, screen.pwd)
|
2024-01-19 13:51:10 -07:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
end)
|
2022-04-22 11:56:31 -07:00
|
|
|
end)
|
2023-10-31 20:04:53 -07:00
|
|
|
|
|
|
|
describe('--embed --listen UI', function()
|
|
|
|
it('waits for connection on listening address', function()
|
2024-04-08 02:03:20 -07:00
|
|
|
t.skip(t.is_os('win'))
|
2023-10-31 20:04:53 -07:00
|
|
|
clear()
|
2024-04-20 08:44:13 -07:00
|
|
|
local child_server = assert(n.new_pipename())
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.jobstart({
|
feat(highlight): update default color scheme
Problem: Default color scheme is suboptimal.
Solution: Start using new color scheme. Introduce new `vim` color scheme
for opt-in backward compatibility.
------
Main design ideas
- Be "Neovim branded".
- Be minimal for 256 colors with a bit more shades for true colors.
- Be accessible through high enough contrast ratios.
- Be suitable for dark and light backgrounds via exchange of dark and
light palettes.
------
Palettes
- Have dark and light variants. Implemented through exporeted
`NvimDark*` and `NvimLight*` hex colors.
- Palettes have 4 shades of grey for UI elements and 6 colors (red,
yellow, green, cyan, blue, magenta).
- Actual values are computed procedurally in Oklch color space based on
a handful of hyperparameters.
- Each color has a 256 colors variant with perceptually closest color.
------
Highlight groups
Use:
- Grey shades for general UI according to their design.
- Bold text for keywords (`Statement` highlight group). This is an
important choice to increase accessibility for people with color
deficiencies, as it doesn't rely on actual color.
- Green for strings, `DiffAdd` (as background), `DiagnosticOk`, and some
minor text UI elements.
- Cyan as main syntax color, i.e. for function usage (`Function`
highlight group), `DiffText`, `DiagnosticInfo`, and some minor text UI
elements.
- Red to generally mean high user attention, i.e. errors; in particular
for `ErrorMsg`, `DiffDelete`, `DiagnosticError`.
- Yellow very sparingly only with true colors to mean mild user
attention, i.e. warnings. That is, `DiagnosticWarn` and `WarningMsg`.
- Blue very sparingly only with true colors as `DiagnosticHint` and some
additional important syntax group (like `Identifier`).
- Magenta very carefully (if at all).
------
Notes
- To make tests work without relatively larege updates, each one is
prepended with an equivalent of the call `:colorscheme vim`.
Plus some tests which spawn new Neovim instances also now use 'vim'
color scheme.
In some cases tests are updated to fit new default color scheme.
2023-11-29 13:16:09 -07:00
|
|
|
nvim_prog,
|
|
|
|
'--embed',
|
|
|
|
'--listen',
|
|
|
|
child_server,
|
|
|
|
'--clean',
|
|
|
|
'--cmd',
|
|
|
|
'colorscheme vim',
|
|
|
|
})
|
2023-11-02 17:19:04 -07:00
|
|
|
retry(nil, nil, function()
|
|
|
|
neq(nil, uv.fs_stat(child_server))
|
|
|
|
end)
|
2023-10-31 20:04:53 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local child_session = n.connect(child_server)
|
2023-10-31 20:04:53 -07:00
|
|
|
|
2023-10-31 21:16:37 -07:00
|
|
|
local info_ok, api_info = child_session:request('nvim_get_api_info')
|
|
|
|
ok(info_ok)
|
|
|
|
eq(2, #api_info)
|
|
|
|
ok(api_info[1] > 2, 'channel_id > 2', api_info[1])
|
2023-10-31 20:04:53 -07:00
|
|
|
|
|
|
|
child_session:request(
|
|
|
|
'nvim_exec2',
|
|
|
|
[[
|
2023-10-31 21:16:37 -07:00
|
|
|
let g:evs = []
|
|
|
|
autocmd UIEnter * call add(g:evs, $"UIEnter:{v:event.chan}")
|
|
|
|
autocmd VimEnter * call add(g:evs, "VimEnter")
|
2023-10-31 20:04:53 -07:00
|
|
|
]],
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
|
2023-10-31 21:16:37 -07:00
|
|
|
-- VimEnter and UIEnter shouldn't be triggered until after attach
|
|
|
|
local var_ok, var = child_session:request('nvim_get_var', 'evs')
|
|
|
|
ok(var_ok)
|
|
|
|
eq({}, var)
|
2023-10-31 20:04:53 -07:00
|
|
|
|
2024-11-11 14:15:19 -07:00
|
|
|
local child_screen = Screen.new(40, 6, nil, child_session)
|
2023-10-31 20:04:53 -07:00
|
|
|
child_screen:expect {
|
|
|
|
grid = [[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*3
|
2023-11-02 17:19:04 -07:00
|
|
|
{2:[No Name] 0,0-1 All}|
|
2023-10-31 20:04:53 -07:00
|
|
|
|
|
|
|
|
]],
|
|
|
|
attr_ids = {
|
|
|
|
[1] = { foreground = Screen.colors.Blue, bold = true },
|
2023-11-02 17:19:04 -07:00
|
|
|
[2] = { reverse = true, bold = true },
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2023-10-31 20:04:53 -07:00
|
|
|
}
|
|
|
|
|
2023-10-31 21:16:37 -07:00
|
|
|
-- VimEnter and UIEnter should now be triggered
|
|
|
|
var_ok, var = child_session:request('nvim_get_var', 'evs')
|
|
|
|
ok(var_ok)
|
|
|
|
eq({ 'VimEnter', ('UIEnter:%d'):format(api_info[1]) }, var)
|
2023-10-31 20:04:53 -07:00
|
|
|
end)
|
|
|
|
end)
|