nvim lua lsp

This commit is contained in:
Henrik Bakken
2023-03-15 22:58:58 +01:00
parent aabf98b206
commit c2a4cfdae0
+85 -23
View File
@@ -41,7 +41,7 @@ require("lazy").setup({
vim.g.tmux_navigator_no_mappings = 1
vim.g.tmux_navigator_disable_when_zoomed = 1
local map = vim.keymap.set
opts = { silent = true, noremap = true }
local opts = { silent = true, noremap = true }
map("n", "<M-h>", ":TmuxNavigateLeft<cr>", opts)
map("n", "<M-j>", ":TmuxNavigateDown<cr>", opts)
map("n", "<M-k>", ":TmuxNavigateUp<cr>", opts)
@@ -148,8 +148,8 @@ require("lazy").setup({
},
{ "diff", colored = true },
},
lualine_x = { "filetype" },
lualine_y = { "progress" },
lualine_x = {},
lualine_y = { "filetype", "progress" },
lualine_z = { "location" },
},
inactive_sections = {
@@ -165,7 +165,7 @@ require("lazy").setup({
{ "diff", colored = true },
},
lualine_x = {},
lualine_y = { "progress" },
lualine_y = { "filetype", "progress" },
lualine_z = { "location" },
},
})
@@ -188,7 +188,7 @@ require("lazy").setup({
config = function()
local map = vim.keymap.set
map("", "<C-g>", ":vertical Git<cr>:vertical resize 60<cr>", {})
map("", "<leader>gb", ":Git blame<cr>", {})
map("", "<leader>gB", ":Git blame<cr>", {})
map("", "<leader>gp", ":Git push<cr>", {})
map("", "<leader>gP", ":Git push -f<cr>", {})
end,
@@ -208,12 +208,14 @@ require("lazy").setup({
signcolumn = true,
numhl = true,
linehl = false,
word_diff = true,
word_diff = false,
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local function map(mode, l, r)
vim.keymap.set(mode, l, r, { buffer = bufnr })
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
@@ -239,7 +241,7 @@ require("lazy").setup({
-- Actions
map({ "n", "v" }, "<leader>gs", ":Gitsigns stage_hunk<CR>")
map({ "n", "v" }, "<leader>xr", ":Gitsigns reset_hunk<CR>")
map({ "n", "v" }, "<leader>gx", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>gu", gs.undo_stage_hunk)
map("n", "<leader>gi", gs.preview_hunk)
map("n", "<leader>gb", function()
@@ -340,6 +342,7 @@ require("lazy").setup({
"nvim-telescope/telescope.nvim",
version = "*",
dependencies = {
"sharkdp/fd",
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope-live-grep-args.nvim",
},
@@ -501,21 +504,34 @@ require("lazy").setup({
"jose-elias-alvarez/null-ls.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
-- local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.completion.spell,
null_ls.builtins.diagnostics.mypy,
null_ls.builtins.diagnostics.eslint_d,
null_ls.builtins.formatting.black.with({ extra_args = { "--preview" }, }),
null_ls.builtins.formatting.black.with({ extra_args = { "--preview" } }),
null_ls.builtins.formatting.eslint_d,
null_ls.builtins.formatting.isort,
null_ls.builtins.formatting.jq,
null_ls.builtins.formatting.prettierd,
null_ls.builtins.formatting.shfmt.with({ extra_args = { "--indent", "4" }, }),
null_ls.builtins.formatting.shfmt.with({ extra_args = { "--indent", "4" } }),
null_ls.builtins.formatting.stylua.with({ extra_args = { "--indent-type", "Spaces" } }),
null_ls.builtins.formatting.yamlfmt,
null_ls.builtins.formatting.yq,
},
-- 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", {
-- group = augroup,
-- buffer = bufnr,
-- callback = function()
-- vim.lsp.buf.format({ bufnr = bufnr })
-- end,
-- })
-- end
-- end,
})
end,
},
@@ -529,7 +545,7 @@ require("lazy").setup({
"hrsh7th/nvim-cmp",
},
config = function()
on_attach = function(client, bufnr)
local on_attach = function(client, bufnr)
local bmap = function(mode, keys, func)
vim.keymap.set(mode, keys, func, { buffer = bufnr, noremap = true })
end
@@ -541,9 +557,15 @@ require("lazy").setup({
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end)
-- jump
bmap("n", "<M-i>", vim.diagnostic.open_float)
bmap("n", "<M-n>", vim.diagnostic.goto_next)
bmap("n", "<M-p>", vim.diagnostic.goto_prev)
bmap("n", "<M-i>", function()
vim.diagnostic.open_float({ source = true })
end)
bmap("n", "<M-n>", function()
vim.diagnostic.goto_next({ severity = { min = vim.diagnostic.severity.INFO } })
end)
bmap("n", "<M-p>", function()
vim.diagnostic.goto_prev({ severity = { min = vim.diagnostic.severity.INFO } })
end)
bmap("n", "gd", vim.lsp.buf.definition)
bmap("n", "gD", vim.lsp.buf.type_definition)
bmap("n", "gi", vim.lsp.buf.declaration)
@@ -556,18 +578,18 @@ require("lazy").setup({
-- other
bmap("n", "K", vim.lsp.buf.hover)
bmap("n", "<M-r>", vim.lsp.buf.rename)
bmap("n", "<leader>f", vim.lsp.buf.format)
bmap("n", "<leader>ca", vim.lsp.buf.code_action)
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
vim.lsp.buf.format()
vim.lsp.buf.format({ timeout_ms = 5000 })
end, { desc = "Format current buffer with LSP" })
bmap("n", "<leader>f", ":Format<cr>")
if
client.server_capabilities.documentFormattingProvider
or client.server_capabilities.documentRangeFormattingProvider
then
vim.api.nvim_command([[augroup Format]])
vim.api.nvim_command([[autocmd! * <buffer>]])
vim.api.nvim_command([[autocmd BufWritePre * lua vim.lsp.buf.format()]])
vim.api.nvim_command([[autocmd BufWritePre * lua vim.lsp.buf.format({ timeout_ms = 5000 })]])
vim.api.nvim_command([[augroup END]])
end
end
@@ -586,8 +608,19 @@ require("lazy").setup({
},
lua_ls = {
Lua = {
workspace = { checkThirdParty = false },
workspace = {
checkThirdParty = false,
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = { enable = false },
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
format = { -- disable formatting, stylua handles it
enable = false,
},
},
},
marksman = {},
@@ -597,7 +630,6 @@ require("lazy").setup({
html = {},
eslint = {},
dockerls = {},
docker_compose_language_service = {},
cssls = {},
bashls = {},
}
@@ -622,6 +654,33 @@ require("lazy").setup({
})
end,
},
{
"folke/noice.nvim",
config = function()
require("noice").setup({
lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true,
},
},
-- you can enable a preset for easier configuration
presets = {
bottom_search = false, -- use a classic bottom cmdline for search
command_palette = true, -- position the cmdline and popupmenu together
long_message_to_split = true, -- long messages will be sent to a split
inc_rename = false, -- enables an input dialog for inc-rename.nvim
lsp_doc_border = false, -- add a border to hover docs and signature help
},
messages = {
enabled = false,
},
})
end,
dependencies = { "MunifTanjim/nui.nvim" },
},
})
-- ----------------------------------------
@@ -731,7 +790,7 @@ local cmd = vim.cmd
vim.api.nvim_command([[augroup MYAU]])
vim.api.nvim_command([[autocmd!]])
vim.api.nvim_command([[autocmd BufWritePost * %s/\s\+$//e]])
vim.api.nvim_command([[autocmd BufWritePre * %s/\s\+$//e]])
vim.api.nvim_command([[autocmd FileType python setlocal indentkeys-=<:>]])
vim.api.nvim_command([[autocmd BufReadPost quickfix nmap <buffer> <cr> <cr>]])
vim.api.nvim_command([[augroup END]])
@@ -804,4 +863,7 @@ map("n", "<F3>", ":LspInfo<cr>", { noremap = true })
map("n", "<F4>", ":NullLsInfo<cr>", { noremap = true })
map("n", "<F5>", ":checkt<cr>", { noremap = true })
map("n", "<F6>", ":TodoQuickFix<cr>", { noremap = true })
map("n", "<F9>", '<cmd>lua require("telescope.builtin").colorscheme({enable_preview=1})<cr>', opts)
map("n", "<F9>", '<cmd>lua require("telescope.builtin").colorscheme({enable_preview=1})<cr>', { noremap = true })
-- shit HACK
map("n", "<leader>b", ":!blackdoc %<cr>", { noremap = true })