Files
nvim/lua/lsp/init.lua
T

112 lines
2.7 KiB
Lua

local codelens = require("lsp.codelens")
local completion = require("lsp.completion")
local diagnostic = require("lsp.diagnostic")
local log = require("log")
local GROUP = vim.api.nvim_create_augroup("ow.lsp", { clear = true })
local M = {}
--- Load a JSON file and return a parsed table merged with settings
---@param path string
---@param settings? table
---@return table?
local function with_file(path, settings)
local file = io.open(path, "r")
if not file then
return
end
local json = file:read("*all")
file:close()
local ok, resp = pcall(
vim.json.decode,
json,
{ luanil = { object = true, array = true } }
)
if not ok then
log.warning("Failed to parse json file %s: %s", path, resp)
return
end
return vim.tbl_deep_extend("force", settings or {}, resp)
end
local function on_attach(client, buf)
client.settings = with_file(
string.format(".%s.json", client.name),
client.settings
) or client.settings
completion.on_attach(client, buf)
vim.api.nvim_clear_autocmds({ group = GROUP, buffer = buf })
vim.api.nvim_create_autocmd("LspProgress", {
buffer = buf,
group = GROUP,
callback = function(ev)
local value = ev.data.params.value
vim.api.nvim_echo({ { value.message or "done" } }, false, {
id = "lsp." .. ev.data.params.token,
kind = "progress",
source = "vim.lsp",
title = value.title,
status = value.kind ~= "end" and "running" or "success",
percent = value.percentage,
})
end,
})
end
function M.setup()
diagnostic.setup()
vim.lsp.enable({
"bashls",
"clangd",
"cmake",
"gopls",
-- "hyprls",
"intelephense",
-- "jedi_language_server",
"lemminx",
-- "xml_ls",
"lua_ls",
"mesonlsp",
"oxfmt",
"oxlint",
-- "phpactor",
-- "pyrefly",
"pyright",
"ruff",
"rust_analyzer",
"svelte",
"tailwindcss",
"tsgo",
"zls",
})
local capabilities = vim.lsp.protocol.make_client_capabilities()
completion.apply_capabilities(capabilities)
vim.lsp.config("*", {
capabilities = capabilities,
})
vim.api.nvim_create_autocmd("LspAttach", {
group = GROUP,
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client then
on_attach(client, ev.buf)
end
end,
})
completion.setup()
codelens.setup()
vim.lsp.log.set_level(vim.log.levels.WARN)
end
return M