Use utils get_node_text to get line content and trim all whitespaces.

This commit is contained in:
Kristijan Husak 2020-10-09 19:51:27 +02:00 committed by Kiyan Yazdani
parent 3aa7e575e2
commit 9ad47c65bd
2 changed files with 3 additions and 4 deletions

View file

@ -425,7 +425,7 @@ Default options (lua syntax):
{
indicator_size = 100,
type_patterns = {'class', 'function', 'method'},
transform_fn = function(line) return line:gsub('[%[%(%{]*%s*$', '') end,
transform_fn = function(line) return line:gsub('%s*[%[%(%{]*%s*$', '') end,
separator = ' -> '
}
<

View file

@ -37,15 +37,14 @@ local get_line_for_node = function(node, type_patterns, transform_fn)
end
end
if not is_valid then return '' end
local range = {node:range()}
local line = transform_fn(vim.trim(vim.fn.getline(range[1] + 1)))
local line = transform_fn(vim.trim(ts_utils.get_node_text(node)[1] or ''))
-- Escape % to avoid statusline to evaluate content as expression
return line:gsub('%%', '%%%%')
end
-- Trim spaces and opening brackets from end
local transform_line = function(line)
return line:gsub('[%[%(%{]*%s*$', '')
return line:gsub('%s*[%[%(%{]*%s*$', '')
end
function M.statusline(opts)