Skip to content

Commit

Permalink
Add safety to get_value, is_sequence_block on nil values
Browse files Browse the repository at this point in the history
Support for returning an empty value instead of crashing when the value
is nil

This helps when working on in-progress yaml files while the winbar is
activated
  • Loading branch information
joshzcold committed Nov 9, 2023
1 parent 15c4cc1 commit 46024a0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lua/yaml_nvim/pair.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,26 @@ end
local function get_value(node, bufnr)
while node ~= nil do
if node:type() == "block_mapping_pair" then
local value = node:field("value")[1]
return table.concat({ vim.treesitter.get_node_text(value, bufnr) }, "\n")
if node:field("value")[1] ~= nil then
local value = node:field("value")[1]
return table.concat({ vim.treesitter.get_node_text(value, bufnr) }, "\n")
end
end

node = node:parent()
end
end

local function is_sequence_block(value)
if value:type() ~= "block_node" then
return false
end
if value then
if value:type() ~= "block_node" then
return false
end

for block_sequence, _ in value:iter_children() do
return block_sequence:type() == "block_sequence"
for block_sequence, _ in value:iter_children() do
return block_sequence:type() == "block_sequence"
end
else
return false
end
end

Expand Down

0 comments on commit 46024a0

Please sign in to comment.