From 714d03e4eb6014a4f7657db41ad89ef513579038 Mon Sep 17 00:00:00 2001 From: PrashanthaTP Date: Sun, 12 Dec 2021 23:24:13 +0530 Subject: [PATCH] Chore(nvim): format using lua-format tags: lua-format, code-formatting --- .../nvim/lua/plugins/nvim-lspconfig/init.lua | 20 +- .../nvim/lua/plugins/nvim-lspconfig/utils.lua | 185 ++++++++---------- 2 files changed, 97 insertions(+), 108 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/init.lua b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua index 64c2910..1d2f048 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/init.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/init.lua @@ -1,13 +1,14 @@ local nvim_lsp = require("lspconfig") local utils = require("plugins.nvim-lspconfig.utils") local on_attach = utils.on_attach - -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -local servers = { "pyright", "clangd", "cmake", "tsserver", "cssls", "sumneko_lua" } - -local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) - +local servers = { + "pyright", "clangd", "cmake", "tsserver", "cssls", "sumneko_lua" +} +local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp + .protocol + .make_client_capabilities()) --[[ for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup({ @@ -19,21 +20,22 @@ for _, lsp in ipairs(servers) do }) end --]] -vim.lsp.set_log_level("debug") +-- vim.lsp.set_log_level("debug") require("plugins.nvim-lspconfig.servers.pyright").setup(on_attach, capabilities) require("plugins.nvim-lspconfig.servers.clangd").setup(on_attach, capabilities) require("plugins.nvim-lspconfig.servers.cmake").setup(on_attach, capabilities) require("plugins.nvim-lspconfig.servers.cssls").setup(on_attach, capabilities) -require("plugins.nvim-lspconfig.servers.sumneko_lua").setup(on_attach, capabilities) +require("plugins.nvim-lspconfig.servers.sumneko_lua").setup(on_attach, + capabilities) require("plugins.nvim-lspconfig.servers.tsserver").setup(on_attach, capabilities) require("plugins.nvim-lspconfig.servers.efm").setup(on_attach, capabilities) --require("plugins.nvim-lspconfig.servers.diagnosticls").setup(on_attach,capabilities) -- function _G.updateLocationList() - vim.lsp.diagnostic.set_loclist({ open_loclist = false }) + vim.lsp.diagnostic.set_loclist({open_loclist = false}) end - ---reference : https://rafaelleru.github.io/blog/quickfix-autocomands/ +--- reference for autocmd : https://github.com/neovim/neovim/issues/14090#issuecomment-979424077 vim.cmd([[ augroup UPDATE_LOCATION_LIST_WITH_LSP_LINTS autocmd! diff --git a/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua index 57bd7fc..df78d83 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig/utils.lua @@ -1,112 +1,99 @@ local lspconfig = require("lspconfig") local t = require("utils").replace_termcodes local M = {} - M.set_keymappings = function(bufnr) - local buf_set_keymap = function(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) - end - - local opts = { noremap = true, silent = true } - - -- See `:help vim.lsp.*` for documentation on any of the below functions - buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) - buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) - buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) - buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - buf_set_keymap("n", t(""), "lua vim.lsp.buf.signature_help()", opts) - buf_set_keymap("n", t("wa"), "lua vim.lsp.buf.add_workspace_folder()", opts) - buf_set_keymap("n", t("wr"), "lua vim.lsp.buf.remove_workspace_folder()", opts) - buf_set_keymap("n", t("wl"), "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", opts) - buf_set_keymap("n", t("D"), "lua vim.lsp.buf.type_definition()", opts) - buf_set_keymap("n", t("rn"), "lua vim.lsp.buf.rename()", opts) - buf_set_keymap("n", t("ca"), "lua vim.lsp.buf.code_action()", opts) - buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) - buf_set_keymap("n", t("e"), "lua vim.lsp.diagnostic.show_line_diagnostics()", opts) - buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", opts) - buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", opts) - buf_set_keymap("n", t("q"), "lua vim.lsp.diagnostic.set_loclist()", opts) - buf_set_keymap("n", t("wf"), "lua vim.lsp.buf.formatting()", opts) - -- formatting + local buf_set_keymap = function(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + local opts = {noremap = true, silent = true} + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", opts) + buf_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", opts) + buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) + buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) + buf_set_keymap("n", t(""), "lua vim.lsp.buf.signature_help()", + opts) + buf_set_keymap("n", t("wa"), + "lua vim.lsp.buf.add_workspace_folder()", opts) + buf_set_keymap("n", t("wr"), + "lua vim.lsp.buf.remove_workspace_folder()", opts) + buf_set_keymap("n", t("wl"), + "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", + opts) + buf_set_keymap("n", t("D"), + "lua vim.lsp.buf.type_definition()", opts) + buf_set_keymap("n", t("rn"), "lua vim.lsp.buf.rename()", + opts) + buf_set_keymap("n", t("ca"), + "lua vim.lsp.buf.code_action()", opts) + buf_set_keymap("n", "gr", "lua vim.lsp.buf.references()", opts) + buf_set_keymap("n", t("e"), + "lua vim.lsp.diagnostic.show_line_diagnostics()", + opts) + buf_set_keymap("n", "[d", "lua vim.lsp.diagnostic.goto_prev()", + opts) + buf_set_keymap("n", "]d", "lua vim.lsp.diagnostic.goto_next()", + opts) + buf_set_keymap("n", t("q"), + "lua vim.lsp.diagnostic.set_loclist()", opts) + -- buf_set_keymap("n", t("wf"), "lua vim.lsp.buf.formatting()", opts) + -- formatting end - -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer M.on_attach = function(client, bufnr) - local buf_set_option = function(...) - vim.api.nvim_buf_set_option(bufnr, ...) - end - -- Enable completion triggered by - buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") - -- Mappings. - M.set_keymappings(bufnr) - - --[[ if client.name == 'tsserver' then + local buf_set_option = function(...) + vim.api.nvim_buf_set_option(bufnr, ...) + end + -- Enable completion triggered by + buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc") + -- Mappings. + M.set_keymappings(bufnr) + --[[ if client.name == 'tsserver' then client.resolved_capabilities.document_formatting = false end --]] - if client.resolved_capabilities.document_formatting then - vim.api.nvim_command([[augroup FORMAT]]) - vim.api.nvim_command([[autocmd! * ]]) - vim.api.nvim_command([[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]]) - vim.api.nvim_command([[augroup end]]) - end - vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = { spacing = 4, prefix = "" }, - signs = true, - underline = true, - update_in_insert = true, - }) - --protocol.SymbolKind = { } - vim.lsp.protocol.completionItemKind = { - "", -- Text - "", -- Method - "", -- Function - "", -- Constructor - "", -- Field - "", -- Variable - "", -- Class - "ﰮ", -- Interface - "", -- Module - "", -- Property - "", -- Unit - "", -- Value - "", -- Enum - "", -- Keyword - "﬌", -- Snippet - "", -- Color - "", -- File - "", -- Reference - "", -- Folder - "", -- EnumMember - "", -- Constant - "", -- Struct - "", -- Event - "ﬦ", -- Operator - "", -- TypeParameter - } -end - ---[==[== on attach add formatting functionality --- - if client.resolved_capabilities.document_formatting then - vim.api.nvim_command([[augroup FORMAT]]) - vim.api.nvim_command([[autocmd! * ]]) - vim.api.nvim_command([[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]]) - vim.api.nvim_command([[augroup end]]) - end ---]==] -local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) - -M.get_capabilities = function() - local _capabilities = nil - if capabilities == nil then - _capabilities = vim.lsp.protocol.make_client_capabilities() - _capabilities.textDocument.completion.completionItem.snippetSupport = true - else - _capabilities = capabilities - end - return _capabilities + if client.resolved_capabilities.document_formatting then + vim.api.nvim_command([[augroup FORMAT]]) + vim.api.nvim_command([[autocmd! * ]]) + vim.api.nvim_command( + [[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]]) + vim.api.nvim_command([[augroup end]]) + end + vim.lsp.handlers["textDocument/publishDiagnostics"] = + vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + virtual_text = {spacing = 4, prefix = ""}, + signs = true, + underline = true, + update_in_insert = false + }) + -- protocol.SymbolKind = { } + vim.lsp.protocol.completionItemKind = { + "", -- Text + "", -- Method + "", -- Function + "", -- Constructor + "", -- Field + "", -- Variable + "", -- Class + "ﰮ", -- Interface + "", -- Module + "", -- Property + "", -- Unit + "", -- Value + "", -- Enum + "", -- Keyword + "﬌", -- Snippet + "", -- Color + "", -- File + "", -- Reference + "", -- Folder + "", -- EnumMember + "", -- Constant + "", -- Struct + "", -- Event + "ﬦ", -- Operator + "" -- TypeParameter + } end - return M