๐Ÿ’ YAML toolkit for Neovim users

Adds support for Snacks's picker

+43 -8
+5 -2
README.md
··· 11 11 | `:YAMLYankKey [register]` | `yaml.yank_key([register])` | Yanks the full path of the key for the current key/value pair. The default register is the unnamed one (`"`) | 12 12 | `:YAMLYankValue [register]` | `yaml.yank_value([register])` | Yanks the value of the current key/value pair. The default register is the unnamed one (`"`) | 13 13 | `:YAMLQuickfix` | `yaml.quickfix()` | Generates a quickfix with key/value pairs | 14 + | `:YAMLSnacks` | `yaml.snacks()` | Full path key/value fuzzy finder via [Snacks](https://github.com/folke/snacks.nvim) **if installed** | 14 15 | `:YAMLTelescope` | `yaml.telescope()` | Full path key/value fuzzy finder via [Telescope](https://github.com/nvim-telescope/telescope.nvim) **if installed** | 15 16 16 17 ![Example GIF](doc/demo.gif) ··· 20 21 * **Neovim 0.9** or newer 21 22 * [`nvim-treesitter`](https://github.com/nvim-treesitter/nvim-treesitter) with [YAML support](https://github.com/ikatyang/tree-sitter-yaml) 22 23 23 - Telescope is **optional**. 24 + Snacks and Telescope are **optional**. 24 25 25 26 <details> 26 27 ··· 41 42 ft = { "yaml" }, -- optional 42 43 dependencies = { 43 44 "nvim-treesitter/nvim-treesitter", 45 + "folke/snacks.nvim", -- optional 44 46 "nvim-telescope/telescope.nvim", -- optional 45 47 }, 46 48 } 47 49 ``` 48 50 49 - 50 51 ### With [`packer.nvim`](https://github.com/wbthomason/packer.nvim): 51 52 52 53 ```lua ··· 55 56 ft = { "yaml" }, -- optional 56 57 requires = { 57 58 "nvim-treesitter/nvim-treesitter", 59 + "folke/snacks.nvim", -- optional 58 60 "nvim-telescope/telescope.nvim" -- optional 59 61 }, 60 62 } ··· 63 65 ### With [`vim-plug`](https://github.com/junegunn/vim-plug): 64 66 65 67 ```viml 68 + Plug 'folke/snacks.nvim' " optional 66 69 Plug 'nvim-telescope/telescope.nvim' " optional 67 70 Plug 'nvim-treesitter/nvim-treesitter' 68 71 Plug 'cuducos/yaml.nvim'
+6 -3
doc/help.txt
··· 3 3 ============================================================================== 4 4 USAGE INSTRUCTIONS *yaml.nvim-usage* 5 5 6 - This plugins offers the following commands and, if |:telescope.nvim| is 7 - available, an extension reached by `:Telescope yaml` to navigate through the 8 - YAML loaded in the current buffer. 6 + This plugins offers the following commands: 9 7 10 8 :YAMLView *:YAMLView* 11 9 ··· 44 42 collects all nested keys and outputs them as a dot-case string (e.g.: 45 43 `root.parent.child.key = value`). It uses Vim's native |:cex| function, so 46 44 the cursor is positioned in the first selection of the |:quickfix|. 45 + 46 + :YAMLSnacks *YAMLSnacks* 47 + 48 + Creates a |:quickfix| list as in |:YAMLQuickfix|, and loads it with 49 + |:Snacks.picker|. Only available if |:Snacks| is installed. 47 50 48 51 :YAMLTelescope *YAMLTelescope* 49 52
+14
lua/yaml_nvim/init.lua
··· 1 1 local has_telescope, _ = pcall(require, "telescope") 2 + local has_snacks, _ = pcall(require, "snacks") 2 3 local document = require("yaml_nvim.document") 3 4 local pair = require("yaml_nvim.pair") 4 5 ··· 163 164 require("telescope.builtin").quickfix() 164 165 end 165 166 167 + M.snacks = function() 168 + if not has_snacks then 169 + return 170 + end 171 + 172 + M.quickfix() 173 + require("snacks").picker.qflist() 174 + end 175 + 166 176 -- Commands 167 177 168 178 vim.cmd("command! YAMLView lua require('yaml_nvim').view()") ··· 173 183 174 184 if has_telescope then 175 185 vim.cmd("command! YAMLTelescope lua require('yaml_nvim').telescope()") 186 + end 187 + 188 + if has_snacks then 189 + vim.cmd("command! YAMLSnacks lua require('yaml_nvim').snacks()") 176 190 end 177 191 178 192 return M
+1 -1
lua/yaml_nvim/pair.lua
··· 108 108 quickfix = { 109 109 bufnr = bufnr, 110 110 col = col, 111 - lnum = line, 111 + lnum = line + 1, 112 112 text = human, 113 113 valid = 1, 114 114 },
+1
tests/init.lua
··· 17 17 18 18 local dependencies = { 19 19 "nvim-lua/plenary.nvim", 20 + "folke/snacks.nvim", 20 21 "nvim-treesitter/nvim-treesitter", 21 22 "nvim-telescope/telescope.nvim", 22 23 }
+6
tests/yaml_nvim/commands_spec.lua
··· 57 57 assert.stub(qf).was_called_with() 58 58 end) 59 59 60 + it("YAMLSnacks calls Lua function", function() 61 + local snacks = stub(require("yaml_nvim"), "snacks") 62 + vim.cmd("YAMLSnacks") 63 + assert.stub(snacks).was_called_with() 64 + end) 65 + 60 66 it("YAMLTelescope calls Lua function", function() 61 67 local telescope = stub(require("yaml_nvim"), "telescope") 62 68 vim.cmd("YAMLTelescope")
+10 -2
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() 61 + stub(vim.fn, "setqflist") 62 + local snacks = require("snacks") 63 + local qflist = spy.on(snacks.picker, "qflist") 64 + require("yaml_nvim").snacks() 65 + assert.spy(qflist).was.called() 66 + end) 67 + 60 68 it("telescope calls Telescope's native quickfix function", function() 61 69 stub(vim.fn, "setqflist") 62 70 local telescope = spy.on(require("telescope.builtin"), "quickfix") ··· 85 93 { 86 94 bufnr = bufnr, 87 95 col = 0, 88 - lnum = 0, 96 + lnum = 1, 89 97 text = "answer = 42", 90 98 valid = 1, 91 99 }, 92 100 { 93 101 bufnr = bufnr, 94 102 col = 0, 95 - lnum = 1, 103 + lnum = 2, 96 104 text = "question = null", 97 105 valid = 1, 98 106 },