diff options
| author | kiyan42 <yazdani.kiyan@protonmail.com> | 2020-05-08 11:22:59 +0200 |
|---|---|---|
| committer | kiyan42 <yazdani.kiyan@protonmail.com> | 2020-05-12 16:16:48 +0200 |
| commit | 45dcebb15f1a954eba2bcb3ae4c1a03f710a1f2a (patch) | |
| tree | 50cbca8e9615d69a8ff9aca6b33a35abb32f9363 /lua/nvim-treesitter/configs.lua | |
| parent | 307c78aa1e2cc5e499469fe892108b7fcf6cdb5e (diff) | |
refacto/feat: better handling of parser updates
features:
- node_movement is moving between scopes.
- add selection initialization from normal mode
- add a decremental selection
improvements:
- attach to buffer to run tree parsing on change
- run state update on CursorMoved
- the buffer state is:
```
{
cursor_pos = { row=row, col=col },
current_node = node_under_cursor,
selection = {
range = nil, -- activates when starting a selection
nodes = {} -- filling up when starting an incremental selection
},
parser = parser, -- parser for current buffer
}
```
- refacto all the modules reliant on parsing the tree, update the current nodes, get the current nodes...
fixes:
- fix has_parser to look for .so libraries
- fix should select the whole file when selection root in selection
Diffstat (limited to 'lua/nvim-treesitter/configs.lua')
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index 9695da5a..31f01a72 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -1,6 +1,8 @@ local api = vim.api + local queries = require'nvim-treesitter.query' -local parser_utils = require'nvim-treesitter.parsers' +local utils = require'nvim-treesitter.utils' + local parsers = {} parsers.javascript = { @@ -218,28 +220,28 @@ local config = { enable = false, disable = {}, keymaps = { + init_selection="gnn", node_incremental="grn", - scope_incremental="grc" + scope_incremental="grc", + node_decremental="grm" }, - is_supported = function() return true end + is_supported = function(ft) + return queries.get_query(ft, 'locals') + end }, node_movement = { enable = false, disable = {}, - is_supported = function() return true end, + is_supported = function(ft) + return queries.get_query(ft, 'locals') + end, keymaps = { - move_up = "<a-k>", - move_down = "<a-j>", - move_left = "<a-h>", - move_right = "<a-l>", + parent_scope = "<a-k>", + child_scope = "<a-j>", + next_scope = "<a-l>", + previous_scope = "<a-h>", }, - }, - -- folding = { - -- enable = false, - -- disable = {}, - -- keymaps = {}, - -- is_supported = function() return false end - -- } + } }, ensure_installed = nil } @@ -279,12 +281,12 @@ local function enable_all(mod, ft) end end if ft then - if parser_utils.has_parser(ft) then + if utils.has_parser(ft) then enable_mod_conf_autocmd(mod, ft) end else for _, ft in pairs(M.available_parsers()) do - if parser_utils.has_parser(ft) then + if utils.has_parser(ft) then enable_mod_conf_autocmd(mod, ft) end end @@ -364,7 +366,7 @@ M.commands = { -- @param mod: module (string) -- @param ft: filetype (string) function M.is_enabled(mod, ft) - if not M.get_parser_configs()[ft] or not parser_utils.has_parser(ft) then + if not M.get_parser_configs()[ft] or not utils.has_parser(ft) then return false end @@ -378,6 +380,7 @@ function M.is_enabled(mod, ft) for _, parser in pairs(module_config.disable) do if ft == parser then return false end end + return true end @@ -393,11 +396,15 @@ function M.setup(user_data) config.modules[mod].disable = data.disable end if config.modules[mod].keymaps and type(data.keymaps) == 'table' then - config.modules[mod].keymaps = data.keymaps + for f, map in pairs(data.keymaps) do + if config.modules[mod].keymaps[f] then + config.modules[mod].keymaps[f] = map + end + end end elseif mod == 'ensure_installed' then config.ensure_installed = data - require'nvim-treesitter/install'.ensure_installed(data) + require'nvim-treesitter.install'.ensure_installed(data) end end end |
