From 45dcebb15f1a954eba2bcb3ae4c1a03f710a1f2a Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Fri, 8 May 2020 11:22:59 +0200 Subject: 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 --- lua/nvim-treesitter/install.lua | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) (limited to 'lua/nvim-treesitter/install.lua') diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 77e0fccc..45aec99c 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -1,38 +1,11 @@ local api = vim.api local fn = vim.fn local luv = vim.loop -local configs = require'nvim-treesitter/configs' -local parsers = configs.get_parser_configs() -local has_parser = require'nvim-treesitter/parsers'.has_parser -local M = {} - -local function get_package_path() - for _, path in pairs(api.nvim_list_runtime_paths()) do - if string.match(path, '.*/nvim%-treesitter') then - return path - end - end - - return nil, 'Plugin runtime path not found.' -end - -local function get_cache_dir() - local home = fn.get(fn.environ(), 'HOME') - local xdg_cache = fn.get(fn.environ(), 'XDG_CACHE_HOME') +local configs = require'nvim-treesitter.configs' +local utils = require'nvim-treesitter.utils' - if xdg_cache == 0 then - xdg_cache = home .. '/.cache' - end - - if luv.fs_access(xdg_cache, 'RW') then - return xdg_cache - elseif luv.fs_access('/tmp', 'RW') then - return '/tmp' - end - - return nil, 'Invalid cache rights, $XDG_CACHE_HOME or /tmp should be read/write' -end +local M = {} local function iter_cmd(cmd_list, i, ft) if i == #cmd_list + 1 then return print('Treesitter parser for '..ft..' has been installed') end @@ -122,7 +95,7 @@ local function install(ft) if not string.match(yesno, '^y.*') then return end end - local parser_config = parsers[ft] + local parser_config = configs.get_parser_configs()[ft] if not parser_config then return api.nvim_err_writeln('Parser not available for language '..ft) end @@ -137,10 +110,10 @@ local function install(ft) return api.nvim_err_writeln('Git is required on your system to run this command') end - local package_path, err = get_package_path() + local package_path, err = utils.get_package_path() if err then return api.nvim_err_writeln(err) end - local cache_folder, err = get_cache_dir() + local cache_folder, err = utils.get_cache_dir() if err then return api.nvim_err_writeln(err) end run_install(cache_folder, package_path, ft, install_info) @@ -157,7 +130,7 @@ M.ensure_installed = function(languages) end for _, ft in ipairs(languages) do - if not has_parser(ft) then + if not utils.has_parser(ft) then install(ft) end end -- cgit v1.2.3