-- инициализация LSP для различных ЯП
local lspconfig = require("lspconfig")
local util = require("lspconfig/util")

local function config(_config)
	local capabilities = vim.lsp.protocol.make_client_capabilities()

	capabilities = vim.tbl_deep_extend("force", capabilities, require("blink.cmp").get_lsp_capabilities({}, false))

	capabilities = vim.tbl_deep_extend("force", capabilities, {
		textDocument = {
			foldingRange = {
				dynamicRegistration = false,
				lineFoldingOnly = true,
			},
		},
	})
	return vim.tbl_deep_extend("force", {
		capabilities = capabilities,
	}, _config or {})
end
-- иницализация gopls LSP для Go
-- https://github.com/golang/tools/blob/master/gopls/doc/vim.md#neovim-install
lspconfig.gopls.setup(config({
	cmd = { "gopls", "serve" },
	filetypes = { "go", "go.mod" },
	root_dir = util.root_pattern("go.work", "go.mod", ".git"),
	settings = {
		gopls = {
			analyses = {
				unusedparams = true,
			},
			staticcheck = true,
			gofumpt = true,
		},
	},
}))

lspconfig.templ.setup(config({
	cmd = { "templ", "lsp" },
	filetypes = { "templ" },
	root_markers = { "go.work", "go.mod", ".git" },
}))

lspconfig.v_analyzer.setup(config({
	cmd = { "v-analyzer" },
	filetypes = { "v", "vv", "vsh" },
	root_markers = { "v.mod", ".git" },
}))
