๐Ÿ’ YAML toolkit for Neovim users

Adds support for Snacks's picker

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