From ec53f123399c933f02c9d2a477e15915b7025d62 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 18 Nov 2021 20:32:42 +0100 Subject: nvim: trouble and null ls --- nvim/lua/lsp_conf.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'nvim/lua/lsp_conf.lua') diff --git a/nvim/lua/lsp_conf.lua b/nvim/lua/lsp_conf.lua index a63b761..ba574d6 100644 --- a/nvim/lua/lsp_conf.lua +++ b/nvim/lua/lsp_conf.lua @@ -1,5 +1,18 @@ local nvim_lsp = require('lspconfig') local coq = require('coq') +local null_ls = require("null-ls") +local trouble = require("trouble") + +-- Redefine sign. +local signs = { Error = ' ', Warning = ' ', Hint = ' ', Information = ' ' } + +for type, icon in pairs(signs) do + local hl = 'LspDiagnosticsSign' .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' }) +end + +local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end +local opts = { noremap=true, silent=true } local on_attach = function(client, bufnr) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end @@ -12,18 +25,31 @@ local on_attach = function(client, bufnr) 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', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', '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) end +null_ls.config({ + debug = false, + sources = { + -- Python + null_ls.builtins.formatting.black, + null_ls.builtins.formatting.isort, + null_ls.builtins.diagnostics.flake8, + -- Rust + null_ls.builtins.formatting.rustfmt, + -- C + null_ls.builtins.formatting.clang_format, + -- JS/TS + null_ls.builtins.formatting.prettier, + } +}) + -- Setup lspconfig. --- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -local servers = { 'jedi_language_server', 'rust_analyzer', 'tsserver', 'clangd' } +local servers = { 'pyright', 'rust_analyzer', 'tsserver', 'clangd' } for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { capabilities = coq.lsp_ensure_capabilities(), @@ -33,3 +59,19 @@ for _, lsp in ipairs(servers) do } } end + +nvim_lsp["null-ls"].setup({ + on_attach = function(client, bufnr) + -- Format on save. + if client.resolved_capabilities.document_formatting then + buf_set_keymap('n', 'fs', 'lua vim.lsp.buf.formatting_sync()', opts) + vim.cmd 'autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()' + end + end +}) + +trouble.setup({ + use_lsp_diagnostic_signs = true, + auto_close = true, + auto_open = true +}) -- cgit v1.2.3-18-g5258