refactor(api): rename nvim_win_remove_ns

Problem:
nvim_win_remove_ns does not follow `help dev-naming` API naming conventions.

Solution:
Rename it.
This commit is contained in:
Justin M. Keyes 2024-04-20 23:21:08 +02:00
parent 783b0aba41
commit 4b34ae4ce3
7 changed files with 97 additions and 48 deletions

View File

@ -2833,16 +2833,7 @@ nvim_win_add_ns({window}, {ns_id}) *nvim_win_add_ns()*
Return: ~
true if the namespace was added, else false
nvim_win_get_ns({window}) *nvim_win_get_ns()*
Gets all the namespaces scopes associated with a window.
Parameters: ~
• {window} Window handle, or 0 for current window
Return: ~
a list of namespaces ids
nvim_win_remove_ns({window}, {ns_id}) *nvim_win_remove_ns()*
nvim_win_del_ns({window}, {ns_id}) *nvim_win_del_ns()*
Removes the namespace scope from the window.
Parameters: ~
@ -2852,6 +2843,15 @@ nvim_win_remove_ns({window}, {ns_id}) *nvim_win_remove_ns()*
Return: ~
true if the namespace was removed, else false
nvim_win_get_ns({window}) *nvim_win_get_ns()*
Gets all the namespaces scopes associated with a window.
Parameters: ~
• {window} Window handle, or 0 for current window
Return: ~
a list of namespaces ids
==============================================================================
Window Functions *api-window*

View File

@ -375,7 +375,7 @@ Use existing common {verb} names (actions) if possible:
- enable: Enables/disables functionality. Signature should be
`enable(enable?:boolean, filter?:table)`.
- eval: Evaluates an expression
- exec: Executes code
- exec: Executes code, may return a result
- fmt: Formats
- get: Gets things (often by a query)
- inspect: Presents a high-level, often interactive, view
@ -393,8 +393,8 @@ Do NOT use these deprecated verbs:
- show: Redundant with "print", "echo"
- toggle: Prefer `enable(not is_enabled())`.
Use consistent names for {noun} (nouns) in API functions: buffer is called
"buf" everywhere, not "buffer" in some places and "buf" in others.
Use consistent names for {topic} in API functions: buffer is called "buf"
everywhere, not "buffer" in some places and "buf" in others.
- buf: Buffer
- chan: |channel|
- cmd: Command
@ -407,10 +407,10 @@ Use consistent names for {noun} (nouns) in API functions: buffer is called
- win: Window
Do NOT use these deprecated nouns:
- buffer
- buffer Use "buf" instead
- callback Use on_foo instead
- command
- window
- command Use "cmd" instead
- window Use "win" instead
*dev-name-events*
Use the "on_" prefix to name event-handling callbacks and also the interface for
@ -428,12 +428,13 @@ Example: >
<
*dev-name-api*
Use this format to name new RPC |API| functions: >
nvim_{noun}_{verb}_{arbitrary-qualifiers}
nvim_{topic}_{verb}_{arbitrary-qualifiers}
If the function acts on an object then {noun} is the name of that object
(e.g. "buf" or "win"). If the function operates in a "global" context then
{noun} is usually omitted (but consider "namespacing" your global operations
with a {noun} that groups functions under a common concept).
Do not add new nvim_buf/nvim_win/nvim_tabpage APIs, unless you are certain the
concept will NEVER be applied to more than one "scope". That is, {topic}
should be the TOPIC ("ns", "extmark", "option", …) that acts on the scope(s)
(buf/win/tabpage/global), it should NOT be the scope. The scope should be
a parameter.
- Example: `nvim_get_keymap('v')` operates in a global context (first
parameter is not a Buffer). The "get" verb indicates that it gets anything
@ -443,6 +444,59 @@ with a {noun} that groups functions under a common concept).
and uses the "del" {verb}.
INTERFACE PATTERNS *dev-patterns*
Prefer adding a single `nvim_{topic}_{verb}_…` interface for a given topic.
Example: >
nvim_ns_add(
ns_id: int,
filter: {
handle: integer (buf/win/tabpage id)
scope: "global" | "win" | "buf" | "tabpage"
}
): { ok: boolean }
nvim_ns_get(
ns_id: int,
filter: {
handle: integer (buf/win/tabpage id)
scope: "global" | "win" | "buf" | "tabpage"
}
): { ids: int[] }
nvim_ns_del(
ns_id: int,
filter: {
handle: integer (buf/win/tabpage id)
scope: "global" | "win" | "buf" | "tabpage"
}
): { ok: boolean }
Anti-Example:
Creating separate `nvim_xx`, `nvim_buf_xx`, `nvim_win_xx`, and
`nvim_tabpage_xx`, functions all for the same `xx` topic, requires 4x the
amount of documentation, boilerplate, and function interfaces. Thus the
following is generally NOT recommended (compare these 12(!) functions to the
above 3 functions! All of these require separate docs, which users must read,
maintainers must maintain, ...): >
nvim_add_ns(…)
nvim_buf_add_ns(…)
nvim_win_add_ns(…)
nvim_tabpage_add_ns(…)
nvim_del_ns(…)
nvim_buf_del_ns(…)
nvim_win_del_ns(…)
nvim_tabpage_del_ns(…)
nvim_get_ns(…)
nvim_buf_get_ns(…)
nvim_win_get_ns(…)
nvim_tabpage_get_ns(…)
API-CLIENT *dev-api-client*
*api-client*

View File

@ -183,7 +183,17 @@ The following new APIs and features were added.
• |'smoothscroll'| option to scroll by screen line rather than by text line
when |'wrap'| is set.
• |nvim_buf_set_extmark()| supports inline virtual text.
• API enhancements
• |nvim_buf_set_extmark()| supports inline virtual text.
• |nvim_win_text_height()| computes the number of screen lines occupied
by a range of text in a given window.
• New RPC client type `msgpack-rpc` is added for |nvim_set_client_info()| to
support fully MessagePack-RPC compliant clients.
• Floating windows can now be hidden by setting `hide` in |nvim_open_win()| or
|nvim_win_set_config()|.
• |nvim_input_mouse()| supports mouse buttons "x1" and "x2".
• Added |nvim_tabpage_set_win()| to set the current window of a tabpage.
• |namespace| can now have window scopes. |nvim_ns_add()|
• 'foldtext' now supports virtual text format. |fold-foldtext|
@ -195,9 +205,6 @@ The following new APIs and features were added.
• |vim.lpeg| and |vim.re| expose the bundled Lpeg expression grammar parser
and its regex interface.
• |nvim_win_text_height()| computes the number of screen lines occupied
by a range of text in a given window.
• Mapping APIs now support abbreviations when mode short-name has suffix "a".
• Better cmdline completion for string option value. |complete-set-option|
@ -291,15 +298,9 @@ The following new APIs and features were added.
• Functions that take a severity as an optional parameter (e.g.
|vim.diagnostic.get()|) now also accept a list of severities |vim.diagnostic.severity|
• New RPC client type `msgpack-rpc` is added for |nvim_set_client_info()| to
support fully MessagePack-RPC compliant clients.
• Floating windows can now show footer with new `footer` and `footer_pos`
config fields. Uses |hl-FloatFooter| by default.
• Floating windows can now be hidden by setting `hide` in |nvim_open_win()| or
|nvim_win_set_config()|.
• |:terminal| command now accepts some |:command-modifiers| (specifically
|:horizontal| and those that affect splitting a window).
@ -330,8 +331,6 @@ The following new APIs and features were added.
• 'completeopt' option supports "popup" flag to show extra information in a
floating window.
• |nvim_input_mouse()| supports mouse buttons "x1" and "x2".
• |v_Q-default| and |v_@-default| repeat a register for each line of a linewise
visual selection.
@ -355,12 +354,8 @@ The following new APIs and features were added.
highlight attribute. The TUI will display URLs using the OSC 8 control
sequence, enabling clickable text in supporting terminals.
• Added |nvim_tabpage_set_win()| to set the current window of a tabpage.
• Clicking on a tabpage in the tabline with the middle mouse button closes it.
• |namespace| can now have window scopes. |nvim_win_add_ns()|
• |extmarks| option `scoped`: only show the extmarks in its namespace's scope.
• Added built-in |commenting| support.

View File

@ -2114,6 +2114,13 @@ function vim.api.nvim_win_call(window, fun) end
--- hidden, even if 'hidden' is not set.
function vim.api.nvim_win_close(window, force) end
--- Removes the namespace scope from the window.
---
--- @param window integer Window handle, or 0 for current window
--- @param ns_id integer the namespace to remove
--- @return boolean
function vim.api.nvim_win_del_ns(window, ns_id) end
--- Removes a window-scoped (w:) variable
---
--- @param window integer Window handle, or 0 for current window
@ -2209,13 +2216,6 @@ function vim.api.nvim_win_hide(window) end
--- @return boolean
function vim.api.nvim_win_is_valid(window) end
--- Removes the namespace scope from the window.
---
--- @param window integer Window handle, or 0 for current window
--- @param ns_id integer the namespace to remove
--- @return boolean
function vim.api.nvim_win_remove_ns(window, ns_id) end
--- Sets the current buffer in a window, without side effects
---
--- @param window integer Window handle, or 0 for current window

View File

@ -158,7 +158,7 @@ function M.on_yank(opts)
yank_timer = nil
yank_cancel = nil
pcall(vim.api.nvim_buf_clear_namespace, bufnr, yank_ns, 0, -1)
pcall(vim.api.nvim_win_remove_ns, winid, yank_ns)
pcall(vim.api.nvim_win_del_ns, winid, yank_ns)
end
yank_timer = vim.defer_fn(yank_cancel, timeout)

View File

@ -1277,7 +1277,7 @@ ArrayOf(Integer) nvim_win_get_ns(Window window, Arena *arena, Error *err)
/// @param window Window handle, or 0 for current window
/// @param ns_id the namespace to remove
/// @return true if the namespace was removed, else false
Boolean nvim_win_remove_ns(Window window, Integer ns_id, Error *err)
Boolean nvim_win_del_ns(Window window, Integer ns_id, Error *err)
FUNC_API_SINCE(12)
{
win_T *win = find_window_by_handle(window, err);

View File

@ -5741,7 +5741,7 @@ describe('decorations: window scoped', function()
|
]]}
api.nvim_win_remove_ns(0, ns)
api.nvim_win_del_ns(0, ns)
screen:expect(noextmarks)
end)
@ -5946,7 +5946,7 @@ describe('decorations: window scoped', function()
|
]]}
eq(true, api.nvim_win_remove_ns(0, ns))
eq(true, api.nvim_win_del_ns(0, ns))
eq({}, api.nvim_win_get_ns(0))
screen:expect(noextmarks)