diff options
| author | Kristijan Husak <husakkristijan@gmail.com> | 2020-10-09 19:51:27 +0200 |
|---|---|---|
| committer | Kiyan Yazdani <yazdani.kiyan@protonmail.com> | 2020-10-11 13:35:18 +0200 |
| commit | 9ad47c65bd0b939173803c8a23c9cf0dc6cff70f (patch) | |
| tree | 4f9664a016f0f885dd7db5d5caeeef90102ef008 | |
| parent | 3aa7e575e23228477e16940d2bc786a52a142eb8 (diff) | |
Use utils get_node_text to get line content and trim all whitespaces.
| -rw-r--r-- | doc/nvim-treesitter.txt | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter.lua | 5 |
2 files changed, 3 insertions, 4 deletions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index c6ea4ed3..dee1ff8b 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -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 = ' -> ' } < diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index 1eb5276f..cd1b6850 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -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) |
