diff options
| author | Kiyan Yazdani <yazdani.kiyan@protonmail.com> | 2020-05-12 16:20:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-12 16:20:13 +0200 |
| commit | 5a66c38b9ff49f0f0b45afa95816c77e18cc9886 (patch) | |
| tree | 542e99206f53df84efa75edd303c6a2f41b98fd9 /lua/nvim-treesitter.lua | |
| parent | Merge pull request #51 from TravonteD/ruby-update (diff) | |
| parent | refacto/feat: better handling of parser updates (diff) | |
| download | nvim-treesitter-5a66c38b9ff49f0f0b45afa95816c77e18cc9886.tar nvim-treesitter-5a66c38b9ff49f0f0b45afa95816c77e18cc9886.tar.gz nvim-treesitter-5a66c38b9ff49f0f0b45afa95816c77e18cc9886.tar.bz2 nvim-treesitter-5a66c38b9ff49f0f0b45afa95816c77e18cc9886.tar.lz nvim-treesitter-5a66c38b9ff49f0f0b45afa95816c77e18cc9886.tar.xz nvim-treesitter-5a66c38b9ff49f0f0b45afa95816c77e18cc9886.tar.zst nvim-treesitter-5a66c38b9ff49f0f0b45afa95816c77e18cc9886.zip | |
Merge pull request #45 from kyazdani42/refacto-feat/buf-state-update
refacto/feat: better handling of parser updates
Diffstat (limited to 'lua/nvim-treesitter.lua')
| -rw-r--r-- | lua/nvim-treesitter.lua | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index 90b5468a3..5c0dfac75 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -1,15 +1,14 @@ local api = vim.api + local install = require'nvim-treesitter.install' -local locals = require'nvim-treesitter.locals' local utils = require'nvim-treesitter.utils' local info = require'nvim-treesitter.info' local configs = require'nvim-treesitter.configs' +local state = require'nvim-treesitter.state' local M = {} --- This function sets up everythin needed for a given language --- this is the main interface through the plugin -function M.setup(lang) +function M.setup() utils.setup_commands('install', install.commands) utils.setup_commands('info', info.commands) utils.setup_commands('configs', configs.commands) @@ -18,33 +17,34 @@ function M.setup(lang) for _, mod in pairs(configs.available_modules()) do if configs.is_enabled(mod, ft) then local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod) - api.nvim_command(string.format("autocmd FileType %s %s", ft, cmd)) + api.nvim_command(string.format("autocmd NvimTreesitter FileType %s %s", ft, cmd)) end end + local cmd = string.format("lua require'nvim-treesitter.state'.attach_to_buffer(%s)", ft) + api.nvim_command(string.format('autocmd NvimTreesitter FileType %s %s', ft, cmd)) end + + state.run_update() end function M.statusline(indicator_size) - local indicator_size = indicator_size or 1000 - local expr = require"nvim-treesitter.utils".expression_at_point() - local current_node = - require'nvim-treesitter.node_movement'.current_node[api.nvim_get_current_buf()] - - local indicator = "" - while expr and (#indicator + #(expr:type()) + 5) < indicator_size do - - local prefix = "" - if expr:parent() then - prefix = "->" - end + local indicator_size = indicator_size or 100 + local bufnr = api.nvim_get_current_buf() + local buf_state = state.get_buf_state(bufnr) + if not buf_state then return "" end + local current_node = buf_state.current_node + if not current_node then return "" end - if expr == current_node then - indicator = string.format("%s[%s]%s", prefix, expr:type(), indicator) - else - indicator = prefix .. expr:type() .. indicator - 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 |
