@@ -261,22 +261,27 @@ end
261
261
---
262
262
--- Note, this call invalidates the tree and requires it to be parsed again.
263
263
---
264
- --- @param regions A list of regions this tree should manage and parse.
264
+ --- @param regions ( table ) list of regions this tree should manage and parse.
265
265
function LanguageTree :set_included_regions (regions )
266
- -- TODO(vigoux): I don't think string parsers are useful for now
267
- if type (self ._source ) == ' number' then
268
- -- Transform the tables from 4 element long to 6 element long (with byte offset)
269
- for _ , region in ipairs (regions ) do
270
- for i , range in ipairs (region ) do
271
- if type (range ) == ' table' and # range == 4 then
272
- local start_row , start_col , end_row , end_col = unpack (range )
266
+ -- Transform the tables from 4 element long to 6 element long (with byte offset)
267
+ for _ , region in ipairs (regions ) do
268
+ for i , range in ipairs (region ) do
269
+ if type (range ) == ' table' and # range == 4 then
270
+ local start_row , start_col , end_row , end_col = unpack (range )
271
+ local start_byte = 0
272
+ local end_byte = 0
273
+ -- TODO(vigoux): proper byte computation here, and account for EOL ?
274
+ if type (self ._source ) == ' number' then
273
275
-- Easy case, this is a buffer parser
274
- -- TODO(vigoux): proper byte computation here, and account for EOL ?
275
- local start_byte = a .nvim_buf_get_offset (self ._source , start_row ) + start_col
276
- local end_byte = a .nvim_buf_get_offset (self ._source , end_row ) + end_col
277
-
278
- region [i ] = { start_row , start_col , start_byte , end_row , end_col , end_byte }
276
+ start_byte = a .nvim_buf_get_offset (self ._source , start_row ) + start_col
277
+ end_byte = a .nvim_buf_get_offset (self ._source , end_row ) + end_col
278
+ elseif type (self ._source ) == ' string' then
279
+ -- string parser, single `\n` delimited string
280
+ start_byte = vim .fn .byteidx (self ._source , start_col )
281
+ end_byte = vim .fn .byteidx (self ._source , end_col )
279
282
end
283
+
284
+ region [i ] = { start_row , start_col , start_byte , end_row , end_col , end_byte }
280
285
end
281
286
end
282
287
end
0 commit comments