mirror of
https://github.com/neovim/neovim.git
synced 2026-07-31 12:49:11 +00:00
Problem:
Options parsing is still painful for dict-style options.
Solution:
schema-maxxing => better `opt:get()` (will be the basis for `vim.o()`),
unified (and more-detailed) err msgs.
- Drop bespoke structure-builder in `_core/options.lua`.
- Define `schema` for all non-primitive options (except 'guicursor' and
statusline-style options); generate reified keysets `OptKeyDict`).
- Generate 'fillchars' => `fcs_tab`, 'listchars' => `lcs_tab`.
- `nvim_set_option_value`:
- Return the improved structures. Also from `vim.opt.x:get()`.
- Eliminate api <=> lua roundtrip, centralize option structure
handling.
- Improve/unify errors.
- Bump ERR_BUFLEN 80 → 256 so the "one of" list isn't truncated.
- Eliminate old 'diffopt' order-dependence (`iwhiteall` before `iwhite`)
Error samples:
Typed-key path (opt_strings_check → diffopt/mousescroll/breakindentopt):
E474: Unknown item 'foo'
E474: 'context' requires a number
E474: 'ver' number is out of range
E474: 'algorithm' must be one of: myers, minimal, patience, histogram
E474: 'filler' does not take a value
Related:
- #31084
- #34661
- #31820
- #14739
- #20107
- fix #18875
- :get() returns `{ sbr = true, shift = '3' }` (reified-keyset) instead of `{'sbr', 'shift:3'}`
- Setting via table now works too. `object_as_optval_for` `is_map` now recognizes struct options.
- fix #30296
- instead of `E474: Invalid argument`, errors now look like:
```
E474: Invalid value 'x', expected one of: single, double: ambiwidth=x
E474: Unknown item 'foo': diffopt=foo
E474: 'context' requires a number: diffopt=context:x
```
simplify `win_float_parse_option` from #26799.
122 lines
3.5 KiB
Lua
122 lines
3.5 KiB
Lua
-- See also: test/old/testdir/test_options.vim
|
|
local t = require('test.testutil')
|
|
local n = require('test.functional.testnvim')()
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
local describe, it, before_each, setup = t.describe, t.it, t.before_each, t.setup
|
|
local command, clear = n.command, n.clear
|
|
local source, expect = n.source, n.expect
|
|
local matches = t.matches
|
|
local pcall_err = t.pcall_err
|
|
local eq = t.eq
|
|
|
|
describe('options', function()
|
|
setup(clear)
|
|
|
|
it('should not throw any exception', function()
|
|
command('options')
|
|
end)
|
|
end)
|
|
|
|
describe('options :set', function()
|
|
before_each(clear)
|
|
|
|
it("should keep two comma when 'path' is changed", function()
|
|
source([[
|
|
set path=foo,,bar
|
|
set path-=bar
|
|
set path+=bar
|
|
$put =&path]])
|
|
|
|
expect([[
|
|
|
|
foo,,bar]])
|
|
end)
|
|
|
|
it("'winminheight'", function()
|
|
local _ = Screen.new(20, 11)
|
|
source([[
|
|
set wmh=0 stal=2
|
|
below sp | wincmd _
|
|
below sp | wincmd _
|
|
below sp | wincmd _
|
|
below sp
|
|
]])
|
|
matches('E36: Not enough room', pcall_err(command, 'set wmh=1'))
|
|
end)
|
|
|
|
it("'winminheight' with tabline", function()
|
|
local _ = Screen.new(20, 11)
|
|
source([[
|
|
set wmh=0 stal=2
|
|
split
|
|
split
|
|
split
|
|
split
|
|
tabnew
|
|
]])
|
|
matches('E36: Not enough room', pcall_err(command, 'set wmh=1'))
|
|
end)
|
|
|
|
it("'scroll'", function()
|
|
local screen = Screen.new(42, 16)
|
|
source([[
|
|
set scroll=2
|
|
set laststatus=2
|
|
]])
|
|
command('verbose set scroll?')
|
|
screen:expect([[
|
|
|
|
|
{1:~ }|*11
|
|
{3: }|
|
|
scroll=7 |
|
|
Last set from changed window size |
|
|
{6:Press ENTER or type command to continue}^ |
|
|
]])
|
|
end)
|
|
|
|
it('foldcolumn and signcolumn to empty string is disallowed', function()
|
|
matches("E474: Invalid value ''.*fdc=", pcall_err(command, 'set fdc='))
|
|
matches('E474: Invalid argument: scl=', pcall_err(command, 'set scl='))
|
|
end)
|
|
end)
|
|
|
|
describe('options validation', function()
|
|
before_each(clear)
|
|
|
|
-- Improved error messages for structured "key:value" options ("schema" in options.lua).
|
|
it('reports specific errors for structured (schema) options', function()
|
|
eq("Vim(set):E474: Unknown item 'foo': diffopt=foo", pcall_err(command, 'set diffopt=foo'))
|
|
eq(
|
|
"Vim(set):E474: 'context' requires a number: diffopt=context:x",
|
|
pcall_err(command, 'set diffopt=context:x')
|
|
)
|
|
eq(
|
|
'Vim(set):E474: '
|
|
.. "'algorithm' must be one of: myers, minimal, patience, histogram: diffopt=algorithm:bad",
|
|
pcall_err(command, 'set diffopt=algorithm:bad')
|
|
)
|
|
eq(
|
|
"Vim(set):E474: 'filler' does not take a value: diffopt=filler:1",
|
|
pcall_err(command, 'set diffopt=filler:1')
|
|
)
|
|
eq(
|
|
"Vim(set):E474: 'ver' number is out of range: mousescroll=ver:99999999999",
|
|
pcall_err(command, 'set mousescroll=ver:99999999999')
|
|
)
|
|
end)
|
|
|
|
-- Enum / flag-list options name the offending value and list the valid ones.
|
|
it('reports specific errors for enum and flag-list options', function()
|
|
eq(
|
|
"Vim(set):E474: Invalid value 'x', expected one of: single, double: ambiwidth=x",
|
|
pcall_err(command, 'set ambiwidth=x')
|
|
)
|
|
eq(
|
|
'Vim(set):E474: '
|
|
.. "Invalid value 'x', expected one of: yes, auto, no, breaksymlink, breakhardlink: backupcopy=x",
|
|
pcall_err(command, 'set backupcopy=x')
|
|
)
|
|
end)
|
|
end)
|