aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorThomas Vigouroux <39092278+vigoux@users.noreply.github.com>2020-05-01 14:39:47 +0200
committerGitHub <noreply@github.com>2020-05-01 14:39:47 +0200
commit322bf360b251d60ccacf8cf53fa1813bc0023550 (patch)
treed50ed4bb3b187a6f44b22f7da3fc254bb83ba900 /lua
parentMerge pull request #34 from theHamsta/ensure_installed (diff)
parentupdate docs for ensure installed, move modules config in config.modules (diff)
downloadnvim-treesitter-322bf360b251d60ccacf8cf53fa1813bc0023550.tar
nvim-treesitter-322bf360b251d60ccacf8cf53fa1813bc0023550.tar.gz
nvim-treesitter-322bf360b251d60ccacf8cf53fa1813bc0023550.tar.bz2
nvim-treesitter-322bf360b251d60ccacf8cf53fa1813bc0023550.tar.lz
nvim-treesitter-322bf360b251d60ccacf8cf53fa1813bc0023550.tar.xz
nvim-treesitter-322bf360b251d60ccacf8cf53fa1813bc0023550.tar.zst
nvim-treesitter-322bf360b251d60ccacf8cf53fa1813bc0023550.zip
Merge pull request #35 from kyazdani42/refacto/config-doc
update docs for ensure installed, move modules config in config.modules
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/configs.lua87
1 files changed, 43 insertions, 44 deletions
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