-- ┌                                               ┐
-- │                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,
})

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

local vue_language_server_path = vim.fn.expand("$MASON/packages")
    .. "/vue-language-server"
    .. "/node_modules/@vue/language-server"
local vue_plugin = {
    name = "@vue/typescript-plugin",
    location = vue_language_server_path,
    languages = { "vue" },
    configNamespace = "typescript",
}

-- ┌                                               ┐
-- │               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,
                },
            },
        },
    },
})

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