๐Ÿ’ YAML toolkit for Neovim users

Adds support for fzf-lua

Fixes #32

+50 -12
+5 -1
README.md
··· 13 13 | `:YAMLQuickfix` | `yaml.quickfix()` | Generates a quickfix with key/value pairs | 14 14 | `:YAMLSnacks` | `yaml.snacks()` | Full path key/value fuzzy finder via [Snacks](https://github.com/folke/snacks.nvim) **if installed** | 15 15 | `:YAMLTelescope` | `yaml.telescope()` | Full path key/value fuzzy finder via [Telescope](https://github.com/nvim-telescope/telescope.nvim) **if installed** | 16 + | `:YAMLFzfLua` | `yaml.fzf_lua()` | Full path key/value fuzzy finder via [fzf-lua](https://github.com/ibhagwan/fzf-lua) **if installed** | 16 17 17 18 ![Example GIF](doc/demo.gif) 18 19 ··· 21 22 * **Neovim 0.9** or newer 22 23 * [`nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter) with [YAML support](https://github.com/ikatyang/tree-sitter-yaml) 23 24 24 - Snacks and Telescope are **optional**. 25 + Snacks, Telescope and fzf-lua are **optional**. 25 26 26 27 <details> 27 28 ··· 44 45 "nvim-treesitter/nvim-treesitter", 45 46 "folke/snacks.nvim", -- optional 46 47 "nvim-telescope/telescope.nvim", -- optional 48 + "ibhagwan/fzf-lua" -- optional 47 49 }, 48 50 } 49 51 ``` ··· 58 60 "nvim-treesitter/nvim-treesitter", 59 61 "folke/snacks.nvim", -- optional 60 62 "nvim-telescope/telescope.nvim" -- optional 63 + "ibhagwan/fzf-lua" --optional 61 64 }, 62 65 } 63 66 ``` ··· 67 70 ```viml 68 71 Plug 'folke/snacks.nvim' " optional 69 72 Plug 'nvim-telescope/telescope.nvim' " optional 73 + Plug 'ibhagwan/fzf-lua' " optional 70 74 Plug 'nvim-treesitter/nvim-treesitter' 71 75 Plug 'cuducos/yaml.nvim' 72 76 ```
+6
doc/help.txt
··· 53 53 Creates a |:quickfix| list as in |:YAMLQuickfix|, and loads it with 54 54 |:telescope.nvim| using |:telescope.builtin|'s `quickfix()` function. Only 55 55 available if |:telescope.nvim| is installed. 56 + 57 + :YAMLFzfLua *YAMLFzfLua* 58 + 59 + Creates a |:quickfix| list as in |:YAMLQuickfix|, and loads it with 60 + |:fzf-lua|'s `quickfix()` function. Only available if |:fzf-lua| is 61 + installed.
+22 -8
lua/yaml_nvim/init.lua
··· 1 - local has_telescope, _ = pcall(require, "telescope") 2 - local has_snacks, _ = pcall(require, "snacks") 1 + local has_snacks, snacks = pcall(require, "snacks") 2 + local has_telescope, telescope = pcall(require, "telescope.builtin") 3 + local has_fzf_lua, fzf_lua = pcall(require, "fzf-lua") 3 4 local document = require("yaml_nvim.document") 4 5 local pair = require("yaml_nvim.pair") 5 6 ··· 155 156 vim.fn.setqflist(lines) 156 157 end 157 158 159 + M.snacks = function() 160 + if not has_snacks then 161 + return 162 + end 163 + 164 + M.quickfix() 165 + snacks.picker.qflist() 166 + end 167 + 158 168 M.telescope = function() 159 169 if not has_telescope then 160 170 return 161 171 end 162 172 163 173 M.quickfix() 164 - require("telescope.builtin").quickfix() 174 + telescope.quickfix() 165 175 end 166 176 167 - M.snacks = function() 168 - if not has_snacks then 177 + M.fzf_lua = function() 178 + if not has_fzf_lua then 169 179 return 170 180 end 171 181 172 182 M.quickfix() 173 - require("snacks").picker.qflist() 183 + fzf_lua.quickfix() 174 184 end 175 185 176 186 -- Commands ··· 181 191 vim.cmd("command! -nargs=? YAMLYankValue lua require('yaml_nvim').yank_value(<f-args>)") 182 192 vim.cmd("command! YAMLQuickfix lua require('yaml_nvim').quickfix()") 183 193 194 + if has_snacks then 195 + vim.cmd("command! YAMLSnacks lua require('yaml_nvim').snacks()") 196 + end 197 + 184 198 if has_telescope then 185 199 vim.cmd("command! YAMLTelescope lua require('yaml_nvim').telescope()") 186 200 end 187 201 188 - if has_snacks then 189 - vim.cmd("command! YAMLSnacks lua require('yaml_nvim').snacks()") 202 + if has_fzf_lua then 203 + vim.cmd("command! YAMLFzfLua lua require('yaml_nvim').fzf_lua()") 190 204 end 191 205 192 206 return M
+3 -2
tests/init.lua
··· 16 16 end 17 17 18 18 local dependencies = { 19 + "folke/snacks.nvim", 20 + "ibhagwan/fzf-lua", 19 21 "nvim-lua/plenary.nvim", 20 - "folke/snacks.nvim", 22 + "nvim-telescope/telescope.nvim", 21 23 "nvim-treesitter/nvim-treesitter", 22 - "nvim-telescope/telescope.nvim", 23 24 } 24 25 for _, dep in pairs(dependencies) do 25 26 install_from_github(dep)
+6
tests/yaml_nvim/commands_spec.lua
··· 68 68 vim.cmd("YAMLTelescope") 69 69 assert.stub(telescope).was_called_with() 70 70 end) 71 + 72 + it("YAMLFzFLua calls Lua function", function() 73 + local fzf_lua = stub(require("yaml_nvim"), "fzf_lua") 74 + vim.cmd("YAMLFzfLua") 75 + assert.stub(fzf_lua).was_called_with() 76 + end) 71 77 end)
+8 -1
tests/yaml_nvim/functions_spec.lua
··· 57 57 assert.are.equal("7", vim.fn.getreg("7")) 58 58 end) 59 59 60 - it("snacks calls Snacks's native quickfix function", function() 60 + it("snacks calls Snacks's native qflist function", function() 61 61 stub(vim.fn, "setqflist") 62 62 local snacks = require("snacks") 63 63 local qflist = spy.on(snacks.picker, "qflist") ··· 70 70 local telescope = spy.on(require("telescope.builtin"), "quickfix") 71 71 require("yaml_nvim").telescope() 72 72 assert.spy(telescope).was.called() 73 + end) 74 + 75 + it("fzf_lua calls fzf-lua's native quickfix function", function() 76 + stub(vim.fn, "setqflist") 77 + local fzf_lua = spy.on(require("fzf-lua"), "quickfix") 78 + require("yaml_nvim").fzf_lua() 79 + assert.spy(fzf_lua).was.called() 73 80 end) 74 81 end) 75 82