summaryrefslogtreecommitdiff
path: root/lua/nvim-treesitter/install.lua
diff options
context:
space:
mode:
authorkiyan42 <yazdani.kiyan@protonmail.com>2020-05-08 11:22:59 +0200
committerkiyan42 <yazdani.kiyan@protonmail.com>2020-05-12 16:16:48 +0200
commit45dcebb15f1a954eba2bcb3ae4c1a03f710a1f2a (patch)
tree50cbca8e9615d69a8ff9aca6b33a35abb32f9363 /lua/nvim-treesitter/install.lua
parent307c78aa1e2cc5e499469fe892108b7fcf6cdb5e (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/install.lua')
-rw-r--r--lua/nvim-treesitter/install.lua41
1 files changed, 7 insertions, 34 deletions
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