local ts = require("nvim-treesitter.configs")

ts.setup({
	ensure_installed = "all",
	highlight = {
		enable = true,
		-- Disable slow treesitter highlight for large files
		disable = function(lang, buf)
			local max_filesize = 100 * 1024 -- 100 KB
			local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
			if ok and stats and stats.size > max_filesize then
				return true
			end
		end,
		additional_vim_regex_highlighting = false,
	},
	indent = { enable = true },
	autopairs = { enable = true, },
	autotag = { enable = true, },
	query_linter = {
		enable = true,
		use_virtual_text = true,
		lint_events = { "BufWrite", "CursorHold" },
	},
	incremental_selection = {
		enable = false,
		keymaps = {
			init_selection = "<space>", -- maps in normal mode to init the node/scope selection with space
			node_incremental = "<space>", -- increment to the upper named parent
			node_decremental = "<bs>", -- decrement to the previous node
			scope_incremental = "<tab>", -- increment to the upper scope (as defined in locals.scm)
		},

		textobjects = {
			select = {
				enable = false,
				lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
				keymaps = {
					-- You can use the capture groups defined in textobjects.scm
					["aa"] = "@parameter.outer",
					["ia"] = "@parameter.inner",
					["af"] = "@function.outer",
					["if"] = "@function.inner",
					["ac"] = "@class.outer",
					["ic"] = "@class.inner",
					["iB"] = "@block.inner",
					["aB"] = "@block.outer",
				},
			},
			move = {
				enable = false,
				set_jumps = true, -- whether to set jumps in the jumplist
				goto_next_start = { ["]]"] = "@function.outer", },
				goto_next_end = { ["]["] = "@function.outer", },
				goto_previous_start = { ["[["] = "@function.outer", },
				goto_previous_end = { ["[]"] = "@function.outer", },
			},
			swap = {
				enable = false,
				swap_next = { ["<leader>a"] = "@parameter.inner", },
				swap_previous = { ["<leader>A"] = "@parameter.inner", },
			},
		},
	},
})

-- local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
-- parser_config.analog = {
-- 	install_info = {
-- 		url = "~/GitHub/mhartington/tree-sitter-analog",
-- 		files = { "src/parser.c", "src/scanner.c" },
-- 		generate_requires_npm = false,
-- 		requires_generate_from_grammar = false,
-- 	},
-- 	filetype = "analog", -- if filetype does not match the parser name
-- }
