Skip to content

Commit

Permalink
feat(quarto.lua): introduce Chunk class to encapsulate code chunk pro…
Browse files Browse the repository at this point in the history
…perties and improve code organization
  • Loading branch information
PMassicotte committed Mar 3, 2025
1 parent 5e4402b commit e8ce22d
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions lua/r/quarto.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
local M = {}

local Chunk = {}
Chunk.__index = Chunk

--- Constructor for the Chunk class
---@param content string The content of the code chunk.
---@param start_row integer The starting row of the code chunk.
---@param end_row integer The ending row of the code chunk.
---@param info_string_params table The parameters specified in the info string of the code chunk.
---@param comment_params table The parameters specified in the code chunk with #|
---@param lang string The language of the code chunk.
---@return table
function Chunk:new(content, start_row, end_row, info_string_params, comment_params, lang)
local chunk = {
content = content,
start_row = start_row,
end_row = end_row,
info_string_params = info_string_params,
comment_params = comment_params,
lang = lang,
}

setmetatable(chunk, Chunk)

return chunk
end

M.command = function(what)
local config = require("r.config").get_config()
local send_cmd = require("r.send").cmd
Expand Down Expand Up @@ -63,14 +89,16 @@ local get_code_chunks = function(bufnr)
local comment_params =
M.parse_code_chunk_params(vim.treesitter.get_node_text(node, bufnr))

table.insert(code_chunks, {
content = vim.treesitter.get_node_text(node, bufnr),
start_row = start_row,
end_row = end_row,
info_string_params = info_string_params,
comment_params = comment_params,
lang = lang,
})
local chunk = Chunk:new(
vim.treesitter.get_node_text(node, bufnr),
start_row,
end_row,
info_string_params,
comment_params,
lang
)

table.insert(code_chunks, chunk)
end
end

Expand Down

0 comments on commit e8ce22d

Please sign in to comment.