aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria José Solano <majosolano99@gmail.com>2024-04-29 13:45:53 -0700
committerGitHub <noreply@github.com>2024-04-29 13:45:53 -0700
commitbc7f86209d3961aa479a8caeb792a8d39de55ece (patch)
tree5a6415c31d2f5f0453ba15dce551240ea9f791b1
parenta1c9da2d5af002ec5e9eb5ac1c0c61fc12ec4190 (diff)
downloadrneovim-bc7f86209d3961aa479a8caeb792a8d39de55ece.tar.gz
rneovim-bc7f86209d3961aa479a8caeb792a8d39de55ece.tar.bz2
rneovim-bc7f86209d3961aa479a8caeb792a8d39de55ece.zip
fix(lsp): redundant vim.snippet.jumpable #28560
-rw-r--r--runtime/doc/lua.txt49
-rw-r--r--runtime/lua/vim/snippet.lua55
-rw-r--r--test/functional/lua/snippet_spec.lua4
3 files changed, 58 insertions, 50 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 51dcf99dd2..c5d656992c 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -4306,8 +4306,33 @@ Iter:totable() *Iter:totable()*
==============================================================================
Lua module: vim.snippet *vim.snippet*
-vim.snippet.active() *vim.snippet.active()*
- Returns `true` if there's an active snippet in the current buffer.
+*vim.snippet.ActiveFilter*
+
+ Fields: ~
+ • {direction} (`vim.snippet.Direction`) Navigation direction. -1 for
+ previous, 1 for next.
+
+
+vim.snippet.active({filter}) *vim.snippet.active()*
+ Returns `true` if there's an active snippet in the current buffer,
+ applying the given filter if provided.
+
+ You can use this function to navigate a snippet as follows: >lua
+ vim.keymap.set({ 'i', 's' }, '<Tab>', function()
+ if vim.snippet.active({ direction = 1 }) then
+ return '<cmd>lua vim.snippet.jump(1)<cr>'
+ else
+ return '<Tab>'
+ end
+ end, { expr = true })
+<
+
+ Parameters: ~
+ • {filter} (`vim.snippet.ActiveFilter?`) Filter to constrain the search
+ with:
+ • `direction` (vim.snippet.Direction): Navigation direction.
+ Will return `true` if the snippet can be jumped in the
+ given direction. See |vim.snippet.ActiveFilter|.
Return: ~
(`boolean`)
@@ -4343,26 +4368,6 @@ vim.snippet.jump({direction}) *vim.snippet.jump()*
• {direction} (`vim.snippet.Direction`) Navigation direction. -1 for
previous, 1 for next.
-vim.snippet.jumpable({direction}) *vim.snippet.jumpable()*
- Returns `true` if there is an active snippet which can be jumped in the
- given direction. You can use this function to navigate a snippet as
- follows: >lua
- vim.keymap.set({ 'i', 's' }, '<Tab>', function()
- if vim.snippet.jumpable(1) then
- return '<cmd>lua vim.snippet.jump(1)<cr>'
- else
- return '<Tab>'
- end
- end, { expr = true })
-<
-
- Parameters: ~
- • {direction} (`vim.snippet.Direction`) Navigation direction. -1 for
- previous, 1 for next.
-
- Return: ~
- (`boolean`)
-
==============================================================================
Lua module: vim.text *vim.text*
diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua
index 37416c389f..8447d08d17 100644
--- a/runtime/lua/vim/snippet.lua
+++ b/runtime/lua/vim/snippet.lua
@@ -532,29 +532,6 @@ end
--- @alias vim.snippet.Direction -1 | 1
---- Returns `true` if there is an active snippet which can be jumped in the given direction.
---- You can use this function to navigate a snippet as follows:
----
---- ```lua
---- vim.keymap.set({ 'i', 's' }, '<Tab>', function()
---- if vim.snippet.jumpable(1) then
---- return '<cmd>lua vim.snippet.jump(1)<cr>'
---- else
---- return '<Tab>'
---- end
---- end, { expr = true })
---- ```
----
---- @param direction (vim.snippet.Direction) Navigation direction. -1 for previous, 1 for next.
---- @return boolean
-function M.jumpable(direction)
- if not M.active() then
- return false
- end
-
- return M._session:get_dest_index(direction) ~= nil
-end
-
--- Jumps within the active snippet in the given direction.
--- If the jump isn't possible, the function call does nothing.
---
@@ -604,11 +581,37 @@ function M.jump(direction)
setup_autocmds(M._session.bufnr)
end
---- Returns `true` if there's an active snippet in the current buffer.
+--- @class vim.snippet.ActiveFilter
+--- @field direction vim.snippet.Direction Navigation direction. -1 for previous, 1 for next.
+
+--- Returns `true` if there's an active snippet in the current buffer,
+--- applying the given filter if provided.
+---
+--- You can use this function to navigate a snippet as follows:
---
+--- ```lua
+--- vim.keymap.set({ 'i', 's' }, '<Tab>', function()
+--- if vim.snippet.active({ direction = 1 }) then
+--- return '<cmd>lua vim.snippet.jump(1)<cr>'
+--- else
+--- return '<Tab>'
+--- end
+--- end, { expr = true })
+--- ```
+---
+--- @param filter? vim.snippet.ActiveFilter Filter to constrain the search with:
+--- - `direction` (vim.snippet.Direction): Navigation direction. Will return `true` if the snippet
+--- can be jumped in the given direction.
--- @return boolean
-function M.active()
- return M._session ~= nil and M._session.bufnr == vim.api.nvim_get_current_buf()
+function M.active(filter)
+ local active = M._session ~= nil and M._session.bufnr == vim.api.nvim_get_current_buf()
+
+ local in_direction = true
+ if active and filter and filter.direction then
+ in_direction = M._session:get_dest_index(filter.direction) ~= nil
+ end
+
+ return active and in_direction
end
--- Exits the current snippet.
diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua
index 83bd91bc71..413aa93994 100644
--- a/test/functional/lua/snippet_spec.lua
+++ b/test/functional/lua/snippet_spec.lua
@@ -97,9 +97,9 @@ describe('vim.snippet', function()
it('does not jump outside snippet range', function()
test_expand_success({ 'function $1($2)', ' $0', 'end' }, { 'function ()', ' ', 'end' })
- eq(false, exec_lua('return vim.snippet.jumpable(-1)'))
+ eq(false, exec_lua('return vim.snippet.active({ direction = -1 })'))
feed('<Tab><Tab>i')
- eq(false, exec_lua('return vim.snippet.jumpable(1)'))
+ eq(false, exec_lua('return vim.snippet.active( { direction = 1 })'))
end)
it('navigates backwards', function()