aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-treesitter.lua
blob: 731f55e5d3042a757313c55a360975824f191371 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local api = vim.api
local parsers = require'nvim-treesitter.parsers'
local install = require'nvim-treesitter.install'
local locals = require'nvim-treesitter.locals'
local utils = require'nvim-treesitter.utils'
local info = require'nvim-treesitter.info'
local configs = require'nvim-treesitter.configs'

local M = {}

-- This function sets up everythin needed for a given language
-- this is the main interface through the plugin
function M.setup(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

return M