๐Ÿ’ YAML toolkit for Neovim users

Refactors: replaces assure_yaml_filetype by get_current_yaml_node

authored by

Eduardo Cuducos and committed by
Joshua Cold
c175904d cce3c5a8

+27 -20
+27 -20
lua/yaml_nvim/init.lua
··· 21 21 end 22 22 end 23 23 24 - local assure_yaml_filetype = function(func, ...) 24 + local get_current_yaml_node = function() 25 25 local restore_to = set_yaml_as_filetype() 26 26 27 - func(...) 27 + local node = document.get_key_relevant_to_cursor() 28 + if node == nil then 29 + return 30 + end 31 + local parsed = pair.parse(node) 28 32 29 33 restore_filetype(restore_to) 34 + 35 + return parsed 30 36 end 31 37 32 - local yank = function(key, value, register) 33 - register = register or [["]] 34 - if not key and not value then 38 + local yank = function(node, key, value, register) 39 + if node == nil then 35 40 return 36 41 end 37 42 38 - local node = document.get_key_relevant_to_cursor() 39 - if node == nil then 43 + register = register or [["]] 44 + if not key and not value then 40 45 return 41 46 end 42 47 43 - local parsed = pair.parse(node) 44 48 local contents = "" 45 49 if key and value then 46 - contents = parsed.human 50 + contents = node.human 47 51 elseif key then 48 - contents = parsed.key 52 + contents = node.key 49 53 elseif value then 50 - contents = parsed.cleaned_value 54 + contents = node.cleaned_value 51 55 end 52 56 53 57 contents = string.gsub(contents, "'", "''") ··· 57 61 end 58 62 59 63 M.view = function() 60 - vim.notify(M.get_yaml_key_and_value()) 64 + local node = get_current_yaml_node() 65 + if node == nil then 66 + return 67 + end 68 + 69 + vim.notify(node.human) 61 70 end 62 71 63 72 M.get_yaml_key_and_value = function() 64 - local restore_to = set_yaml_as_filetype() 65 - local node = document.get_key_relevant_to_cursor() 73 + local node = get_current_yaml_node() 66 74 if node == nil then 67 75 return 68 76 end 69 - local parsed = pair.parse(node) 70 - restore_filetype(restore_to) 71 - return parsed.human 77 + 78 + return node.human 72 79 end 73 80 74 81 M.get_yaml_key = function() ··· 83 90 end 84 91 85 92 M.yank = function(register) 86 - assure_yaml_filetype(yank, true, true, register) 93 + yank(get_current_yaml_node(), true, true, register) 87 94 end 88 95 89 96 M.yank_key = function(register) 90 - assure_yaml_filetype(yank, true, false, register) 97 + yank(get_current_yaml_node(), true, false, register) 91 98 end 92 99 93 100 M.yank_value = function(register) 94 - assure_yaml_filetype(yank, false, true, register) 101 + yank(get_current_yaml_node(), false, true, register) 95 102 end 96 103 97 104 M.quickfix = function()