Skip to content

Commit e8ce22d

Browse files
committed
feat(quarto.lua): introduce Chunk class to encapsulate code chunk properties and improve code organization
1 parent 5e4402b commit e8ce22d

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

lua/r/quarto.lua

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
local M = {}
22

3+
local Chunk = {}
4+
Chunk.__index = Chunk
5+
6+
--- Constructor for the Chunk class
7+
---@param content string The content of the code chunk.
8+
---@param start_row integer The starting row of the code chunk.
9+
---@param end_row integer The ending row of the code chunk.
10+
---@param info_string_params table The parameters specified in the info string of the code chunk.
11+
---@param comment_params table The parameters specified in the code chunk with #|
12+
---@param lang string The language of the code chunk.
13+
---@return table
14+
function Chunk:new(content, start_row, end_row, info_string_params, comment_params, lang)
15+
local chunk = {
16+
content = content,
17+
start_row = start_row,
18+
end_row = end_row,
19+
info_string_params = info_string_params,
20+
comment_params = comment_params,
21+
lang = lang,
22+
}
23+
24+
setmetatable(chunk, Chunk)
25+
26+
return chunk
27+
end
28+
329
M.command = function(what)
430
local config = require("r.config").get_config()
531
local send_cmd = require("r.send").cmd
@@ -63,14 +89,16 @@ local get_code_chunks = function(bufnr)
6389
local comment_params =
6490
M.parse_code_chunk_params(vim.treesitter.get_node_text(node, bufnr))
6591

66-
table.insert(code_chunks, {
67-
content = vim.treesitter.get_node_text(node, bufnr),
68-
start_row = start_row,
69-
end_row = end_row,
70-
info_string_params = info_string_params,
71-
comment_params = comment_params,
72-
lang = lang,
73-
})
92+
local chunk = Chunk:new(
93+
vim.treesitter.get_node_text(node, bufnr),
94+
start_row,
95+
end_row,
96+
info_string_params,
97+
comment_params,
98+
lang
99+
)
100+
101+
table.insert(code_chunks, chunk)
74102
end
75103
end
76104

0 commit comments

Comments
 (0)