Remove old statusline implementation with new one.

This commit is contained in:
Kristijan Husak
2020-10-09 19:08:44 +02:00
committed by Kiyan Yazdani
parent 62df1143da
commit 3aa7e575e2
3 changed files with 8 additions and 43 deletions

View File

@@ -1,9 +1,5 @@
function! nvim_treesitter#statusline(len) abort
return luaeval("require'nvim-treesitter'.statusline(_A)", a:len)
endfunction
function! nvim_treesitter#named_statusline(...) abort
return luaeval("require'nvim-treesitter'.named_statusline(_A)", get(a:, 1, {}))
function! nvim_treesitter#statusline(...) abort
return luaeval("require'nvim-treesitter'.statusline(_A)", get(a:, 1, {}))
endfunction
function! nvim_treesitter#foldexpr() abort

View File

@@ -415,16 +415,8 @@ to the jump list.
==============================================================================
FUNCTIONS *nvim-treesitter-functions*
*nvim_treesitter#statusline()*
nvim_treesitter#statusline(size)~
Returns a string describing the current position in the syntax tree. This
could be used as a statusline indicator.
Note: The `size` argument is optional. When specified, the string will not be
longer than `size`.
*nvim_treesitter#named_statusline()*
nvim_treesitter#named_statusline(opts)~
*nvim_treesitter#statusline()*
nvim_treesitter#statusline(opts)~
Returns a string describing the current position in the file. This
could be used as a statusline indicator.

View File

@@ -27,32 +27,6 @@ function M.define_modules(...)
configs.define_modules(...)
end
function M.statusline(indicator_size)
if not parsers.has_parser() then return end
local indicator_size = indicator_size or 100
local current_node = ts_utils.get_node_at_cursor()
if not current_node then return "" end
local expr = current_node:parent()
local prefix = ""
if expr then
prefix = "->"
end
local indicator = current_node:type()
while expr and (#indicator + #(expr:type()) + 5) < indicator_size do
indicator = expr:type() .. prefix .. indicator
expr = expr:parent()
end
if expr then
return "..." .. indicator
else
return indicator
end
end
local get_line_for_node = function(node, type_patterns, transform_fn)
local node_type = node:type()
local is_valid = false
@@ -74,9 +48,12 @@ local transform_line = function(line)
return line:gsub('[%[%(%{]*%s*$', '')
end
function M.named_statusline(opts)
function M.statusline(opts)
if not parsers.has_parser() then return end
local options = opts or {}
if type(opts) == 'number' then
options = {indicator_size = opts}
end
local indicator_size = options.indicator_size or 100
local type_patterns = options.type_patterns or {'class', 'function', 'method'}
local transform_fn = options.transform_fn or transform_line