diff --git a/lua/regexplainer.lua b/lua/regexplainer.lua index 265bd93..79b6a83 100644 --- a/lua/regexplainer.lua +++ b/lua/regexplainer.lua @@ -4,8 +4,9 @@ local utils = require 'regexplainer.utils' local Buffers = require 'regexplainer.buffers' local defer = require 'regexplainer.utils.defer' -local get_node_text = vim.treesitter.get_node_text or vim.treesitter.query.get_node_text +local get_node_text = vim.treesitter.get_node_text local extend = vim.tbl_deep_extend +local buf_delete = vim.api.nvim_buf_delete local ag = vim.api.nvim_create_augroup local au = vim.api.nvim_create_autocmd @@ -102,14 +103,10 @@ local function show_for_real(options) renderer = require'regexplainer.renderers.debug' end - Buffers.render(buffer, - renderer, - components, - options, - { - full_regexp_text = get_node_text(node, scratchnr), - }) - vim.api.nvim_buf_delete(scratchnr, { force = true }) + local state = { full_regexp_text = get_node_text(node, scratchnr) } + + Buffers.render(buffer, renderer, components, options, state) + buf_delete(scratchnr, { force = true }) else Buffers.hide_all() end