chore(nvim): update LSP configuration and mappings

This commit is contained in:
Oliver Davies 2022-07-23 00:33:34 +01:00
parent 2a766fd148
commit 5000deb8b0
4 changed files with 65 additions and 10 deletions

View file

@ -39,13 +39,13 @@ local custom_attach = function(client)
buf_nnoremap { "<leader>ca", vim.lsp.buf.code_action } buf_nnoremap { "<leader>ca", vim.lsp.buf.code_action }
buf_nnoremap { "<leader>dn", vim.diagnostic.goto_next } buf_nnoremap { "<leader>dn", vim.diagnostic.goto_next }
buf_nnoremap { "<leader>dp", vim.diagnostic.goto_prev } buf_nnoremap { "<leader>dp", vim.diagnostic.goto_prev }
buf_nnoremap { "<leader>gD", vim.lsp.buf.declaration }
buf_nnoremap { "<leader>gT", vim.lsp.buf.type_definition }
buf_nnoremap { "<leader>gd", vim.lsp.buf.definition }
buf_nnoremap { "<leader>gi", vim.lsp.buf.implementation }
buf_nnoremap { "<leader>rn", vim.lsp.buf.rename } buf_nnoremap { "<leader>rn", vim.lsp.buf.rename }
buf_nnoremap { "<leader>rr", "<cmd>LspRestart<cr>" } buf_nnoremap { "<leader>rr", "<cmd>LspRestart<cr>" }
buf_nnoremap { "K", vim.lsp.buf.hover } buf_nnoremap { "K", vim.lsp.buf.hover }
buf_nnoremap { "gD", vim.lsp.buf.declaration }
buf_nnoremap { "gT", vim.lsp.buf.type_definition }
buf_nnoremap { "gd", vim.lsp.buf.definition }
buf_nnoremap { "gi", vim.lsp.buf.implementation }
if filetype ~= "lua" then if filetype ~= "lua" then
buf_nnoremap { "K", vim.lsp.buf.hover } buf_nnoremap { "K", vim.lsp.buf.hover }
@ -154,12 +154,12 @@ for server, config in pairs(servers) do
setup_server(server, config) setup_server(server, config)
end end
vim.diagnostic.config({ vim.diagnostic.config {
signs = true, signs = true,
underline = false, underline = false,
update_in_insert = false, update_in_insert = false,
virtual_text = { spacing = 2 }, virtual_text = { spacing = 2 },
}) }
require "opdavies.lsp.null-ls" require "opdavies.lsp.null-ls"
require "opdavies.lsp.signature" require "opdavies.lsp.signature"

View file

@ -3,21 +3,47 @@ if not status_ok then
return return
end end
local lsp_formatting = function(bufnr)
vim.lsp.buf.format {
filter = function(client)
return client.name == "null-ls"
end,
bufnr = bufnr,
}
end
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local completion = null_ls.builtins.completion local completion = null_ls.builtins.completion
local diagnostics = null_ls.builtins.diagnostics local diagnostics = null_ls.builtins.diagnostics
local formatting = null_ls.builtins.formatting local formatting = null_ls.builtins.formatting
null_ls.setup { null_ls.setup {
on_attach = function(client, bufnr)
if client.supports_method "textDocument/formatting" then
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
lsp_formatting(bufnr)
end,
group = augroup,
})
end
end,
sources = { sources = {
formatting.phpcbf,
formatting.markdownlint,
formatting.prettier, formatting.prettier,
formatting.rustywind, formatting.rustywind,
formatting.stylua, formatting.stylua,
diagnostics.eslint, diagnostics.eslint,
diagnostics.markdownlint,
diagnostics.php, diagnostics.php,
diagnostics.phpcs, diagnostics.phpcs,
diagnostics.phpstan, diagnostics.phpstan,
diagnostics.shellcheck,
completion.spell,
}, },
} }

View file

@ -18,7 +18,23 @@ function M.current_buf()
previewer = false, previewer = false,
} }
require "telescope.builtin".current_buffer_fuzzy_find(opts) require("telescope.builtin").current_buffer_fuzzy_find(opts)
end
M.diagnostics = function()
local theme = require("telescope.themes").get_dropdown {
previewer = false,
}
require("telescope.builtin").diagnostics(theme)
end
function M.lsp_document_symbols()
local theme = require("telescope.themes").get_dropdown {
previewer = false,
}
require("telescope.builtin").lsp_document_symbols(theme)
end end
function M.edit_neovim() function M.edit_neovim()
@ -50,7 +66,7 @@ end
function M.file_browser() function M.file_browser()
local opts = { local opts = {
cwd = vim.fn.expand "%:p:h", cwd = vim.fn.expand "%:p:h",
sorting_strategy = "ascending" sorting_strategy = "ascending",
} }
require("telescope").extensions.file_browser.file_browser(opts) require("telescope").extensions.file_browser.file_browser(opts)
@ -66,6 +82,16 @@ function M.fd()
require("telescope.builtin").find_files(opts) require("telescope.builtin").find_files(opts)
end end
function M.git_files()
local opts = themes.get_ivy {
file_ignore_patterns = { ".git/", "vendor" },
hidden = true,
no_ignore = true,
}
require("telescope.builtin").git_files(opts)
end
function M.live_grep() function M.live_grep()
require("telescope.builtin").live_grep { require("telescope.builtin").live_grep {
file_ignore_patterns = { ".git/" }, file_ignore_patterns = { ".git/" },

View file

@ -28,6 +28,9 @@ telescope_mapper("<leader>fg", "git_files")
telescope_mapper("<leader>fh", "help_tags") telescope_mapper("<leader>fh", "help_tags")
telescope_mapper("<leader>fl", "live_grep") telescope_mapper("<leader>fl", "live_grep")
telescope_mapper("<leader>ds", "lsp_document_symbols")
telescope_mapper("<leader>dl", "diagnostics")
telescope_mapper("<leader>en", "edit_neovim") telescope_mapper("<leader>en", "edit_neovim")
telescope_mapper("<leader>ez", "edit_zsh") telescope_mapper("<leader>ez", "edit_zsh")