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
This commit is contained in:
kiyan42 2020-05-08 11:22:59 +02:00
parent 307c78aa1e
commit 45dcebb15f
14 changed files with 555 additions and 333 deletions

View file

@ -31,25 +31,27 @@ By default, everything is disabled. To enable support for features, in your `ini
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true, -- false will disable the whole extension
disable = { 'c', 'rust' }, -- list of language that will be disabled
enable = true, -- false will disable the whole extension
disable = { 'c', 'rust' }, -- list of language that will be disabled
},
incremental_selection = { -- this enables incremental selection
incremental_selection = {
enable = true,
disable = { 'cpp', 'lua' },
keymaps = { -- mappings for incremental selection (visual mappings)
node_incremental = "<leader>e", -- "grn" by default,
scope_incremental = "<leader>f" -- "grc" by default
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
node_incremental = "grn", -- increment to the upper named parent
scope_incremental = "grc", -- increment to the upper scope (as defined in locals.scm)
scope_decremental = "grm", -- decrement to the previous scope
}
},
node_movement = { -- this cursor movement in node hierachy
enable = true,
disable = { 'cpp', 'rust' },
keymaps = { -- mappings for node movement (normal mappings)
move_up = "<a-k>", -- default is to move with alt key hold
move_down = "<a-j>",
move_left = "<a-h>",
move_right = "<a-l>",
keymaps = { -- mappings for scope movement
parent_scope = "<a-k>", -- default is to move with alt key hold
child_scope = "<a-j>",
next_scope = "<a-h>",
previous_scope = "<a-l>",
}
},
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages