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:
kiyan42
2020-04-22 11:13:05 +02:00
parent b7fdd6ae38
commit 62786ec7c6
8 changed files with 453 additions and 112 deletions

View File

@@ -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