mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-08 14:30:05 -04:00
update docs for ensure installed, move modules config in config.modules
This commit is contained in:
parent
1d6ad9b560
commit
dc06f9ea81
3 changed files with 48 additions and 47 deletions
|
|
@ -96,10 +96,11 @@ require'nvim-treesitter.configs'.setup {
|
||||||
enable = true,
|
enable = true,
|
||||||
disable = { 'cpp', 'lua' },
|
disable = { 'cpp', 'lua' },
|
||||||
keymaps = { -- mappings for incremental selection (visual mappings)
|
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
|
scope_incremental = "<leader>f" -- "grc" by default
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
ensure_installed = 'all' -- one of 'all', 'language', or a list of languages
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ By default, everything is disabled. To enable support for features, in your `ini
|
||||||
node_incremental = "<leader>e", -- "grn" by default,
|
node_incremental = "<leader>e", -- "grn" by default,
|
||||||
scope_incremental = "<leader>f" -- "grc" by default
|
scope_incremental = "<leader>f" -- "grc" by default
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
ensure_installed = 'all' -- can be one of 'all', 'language' or {'language1', 'language2' ... }
|
||||||
}
|
}
|
||||||
<
|
<
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,28 +150,31 @@ parsers.tsx = {
|
||||||
-- @keymaps list of user mappings for a given module if relevant
|
-- @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
|
-- @is_supported function which, given a ft, will return true if the ft works on the module
|
||||||
local config = {
|
local config = {
|
||||||
highlight = {
|
modules = {
|
||||||
enable = false,
|
highlight = {
|
||||||
disable = {},
|
enable = false,
|
||||||
is_supported = function(ft)
|
disable = {},
|
||||||
return queries.get_query(ft, 'highlights') ~= nil
|
is_supported = function(ft)
|
||||||
end
|
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
|
textobj = {
|
||||||
|
enable = false,
|
||||||
|
disable = {},
|
||||||
|
keymaps = {
|
||||||
|
node_incremental="grn",
|
||||||
|
scope_incremental="grc"
|
||||||
|
},
|
||||||
|
is_supported = function() return true end
|
||||||
|
},
|
||||||
|
-- folding = {
|
||||||
|
-- enable = false,
|
||||||
|
-- disable = {},
|
||||||
|
-- keymaps = {},
|
||||||
|
-- is_supported = function() return false end
|
||||||
|
-- }
|
||||||
},
|
},
|
||||||
-- folding = {
|
ensure_installed = nil
|
||||||
-- enable = false,
|
|
||||||
-- disable = {},
|
|
||||||
-- keymaps = {},
|
|
||||||
-- is_supported = function() return false end
|
|
||||||
-- }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
@ -179,7 +182,7 @@ local M = {}
|
||||||
local function enable_module(mod, bufnr, ft)
|
local function enable_module(mod, bufnr, ft)
|
||||||
local bufnr = bufnr or api.nvim_get_current_buf()
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
local ft = ft or api.nvim_buf_get_option(bufnr, 'ft')
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -188,20 +191,20 @@ local function enable_module(mod, bufnr, ft)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function enable_mod_conf_autocmd(mod, ft)
|
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)
|
local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod)
|
||||||
api.nvim_command(string.format("autocmd FileType %s %s", ft, cmd))
|
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
|
if parser == ft then
|
||||||
table.remove(config[mod].disable, i)
|
table.remove(config.modules[mod].disable, i)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function enable_all(mod, ft)
|
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
|
for _, bufnr in pairs(api.nvim_list_bufs()) do
|
||||||
if not ft or api.nvim_buf_get_option(bufnr, 'ft') == ft then
|
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
|
end
|
||||||
end
|
end
|
||||||
config[mod].enable = true
|
config.modules[mod].enable = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disable_module(mod, bufnr, ft)
|
local function disable_module(mod, bufnr, ft)
|
||||||
local bufnr = bufnr or api.nvim_get_current_buf()
|
local bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
local ft = ft or api.nvim_buf_get_option(bufnr, 'ft')
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -234,10 +237,10 @@ local function disable_module(mod, bufnr, ft)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disable_mod_conf_autocmd(mod, ft)
|
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))
|
api.nvim_command(string.format("autocmd! FileType %s", ft))
|
||||||
table.insert(config[mod].disable, ft)
|
table.insert(config.modules[mod].disable, ft)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disable_all(mod, ft)
|
local function disable_all(mod, ft)
|
||||||
|
|
@ -252,7 +255,7 @@ local function disable_all(mod, ft)
|
||||||
for _, ft in pairs(M.available_parsers()) do
|
for _, ft in pairs(M.available_parsers()) do
|
||||||
disable_mod_conf_autocmd(mod, ft)
|
disable_mod_conf_autocmd(mod, ft)
|
||||||
end
|
end
|
||||||
config[mod].enable = false
|
config.modules[mod].enable = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -298,7 +301,7 @@ function M.is_enabled(mod, ft)
|
||||||
return false
|
return false
|
||||||
end
|
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 then return false end
|
||||||
|
|
||||||
if not module_config.enable or not module_config.is_supported(ft) then
|
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
|
if not user_data then return end
|
||||||
|
|
||||||
for mod, data in pairs(user_data) do
|
for mod, data in pairs(user_data) do
|
||||||
if config[mod] then
|
if config.modules[mod] then
|
||||||
if type(data.enable) == 'boolean' then
|
if type(data.enable) == 'boolean' then
|
||||||
config[mod].enable = data.enable
|
config.modules[mod].enable = data.enable
|
||||||
end
|
end
|
||||||
if type(data.disable) == 'table' then
|
if type(data.disable) == 'table' then
|
||||||
config[mod].disable = data.disable
|
config.modules[mod].disable = data.disable
|
||||||
end
|
end
|
||||||
if config[mod].keymaps and type(data.keymaps) == 'table' then
|
if config.modules[mod].keymaps and type(data.keymaps) == 'table' then
|
||||||
config[mod].keymaps = data.keymaps
|
config.modules[mod].keymaps = data.keymaps
|
||||||
end
|
|
||||||
if mod == 'ensure_installed' then
|
|
||||||
require'nvim-treesitter/install'.ensure_installed(data)
|
|
||||||
end
|
end
|
||||||
|
elseif mod == 'ensure_installed' then
|
||||||
|
config.ensure_installed = data
|
||||||
|
require'nvim-treesitter/install'.ensure_installed(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_config()
|
|
||||||
return config
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.get_parser_configs()
|
function M.get_parser_configs()
|
||||||
return parsers
|
return parsers
|
||||||
end
|
end
|
||||||
|
|
@ -345,7 +344,7 @@ function M.available_parsers()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.available_modules()
|
function M.available_modules()
|
||||||
return vim.tbl_keys(config)
|
return vim.tbl_keys(config.modules)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue