|
1 | 1 | local M = {}
|
2 | 2 |
|
| 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 | + |
3 | 29 | M.command = function(what)
|
4 | 30 | local config = require("r.config").get_config()
|
5 | 31 | local send_cmd = require("r.send").cmd
|
@@ -63,14 +89,16 @@ local get_code_chunks = function(bufnr)
|
63 | 89 | local comment_params =
|
64 | 90 | M.parse_code_chunk_params(vim.treesitter.get_node_text(node, bufnr))
|
65 | 91 |
|
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) |
74 | 102 | end
|
75 | 103 | end
|
76 | 104 |
|
|
0 commit comments