From f19e254a646516f998cddc42ed4b5dd7655a5929 Mon Sep 17 00:00:00 2001 From: SamuraX Date: Sat, 30 Sep 2023 23:22:08 -0300 Subject: [PATCH] feat: add lspconfig default handler --- .../nvim/lua/josean/plugins/lsp/lspconfig.lua | 140 ++++++++---------- 1 file changed, 60 insertions(+), 80 deletions(-) diff --git a/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua b/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua index 618a0ab..c8ff2f8 100644 --- a/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua +++ b/.config/nvim/lua/josean/plugins/lsp/lspconfig.lua @@ -70,92 +70,72 @@ return { vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end - -- configure html server - lspconfig["html"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) + local function default_handler(server_name, capabilities) + require("lspconfig")[server_name].setup({ + capabilities = capabilities, + on_attach = on_attach, + }) + end - -- configure typescript server with plugin - lspconfig["tsserver"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - -- configure css server - lspconfig["cssls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - -- configure tailwindcss server - lspconfig["tailwindcss"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - -- configure svelte server - lspconfig["svelte"].setup({ - capabilities = capabilities, - on_attach = function(client, bufnr) - on_attach(client, bufnr) - - vim.api.nvim_create_autocmd("BufWritePost", { - pattern = { "*.js", "*.ts" }, - callback = function(ctx) - if client.name == "svelte" then - client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.file }) - end + lspconfig.setup_handlers({ + function(server_name) + default_handler(server_name, capabilities) + end, + -- configure svelte language server + ["svelte"] = function() + lspconfig.svelte.setup({ + capabilities = capabilities, + on_attach = function(client, bufnr) + on_attach(client, bufnr) + vim.api.nvim_create_autocmd("BufWritePost", { + pattern = { "*.js", "*.ts" }, + callback = function(ctx) + if client.name == "svelte" then + client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.file }) + end + end, + }) end, }) end, - }) - - -- configure prisma orm server - lspconfig["prismals"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - -- configure graphql language server - lspconfig["graphql"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" }, - }) - - -- configure emmet language server - lspconfig["emmet_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, - }) - - -- configure python server - lspconfig["pyright"].setup({ - capabilities = capabilities, - on_attach = on_attach, - }) - - -- configure lua server (with special settings) - lspconfig["lua_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { -- custom settings for lua - Lua = { - -- make the language server recognize "vim" global - diagnostics = { - globals = { "vim" }, - }, - workspace = { - -- make language server aware of runtime files - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true, + -- configure graphql language server + ["graphql"] = function() + lspconfig.graphql.setup({ + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" }, + }) + end, + -- configure emmet language server + ["emmet_ls"] = function() + lspconfig.emmet_ls.setup({ + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, + }) + end, + -- configure lua server (with special settings) + ["lua_ls"] = function() + lspconfig.lua_ls.setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { + Lua = { + -- make the language server recognize "vim" global + diagnostics = { + globals = { "vim" }, + }, + workspace = { + -- make language server aware of runtime files + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, }, }, - }, - }, + }) + end, }) end, }