---@class ow.lsp.Response ---@field err lsp.ResponseError? ---@field result any ---@field context lsp.HandlerContext local codelens = require("lsp.codelens") 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 if type(resp) ~= "table" then log.warning( "Invalid json in file %s: expected table, got: %s", path, type(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 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, }) pcall(vim.keymap.del, "n", "K", { buffer = buf }) end function M.setup() diagnostic.setup() vim.lsp.enable({ "bashls", "clangd", "neocmake", "emmylua_ls", "gopls", -- "hyprls", "intelephense", -- "jedi_language_server", "jsonls", "lemminx", -- "xml_ls", -- "lua_ls", "mesonlsp", "oxfmt", "oxlint", -- "phpactor", -- "pyrefly", "pyright", "ruff", "rust_analyzer", "svelte", "tailwindcss", "tsgo", "zls", }) local capabilities = require("blink.cmp").get_lsp_capabilities({}, true) 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, }) -- require("lsp.completion").setup() codelens.setup() vim.lsp.log.set_level(vim.log.levels.WARN) end return M