diff options
| author | kiyan42 <yazdani.kiyan@protonmail.com> | 2020-05-01 12:26:57 +0200 |
|---|---|---|
| committer | kiyan42 <yazdani.kiyan@protonmail.com> | 2020-05-01 12:26:57 +0200 |
| commit | dc06f9ea8147da2b6aed60ce2eb657470e4e99a7 (patch) | |
| tree | d50ed4bb3b187a6f44b22f7da3fc254bb83ba900 | |
| parent | Merge pull request #34 from theHamsta/ensure_installed (diff) | |
| download | nvim-treesitter-dc06f9ea8147da2b6aed60ce2eb657470e4e99a7.tar nvim-treesitter-dc06f9ea8147da2b6aed60ce2eb657470e4e99a7.tar.gz nvim-treesitter-dc06f9ea8147da2b6aed60ce2eb657470e4e99a7.tar.bz2 nvim-treesitter-dc06f9ea8147da2b6aed60ce2eb657470e4e99a7.tar.lz nvim-treesitter-dc06f9ea8147da2b6aed60ce2eb657470e4e99a7.tar.xz nvim-treesitter-dc06f9ea8147da2b6aed60ce2eb657470e4e99a7.tar.zst nvim-treesitter-dc06f9ea8147da2b6aed60ce2eb657470e4e99a7.zip | |
update docs for ensure installed, move modules config in config.modules
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | doc/nvim-treesitter.txt | 3 | ||||
| -rw-r--r-- | lua/nvim-treesitter/configs.lua | 87 |
3 files changed, 48 insertions, 47 deletions
@@ -96,10 +96,11 @@ require'nvim-treesitter.configs'.setup { enable = true, disable = { 'cpp', 'lua' }, keymaps = { -- mappings for incremental selection (visual mappings) - node_incremental = "<leader>e", -- "grn" by default, + node_incremental = "<leader>e", -- "grn" by default, scope_incremental = "<leader>f" -- "grc" by default } - } + }, + ensure_installed = 'all' -- one of 'all', 'language', or a list of languages } EOF ``` diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 798c5bfc1..55ada1596 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -41,7 +41,8 @@ By default, everything is disabled. To enable support for features, in your `ini node_incremental = "<leader>e", -- "grn" by default, scope_incremental = "<leader>f" -- "grc" by default } - } + }, + ensure_installed = 'all' -- can be one of 'all', 'language' or {'language1', 'language2' ... } } < diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index eabe3e3bd..90ab92c4c 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -150,28 +150,31 @@ parsers.tsx = { -- @keymaps list of user mappings for a given module if relevant -- @is_supported function which, given a ft, will return true if the ft works on the module local config = { - highlight = { - enable = false, - disable = {}, - is_supported = function(ft) - return queries.get_query(ft, 'highlights') ~= nil - end - }, - textobj = { - enable = false, - disable = {}, - keymaps = { - node_incremental="grn", - scope_incremental="grc" + modules = { + highlight = { + enable = false, + disable = {}, + is_supported = function(ft) + return queries.get_query(ft, 'highlights') ~= nil + end + }, + textobj = { + enable = false, + disable = {}, + keymaps = { + node_incremental="grn", + scope_incremental="grc" + }, + is_supported = function() return true end }, - is_supported = function() return true end + -- folding = { + -- enable = false, + -- disable = {}, + -- keymaps = {}, + -- is_supported = function() return false end + -- } }, - -- folding = { - -- enable = false, - -- disable = {}, - -- keymaps = {}, - -- is_supported = function() return false end - -- } + ensure_installed = nil } local M = {} @@ -179,7 +182,7 @@ local M = {} local function enable_module(mod, bufnr, ft) local bufnr = bufnr or api.nvim_get_current_buf() local ft = ft or api.nvim_buf_get_option(bufnr, 'ft') - if not parsers[ft] or not config[mod] then + if not parsers[ft] or not config.modules[mod] then return end @@ -188,20 +191,20 @@ local function enable_module(mod, bufnr, ft) end local function enable_mod_conf_autocmd(mod, ft) - if not config[mod] or M.is_enabled(mod, ft) then return end + if not config.modules[mod] or M.is_enabled(mod, ft) then return end local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod) api.nvim_command(string.format("autocmd FileType %s %s", ft, cmd)) - for i, parser in pairs(config[mod].disable) do + for i, parser in pairs(config.modules[mod].disable) do if parser == ft then - table.remove(config[mod].disable, i) + table.remove(config.modules[mod].disable, i) break end end end local function enable_all(mod, ft) - if not config[mod] then return end + if not config.modules[mod] then return end for _, bufnr in pairs(api.nvim_list_bufs()) do if not ft or api.nvim_buf_get_option(bufnr, 'ft') == ft then @@ -219,13 +222,13 @@ local function enable_all(mod, ft) end end end - config[mod].enable = true + config.modules[mod].enable = true end local function disable_module(mod, bufnr, ft) local bufnr = bufnr or api.nvim_get_current_buf() local ft = ft or api.nvim_buf_get_option(bufnr, 'ft') - if not parsers[ft] or not config[mod] then + if not parsers[ft] or not config.modules[mod] then return end @@ -234,10 +237,10 @@ local function disable_module(mod, bufnr, ft) end local function disable_mod_conf_autocmd(mod, ft) - if not config[mod] or not M.is_enabled(mod, ft) then return end + if not config.modules[mod] or not M.is_enabled(mod, ft) then return end api.nvim_command(string.format("autocmd! FileType %s", ft)) - table.insert(config[mod].disable, ft) + table.insert(config.modules[mod].disable, ft) end local function disable_all(mod, ft) @@ -252,7 +255,7 @@ local function disable_all(mod, ft) for _, ft in pairs(M.available_parsers()) do disable_mod_conf_autocmd(mod, ft) end - config[mod].enable = false + config.modules[mod].enable = false end end @@ -298,7 +301,7 @@ function M.is_enabled(mod, ft) return false end - local module_config = M.get_config()[mod] + local module_config = config.modules[mod] if not module_config then return false end if not module_config.enable or not module_config.is_supported(ft) then @@ -315,27 +318,23 @@ function M.setup(user_data) if not user_data then return end for mod, data in pairs(user_data) do - if config[mod] then + if config.modules[mod] then if type(data.enable) == 'boolean' then - config[mod].enable = data.enable + config.modules[mod].enable = data.enable end if type(data.disable) == 'table' then - config[mod].disable = data.disable + config.modules[mod].disable = data.disable end - if config[mod].keymaps and type(data.keymaps) == 'table' then - config[mod].keymaps = data.keymaps - end - if mod == 'ensure_installed' then - require'nvim-treesitter/install'.ensure_installed(data) + if config.modules[mod].keymaps and type(data.keymaps) == 'table' then + config.modules[mod].keymaps = data.keymaps end + elseif mod == 'ensure_installed' then + config.ensure_installed = data + require'nvim-treesitter/install'.ensure_installed(data) end end end -function M.get_config() - return config -end - function M.get_parser_configs() return parsers end @@ -345,7 +344,7 @@ function M.available_parsers() end function M.available_modules() - return vim.tbl_keys(config) + return vim.tbl_keys(config.modules) end return M |
