-- ┌                                               ┐
-- │                Web technology                 │
-- └                                               ┘
local lsp = vim.lsp

local capabilities = require("lsp-options").capabilities
local on_attach = require("lsp-options").on_attach
local on_attach_no_formatting = require("lsp-options").on_attach_no_formatting

-- ┌                                               ┐
-- │                HTML, CSS, JSON                │
-- └                                               ┘
lsp.config("cssls", {
	capabilities = capabilities,
	on_attach = on_attach,
})

lsp.config("html", {
	capabilities = capabilities,
	on_attach = on_attach,
})

lsp.config("jsonls", {
	capabilities = capabilities,
	on_attach = on_attach,
})

-- ┌                                               ┐
-- │                      PHP                      │
-- └                                               ┘
lsp.config("intelephense", {
	capabilities = capabilities,
	on_attach = on_attach,
})

-- ┌                                               ┐
-- │                      Vue                      │
-- └                                               ┘
lsp.config("vue_ls", {
	capabilities = capabilities,
	on_attach = on_attach_no_formatting,
	filetypes = {
		"vue",
	},
})

local vue_plugin = {
	name = "@vue/typescript-plugin",
	location = "/usr/lib/node_modules/",
	languages = { "vue" },
	configNamespace = "typescript",
	enableForWorkspaceTypeScriptVersions = true,
}

-- ┌                                               ┐
-- │               TS, JS, TSX, JSX                │
-- └                                               ┘
lsp.config("vtsls", {
	capabilities = capabilities,
	on_attach = on_attach_no_formatting,
	filetypes = {
		"javascript",
		"typescript",
		"typescriptreact",
		"javascriptreact",
		"vue",
	},
	settings = {
		vtsls = {
			tsserver = {
				globalPlugins = {
					vue_plugin,
				},
			},
		},
	},
})

-- ┌                                               ┐
-- │                     nginx                     │
-- └                                               ┘
lsp.config("nginx_language_server", {
	capabilities = capabilities,
	on_attach = on_attach,
})

-- ── Enable configs ───────────────────────────────────────────────
local enable = vim.lsp.enable
enable("jsonls")
enable("html")
enable("cssls")
enable("intelephense")
enable("vtsls")
enable("vue_ls")
enable("nginx_language_server")
