Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Apr 19, 2022
1 parent 3874697 commit 4f97b70
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions lua/nvim_context_vt/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ local M = {}

-- This is from nvim-treesitter
function M.get_node_text(node, bufnr)
local bufnr = bufnr or vim.api.nvim_get_current_buf()
if not node then
return {}
end

local start_row, start_col, end_row, end_col = ts_utils.get_node_range(node)
if start_row ~= end_row then
local lines = vim.api.nvim_buf_get_lines(bufnr, start_row, end_row + 1, false)
lines[1] = string.sub(lines[1], start_col + 1)
if #lines == end_row - start_row + 1 then
lines[#lines] = string.sub(lines[#lines], 1, end_col)
local bufnr = bufnr or vim.api.nvim_get_current_buf()
if not node then
return {}
end
return lines
else
local line = vim.api.nvim_buf_get_lines(bufnr, start_row, start_row + 1, false)[1]
return line and { string.sub(line, start_col + 1, end_col) } or {}
end
end

local start_row, start_col, end_row, end_col = ts_utils.get_node_range(node)
if start_row ~= end_row then
local lines = vim.api.nvim_buf_get_lines(bufnr, start_row, end_row + 1, false)
lines[1] = string.sub(lines[1], start_col + 1)
if #lines == end_row - start_row + 1 then
lines[#lines] = string.sub(lines[#lines], 1, end_col)
end
return lines
else
local line = vim.api.nvim_buf_get_lines(bufnr, start_row, start_row + 1, false)[1]
return line and { string.sub(line, start_col + 1, end_col) } or {}
end
end

M.default_parser = function(node, _, opts)
return opts.prefix .. ' ' .. M.get_node_text(node, 0)[1]
Expand Down

0 comments on commit 4f97b70

Please sign in to comment.