diff options
| author | jdhao <jdhao@hotmail.com> | 2022-09-10 23:55:22 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2022-09-10 23:55:22 +0800 |
| commit | aaeb6a813a9044892e5bb76ba4a3a61db08eae4d (patch) | |
| tree | 6a1dc5a4f79f08678bdb8903a7920e8545718fa7 /lua/config/lsp.lua | |
| parent | 9ba728e201657892681cafc2c6fe8ad997873b49 (diff) | |
format with stylua
Diffstat (limited to 'lua/config/lsp.lua')
| -rw-r--r-- | lua/config/lsp.lua | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 76436a4..0fad17a 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -14,37 +14,41 @@ local custom_attach = function(client, bufnr) keymap.set(mode, l, r, opts) end - map("n", "gd", vim.lsp.buf.definition, {desc = 'go to definition'}) + map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" }) map("n", "<C-]>", vim.lsp.buf.definition) map("n", "K", vim.lsp.buf.hover) map("n", "<C-k>", vim.lsp.buf.signature_help) - map("n", "<space>rn", vim.lsp.buf.rename, { desc = 'varialbe rename' }) - map("n", "gr", vim.lsp.buf.references, { desc = 'show references' }) - map("n", "[d", vim.diagnostic.goto_prev, { desc = 'previous diagnostic' }) - map("n", "]d", vim.diagnostic.goto_next, { desc = 'next diagnostic' }) - map("n", "<space>q", function() vim.diagnostic.setqflist({open = true}) end, { desc = 'put diagnostic to qf' }) - map("n", "<space>ca", vim.lsp.buf.code_action, { desc = 'LSP code action' }) - map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = 'add workspace folder' } ) - map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = 'remove workspace folder' }) - map("n", "<space>wl", function() inspect(vim.lsp.buf.list_workspace_folders()) end, { desc = 'list workspace folder' }) + map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" }) + map("n", "gr", vim.lsp.buf.references, { desc = "show references" }) + map("n", "[d", vim.diagnostic.goto_prev, { desc = "previous diagnostic" }) + map("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic" }) + map("n", "<space>q", function() + vim.diagnostic.setqflist { open = true } + end, { desc = "put diagnostic to qf" }) + map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" }) + map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) + map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) + map("n", "<space>wl", function() + inspect(vim.lsp.buf.list_workspace_folders()) + end, { desc = "list workspace folder" }) -- Set some key bindings conditional on server capabilities if client.resolved_capabilities.document_formatting then - map("n", "<space>f", vim.lsp.buf.formatting_sync, { desc = 'format code' }) + map("n", "<space>f", vim.lsp.buf.formatting_sync, { desc = "format code" }) end if client.resolved_capabilities.document_range_formatting then - map("x", "<space>f", vim.lsp.buf.range_formatting, { desc = 'range format' }) + map("x", "<space>f", vim.lsp.buf.range_formatting, { desc = "range format" }) end api.nvim_create_autocmd("CursorHold", { - buffer=bufnr, + buffer = bufnr, callback = function() local float_opts = { focusable = false, close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, - border = 'rounded', - source = 'always', -- show source in diagnostic popup window - prefix = ' ' + border = "rounded", + source = "always", -- show source in diagnostic popup window + prefix = " ", } if not vim.b.diagnostics_pos then @@ -52,14 +56,15 @@ local custom_attach = function(client, bufnr) end local cursor_pos = api.nvim_win_get_cursor(0) - if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) and - #vim.diagnostic.get() > 0 + if + (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) + and #vim.diagnostic.get() > 0 then - vim.diagnostic.open_float(nil, float_opts) + vim.diagnostic.open_float(nil, float_opts) end vim.b.diagnostics_pos = cursor_pos - end + end, }) -- The blow command will highlight the current variable and its usages in the buffer. @@ -76,20 +81,20 @@ local custom_attach = function(client, bufnr) ]]) end - if vim.g.logging_level == 'debug' then + if vim.g.logging_level == "debug" then local msg = string.format("Language server %s started!", client.name) - vim.notify(msg, vim.log.levels.DEBUG, {title = 'Nvim-config'}) + vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" }) end end local capabilities = lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = true local lspconfig = require("lspconfig") -if utils.executable('pylsp') then - lspconfig.pylsp.setup({ +if utils.executable("pylsp") then + lspconfig.pylsp.setup { on_attach = custom_attach, settings = { pylsp = { @@ -107,9 +112,9 @@ if utils.executable('pylsp') then debounce_text_changes = 200, }, capabilities = capabilities, - }) + } else - vim.notify("pylsp not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) + vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end -- if utils.executable('pyright') then @@ -121,43 +126,43 @@ end -- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) -- end -if utils.executable('clangd') then - lspconfig.clangd.setup({ +if utils.executable("clangd") then + lspconfig.clangd.setup { on_attach = custom_attach, capabilities = capabilities, filetypes = { "c", "cpp", "cc" }, flags = { debounce_text_changes = 500, }, - }) + } else - vim.notify("clangd not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) + vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end -- set up vim-language-server -if utils.executable('vim-language-server') then - lspconfig.vimls.setup({ +if utils.executable("vim-language-server") then + lspconfig.vimls.setup { on_attach = custom_attach, flags = { debounce_text_changes = 500, }, capabilities = capabilities, - }) + } else - vim.notify("vim-language-server not found!", vim.log.levels.WARN, {title = 'Nvim-config'}) + vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" }) end -- set up bash-language-server -if utils.executable('bash-language-server') then - lspconfig.bashls.setup({ +if utils.executable("bash-language-server") then + lspconfig.bashls.setup { on_attach = custom_attach, capabilities = capabilities, - }) + } end if utils.executable("lua-language-server") then -- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings . - lspconfig.sumneko_lua.setup({ + lspconfig.sumneko_lua.setup { on_attach = custom_attach, settings = { Lua = { @@ -174,8 +179,8 @@ if utils.executable("lua-language-server") then -- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace . -- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua . library = { - fn.stdpath('data') .. "/site/pack/packer/opt/emmylua-nvim", - fn.stdpath('config'), + fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim", + fn.stdpath("config"), }, maxPreload = 2000, preloadFileSize = 50000, @@ -183,7 +188,7 @@ if utils.executable("lua-language-server") then }, }, capabilities = capabilities, - }) + } end -- Change diagnostic signs. @@ -193,12 +198,12 @@ fn.sign_define("DiagnosticSignInformation", { text = "", texthl = "Diagnostic fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) -- global config for diagnostic -vim.diagnostic.config({ +vim.diagnostic.config { underline = false, virtual_text = false, signs = true, severity_sort = true, -}) +} -- lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, { -- underline = false, |
