-
-
Notifications
You must be signed in to change notification settings - Fork 628
feat: validate some option string values #2404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks, this greatly improves usability.
Now we need to refactor FIELD_OVERRIDE_TYPECHECK
and FIELD_SKIP_VALIDATE
to use this same table structure...
Tested:
sort.sorter
view.side
view.signcolumn
renderer.highlight_opened_files
renderer.highlight_modified
renderer.icons.git_placement
renderer.icons.diagnostics_placement
renderer.icons.modified_placement
Unfortunately, Neovim crashes if a multiline message is routed through Noice. See neovim/neovim#22919 (comment) I needed to run Is |
Sorry @przepompownia, but I think you posted the comment in the wrong place... |
@Akmadan23 please test some invalid config using such local configDir = vim.fn.expand('<sfile>:p:h')
vim.env['XDG_CONFIG_HOME'] = configDir
vim.env['XDG_DATA_HOME'] = configDir .. '/.xdg/data'
vim.env['XDG_STATE_HOME'] = configDir .. '/.xdg/state'
vim.env['XDG_CACHE_HOME'] = configDir .. '/.xdg/cache'
local stdPathConfig = vim.fn.stdpath('config')
vim.opt.runtimepath:prepend(stdPathConfig)
vim.opt.packpath:prepend(stdPathConfig)
local plugins_path = vim.fn.fnamemodify('plugins/', ':p')
for name, url in pairs {
['nvim-tree.lua'] = 'https://github.com/nvim-tree/nvim-tree.lua',
['nui'] = 'https://github.com/MunifTanjim/nui.nvim',
['noice.nvim'] = 'https://github.com/folke/noice.nvim',
} do
local install_path = plugins_path .. name
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
end
vim.opt.runtimepath:append(install_path)
end
require('noice').setup({})
require('nvim-tree').setup({
sort_by = 'foo',
renderer = 1,
}) with and without |
@przepompownia ok, now I see the issue. Since nvim-tree was not mentioned anywhere in the comment you linked I assumed it was unrelated. However the |
Right, this PR only revealed the problem - this line existed before but was not reached for me. |
@alex-courtis back to the topic...
Yeah, |
The newline was added in an attempt to ensure that startup messages are seen. #2385 (comment) It's an attempt to work around neovim/neovim#17832 Reverting that change. Thanks for bringing it up @przepompownia |
You're right I wouldn't be unhappy if you did refactor that one though ;) |
I almost already did it, just a question: Edit: never mind, I found out they are from |
@alex-courtis thanks for 94c7c81. Adding this validation increased the chance of crash Neovim process if the user has also Noice and some invalid option. In such case the user cannot see any validation error unless see it in headless mode. Finding where the bug lies is also not trivial. |
Yup. These ambiguous fields are the reason I'd like to exactly specify them.
I was thinking it could look like ACCEPTED_STRINGS - array rather than map of booleans. Something like local ACCEPTED_TYPES = {
view = {
width = { "string", "function", "number", "table" },
---
},
---
} |
Which validation is the one increasing the chance? Do you mean this new type checking validation specifically? Option validation and error notification has been around for years. Are you saying that it's just he newline that is a problem? |
Yes, I am indeed refactoring it following this structure, so the only solution I can think of is something like this local ACCEPTED_TYPES = {
view = {
width = { "string", "function", "number", "table",
min = { "string", "function", "number" },
max = { "string", "function", "number" },
},
},
-- ...
} |
From what I understood that seems to be the case, @przepompownia correct me if I'm wrong. |
For me, only the newline. More precisely, this change only increases the amount of cases that lead to crash Neovim in combination with the other conditions mentioned. I started using nvim-tree about 11 months ago. Some (currently invalid) config entries (like |
This can be useful to warn the user when a string value is not "accepted" in those cases where strings act like a sort of enum. I don't know if this can be considered a feature or something, let me know...