mirror of
https://github.com/chenasraf/nvim-treesitter.git
synced 2026-05-18 01:39:00 +00:00
feat/refacto: improve configurations
- You should now get the configs through functions - Configs for languages are now inside a local object called parsers - You can get the parser installation configurations with `get_parser_configs` - A new object has been initialized inside configs to specify module config (called config). - Provide functions to enable/disable a module on one buffer - Provide functions to enable/disable a module on all buffers, and if filetype is specified, for specific filetype - Provide function to determine if module is activated for a specified filetype
This commit is contained in:
@@ -1,30 +1,28 @@
|
||||
local api = vim.api
|
||||
local parsers = require'nvim-treesitter.parsers'
|
||||
local configs = require 'nvim-treesitter.configs'
|
||||
local install = require'nvim-treesitter.install'
|
||||
local locals = require'nvim-treesitter.locals'
|
||||
local highlight = require'nvim-treesitter.highlight'
|
||||
local utils = require'nvim-treesitter.utils'
|
||||
local info = require'nvim-treesitter.info'
|
||||
local configs = require'nvim-treesitter.configs'
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.available_parsers()
|
||||
return vim.tbl_keys(configs.repositories)
|
||||
end
|
||||
|
||||
-- This function sets up everythin needed for a given language
|
||||
-- this is the main interface through the plugin
|
||||
function M.setup(lang)
|
||||
if parsers.has_parser(lang) then
|
||||
local autocmd = "autocmd NvimTreesitter FileType %s lua require'nvim-treesitter.highlight'.setup()"
|
||||
api.nvim_command(string.format(autocmd, lang))
|
||||
utils.setup_commands('install', install.commands)
|
||||
utils.setup_commands('info', info.commands)
|
||||
utils.setup_commands('configs', configs.commands)
|
||||
|
||||
for _, ft in pairs(configs.available_parsers()) do
|
||||
for _, mod in pairs(configs.available_modules()) do
|
||||
if parsers.has_parser(ft) and configs.is_enabled(mod, ft) then
|
||||
local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod)
|
||||
api.nvim_command(string.format("autocmd FileType %s %s", ft, cmd))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- This function initialize the plugin
|
||||
-- it is run at startup
|
||||
M._root = {}
|
||||
function M._root.setup()
|
||||
install.setup()
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user