aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators/gen_options.lua
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2024-11-04 19:00:12 +0600
committerGitHub <noreply@github.com>2024-11-04 05:00:12 -0800
commita27419f3fc540f66567f4559a796cd6758f1bb1f (patch)
treeff8d1f00c01bb391facba5d239a58eb5aa07eb44 /src/nvim/generators/gen_options.lua
parent04d178053fee7be92c8a7634a1acfe373c758638 (diff)
downloadrneovim-a27419f3fc540f66567f4559a796cd6758f1bb1f.tar.gz
rneovim-a27419f3fc540f66567f4559a796cd6758f1bb1f.tar.bz2
rneovim-a27419f3fc540f66567f4559a796cd6758f1bb1f.zip
feat(options)!: disallow setting hidden options #28400
Problem: There are three different ways of marking an option as hidden, `enable_if = false`, `hidden = true` and `immutable = true`. These also have different behaviors. Options hidden with `enable_if = false` can't have their value fetched using Vim script or the API, but options hidden with `hidden = true` or `immutable = true` can. On the other hand, options with `hidden = true` do not error when trying to set their value, but options with `immutable = true` do. Solution: Remove `enable_if = false`, remove the `hidden` property for options, and use `immutable = true` to mark an option as hidden instead. Also make hidden option variable pointers always point to the default value, which allows fetching the value of every hidden option using Vim script and the API. This does also mean that trying to set a hidden option will now give an error instead of just being ignored.
Diffstat (limited to 'src/nvim/generators/gen_options.lua')
-rw-r--r--src/nvim/generators/gen_options.lua19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua
index 8397a434e4..92349b5298 100644
--- a/src/nvim/generators/gen_options.lua
+++ b/src/nvim/generators/gen_options.lua
@@ -191,23 +191,17 @@ local function dump_option(i, o)
w(get_cond(o.enable_if))
end
- -- An option cannot be both hidden and immutable.
- assert(not o.hidden or not o.immutable)
-
- local has_var = true
if o.varname then
w(' .var=&' .. o.varname)
- elseif o.hidden or o.immutable then
- -- Hidden and immutable options can directly point to the default value.
+ elseif o.immutable then
+ -- Immutable options can directly point to the default value.
w((' .var=&options[%u].def_val.data'):format(i - 1))
elseif #o.scope == 1 and o.scope[1] == 'window' then
w(' .var=VAR_WIN')
else
- has_var = false
+ -- Option must be immutable or have a variable.
+ assert(false)
end
- -- `enable_if = false` should be present iff there is no variable.
- assert((o.enable_if == false) == not has_var)
- w(' .hidden=' .. (o.hidden and 'true' or 'false'))
w(' .immutable=' .. (o.immutable and 'true' or 'false'))
if #o.scope == 1 and o.scope[1] == 'global' then
w(' .indir=PV_NONE')
@@ -237,7 +231,10 @@ local function dump_option(i, o)
end
if o.enable_if then
w('#else')
- w(' .var=NULL')
+ -- Hidden option directly points to default value.
+ w((' .var=&options[%u].def_val.data'):format(i - 1))
+ -- Option is always immutable on the false branch of `enable_if`.
+ w(' .immutable=true')
w(' .indir=PV_NONE')
w('#endif')
end