aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorMichal Liszcz <liszcz.michal@gmail.com>2023-03-29 09:59:01 +0200
committerGitHub <noreply@github.com>2023-03-29 09:59:01 +0200
commitb7748662ed5b06c12a74560690b728fdf770666f (patch)
treefbade6571fddb65539b9d0ea3d8f62e1a8306915 /src/nvim/api
parenteac75a971d042bd610310314e6c64097694ee418 (diff)
downloadrneovim-b7748662ed5b06c12a74560690b728fdf770666f.tar.gz
rneovim-b7748662ed5b06c12a74560690b728fdf770666f.tar.bz2
rneovim-b7748662ed5b06c12a74560690b728fdf770666f.zip
fix(api): Use local LastSet structure in nvim_get_option_info (#22741)
fix(api): use local LastSet structure in nvim_get_option_info * nvim_get_option_info is deprecated. It is always using the global LastSet information as reported in #15232. * nvim_get_option_info2 is added. The new function additionally accepts an 'opts' table {scope, buf, win} allowing to specify the option scope and query local options from another buffer or window.
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/deprecated.c14
-rw-r--r--src/nvim/api/options.c33
2 files changed, 41 insertions, 6 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
index 6a12cfe2da..5937b2f635 100644
--- a/src/nvim/api/deprecated.c
+++ b/src/nvim/api/deprecated.c
@@ -20,6 +20,7 @@
#include "nvim/highlight_group.h"
#include "nvim/lua/executor.h"
#include "nvim/memory.h"
+#include "nvim/option.h"
#include "nvim/pos.h"
#include "nvim/types.h"
@@ -508,3 +509,16 @@ static int64_t convert_index(int64_t index)
{
return index < 0 ? index - 1 : index;
}
+
+/// Gets the option information for one option
+///
+/// @deprecated Use @ref nvim_get_option_info2 instead.
+///
+/// @param name Option name
+/// @param[out] err Error details, if any
+/// @return Option Information
+Dictionary nvim_get_option_info(String name, Error *err)
+ FUNC_API_SINCE(7)
+{
+ return get_vimoption(name, OPT_GLOBAL, curbuf, curwin, err);
+}
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 7a453c01b4..31a2fb3b80 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -283,7 +283,7 @@ void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict(
/// Gets the option information for all options.
///
/// The dictionary has the full option names as keys and option metadata
-/// dictionaries as detailed at |nvim_get_option_info()|.
+/// dictionaries as detailed at |nvim_get_option_info2()|.
///
/// @return dictionary of all options
Dictionary nvim_get_all_options_info(Error *err)
@@ -292,7 +292,7 @@ Dictionary nvim_get_all_options_info(Error *err)
return get_all_vimoptions();
}
-/// Gets the option information for one option
+/// Gets the option information for one option from arbitrary buffer or window
///
/// Resulting dictionary has keys:
/// - name: Name of the option (like 'filetype')
@@ -311,15 +311,36 @@ Dictionary nvim_get_all_options_info(Error *err)
/// - commalist: List of comma separated values
/// - flaglist: List of single char flags
///
+/// When {scope} is not provided, the last set information applies to the local
+/// value in the current buffer or window if it is available, otherwise the
+/// global value information is returned. This behavior can be disabled by
+/// explicitly specifying {scope} in the {opts} table.
///
-/// @param name Option name
+/// @param name Option name
+/// @param opts Optional parameters
+/// - scope: One of "global" or "local". Analogous to
+/// |:setglobal| and |:setlocal|, respectively.
+/// - win: |window-ID|. Used for getting window local options.
+/// - buf: Buffer number. Used for getting buffer local options.
+/// Implies {scope} is "local".
/// @param[out] err Error details, if any
/// @return Option Information
-Dictionary nvim_get_option_info(String name, Error *err)
- FUNC_API_SINCE(7)
+Dictionary nvim_get_option_info2(String name, Dict(option) *opts, Error *err)
+ FUNC_API_SINCE(11)
{
- return get_vimoption(name, err);
+ int scope = 0;
+ int opt_type = SREQ_GLOBAL;
+ void *from = NULL;
+ if (!validate_option_value_args(opts, &scope, &opt_type, &from, NULL, err)) {
+ return (Dictionary)ARRAY_DICT_INIT;
+ }
+
+ buf_T *buf = (opt_type == SREQ_BUF) ? (buf_T *)from : curbuf;
+ win_T *win = (opt_type == SREQ_WIN) ? (win_T *)from : curwin;
+
+ return get_vimoption(name, scope, buf, win, err);
}
+
/// Sets the global value of an option.
///
/// @param channel_id