nvim lua lsp

This commit is contained in:
Henrik Bakken
2023-03-15 22:58:58 +01:00
parent aabf98b206
commit c2a4cfdae0
+109 -47
View File
@@ -18,14 +18,14 @@ end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
require("lazy").setup({ require("lazy").setup({
-- tpope -- tpope
"tpope/vim-sensible", -- sensible default "tpope/vim-sensible", -- sensible default
"tpope/vim-commentary", -- comment out stuff "tpope/vim-commentary", -- comment out stuff
"tpope/vim-surround", "tpope/vim-surround",
"tpope/vim-repeat", -- repeat vim-surround with . "tpope/vim-repeat", -- repeat vim-surround with .
"tpope/vim-eunuch", -- Move, Rename etc "tpope/vim-eunuch", -- Move, Rename etc
-- div utils -- div utils
"dhruvasagar/vim-table-mode", -- tables "dhruvasagar/vim-table-mode", -- tables
"itchyny/vim-qfedit", -- editable quickfix list "itchyny/vim-qfedit", -- editable quickfix list
{ {
-- keep location upon reopening -- keep location upon reopening
"ethanholz/nvim-lastplace", "ethanholz/nvim-lastplace",
@@ -41,7 +41,7 @@ require("lazy").setup({
vim.g.tmux_navigator_no_mappings = 1 vim.g.tmux_navigator_no_mappings = 1
vim.g.tmux_navigator_disable_when_zoomed = 1 vim.g.tmux_navigator_disable_when_zoomed = 1
local map = vim.keymap.set 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-h>", ":TmuxNavigateLeft<cr>", opts)
map("n", "<M-j>", ":TmuxNavigateDown<cr>", opts) map("n", "<M-j>", ":TmuxNavigateDown<cr>", opts)
map("n", "<M-k>", ":TmuxNavigateUp<cr>", opts) map("n", "<M-k>", ":TmuxNavigateUp<cr>", opts)
@@ -60,8 +60,8 @@ require("lazy").setup({
vim.fn["mkdp#util#install"]() vim.fn["mkdp#util#install"]()
end, end,
config = function() config = function()
vim.g.mkdp_auto_start = 0 -- auto start on moving into vim.g.mkdp_auto_start = 0 -- auto start on moving into
vim.g.mkdp_auto_close = 0 -- auto close on moving away vim.g.mkdp_auto_close = 0 -- auto close on moving away
vim.g.mkdp_open_to_the_world = 1 -- available to others vim.g.mkdp_open_to_the_world = 1 -- available to others
vim.g.mkdp_port = 8555 vim.g.mkdp_port = 8555
vim.g.mkdp_echo_preview_url = 1 vim.g.mkdp_echo_preview_url = 1
@@ -148,8 +148,8 @@ require("lazy").setup({
}, },
{ "diff", colored = true }, { "diff", colored = true },
}, },
lualine_x = { "filetype" }, lualine_x = {},
lualine_y = { "progress" }, lualine_y = { "filetype", "progress" },
lualine_z = { "location" }, lualine_z = { "location" },
}, },
inactive_sections = { inactive_sections = {
@@ -165,7 +165,7 @@ require("lazy").setup({
{ "diff", colored = true }, { "diff", colored = true },
}, },
lualine_x = {}, lualine_x = {},
lualine_y = { "progress" }, lualine_y = { "filetype", "progress" },
lualine_z = { "location" }, lualine_z = { "location" },
}, },
}) })
@@ -188,7 +188,7 @@ require("lazy").setup({
config = function() config = function()
local map = vim.keymap.set local map = vim.keymap.set
map("", "<C-g>", ":vertical Git<cr>:vertical resize 60<cr>", {}) 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<cr>", {})
map("", "<leader>gP", ":Git push -f<cr>", {}) map("", "<leader>gP", ":Git push -f<cr>", {})
end, end,
@@ -208,12 +208,14 @@ require("lazy").setup({
signcolumn = true, signcolumn = true,
numhl = true, numhl = true,
linehl = false, linehl = false,
word_diff = true, word_diff = false,
on_attach = function(bufnr) on_attach = function(bufnr)
local gs = package.loaded.gitsigns local gs = package.loaded.gitsigns
local function map(mode, l, r) local function map(mode, l, r, opts)
vim.keymap.set(mode, l, r, { buffer = bufnr }) opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end end
-- Navigation -- Navigation
@@ -239,7 +241,7 @@ require("lazy").setup({
-- Actions -- Actions
map({ "n", "v" }, "<leader>gs", ":Gitsigns stage_hunk<CR>") 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>gu", gs.undo_stage_hunk)
map("n", "<leader>gi", gs.preview_hunk) map("n", "<leader>gi", gs.preview_hunk)
map("n", "<leader>gb", function() map("n", "<leader>gb", function()
@@ -265,7 +267,7 @@ require("lazy").setup({
dependencies = { "nvim-lua/plenary.nvim" }, dependencies = { "nvim-lua/plenary.nvim" },
config = function() config = function()
require("todo-comments").setup({ require("todo-comments").setup({
signs = true, -- show icons in the signs column signs = true, -- show icons in the signs column
sign_priority = 8, -- sign priority sign_priority = 8, -- sign priority
-- keywords recognized as todo comments -- keywords recognized as todo comments
keywords = { keywords = {
@@ -340,6 +342,7 @@ require("lazy").setup({
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
version = "*", version = "*",
dependencies = { dependencies = {
"sharkdp/fd",
"nvim-lua/plenary.nvim", "nvim-lua/plenary.nvim",
"nvim-telescope/telescope-live-grep-args.nvim", "nvim-telescope/telescope-live-grep-args.nvim",
}, },
@@ -447,9 +450,9 @@ require("lazy").setup({
dependencies = { "nvim-treesitter/nvim-treesitter" }, dependencies = { "nvim-treesitter/nvim-treesitter" },
config = function() config = function()
require("treesitter-context").setup({ require("treesitter-context").setup({
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands) enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
throttle = true, -- Throttles plugin updates (may improve performance) throttle = true, -- Throttles plugin updates (may improve performance)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit. max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
patterns = { patterns = {
default = { default = {
"class", "class",
@@ -501,21 +504,34 @@ require("lazy").setup({
"jose-elias-alvarez/null-ls.nvim", "jose-elias-alvarez/null-ls.nvim",
dependencies = { "nvim-lua/plenary.nvim" }, dependencies = { "nvim-lua/plenary.nvim" },
config = function() config = function()
-- local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local null_ls = require("null-ls") local null_ls = require("null-ls")
null_ls.setup({ null_ls.setup({
sources = { sources = {
null_ls.builtins.completion.spell,
null_ls.builtins.diagnostics.mypy, null_ls.builtins.diagnostics.mypy,
null_ls.builtins.diagnostics.eslint_d, 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.eslint_d,
null_ls.builtins.formatting.isort, null_ls.builtins.formatting.isort,
null_ls.builtins.formatting.jq, null_ls.builtins.formatting.jq,
null_ls.builtins.formatting.prettierd, 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.yamlfmt,
null_ls.builtins.formatting.yq, 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, end,
}, },
@@ -529,7 +545,7 @@ require("lazy").setup({
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
}, },
config = function() config = function()
on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
local bmap = function(mode, keys, func) local bmap = function(mode, keys, func)
vim.keymap.set(mode, keys, func, { buffer = bufnr, noremap = true }) vim.keymap.set(mode, keys, func, { buffer = bufnr, noremap = true })
end end
@@ -541,9 +557,15 @@ require("lazy").setup({
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end) end)
-- jump -- jump
bmap("n", "<M-i>", vim.diagnostic.open_float) bmap("n", "<M-i>", function()
bmap("n", "<M-n>", vim.diagnostic.goto_next) vim.diagnostic.open_float({ source = true })
bmap("n", "<M-p>", vim.diagnostic.goto_prev) 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.definition)
bmap("n", "gD", vim.lsp.buf.type_definition) bmap("n", "gD", vim.lsp.buf.type_definition)
bmap("n", "gi", vim.lsp.buf.declaration) bmap("n", "gi", vim.lsp.buf.declaration)
@@ -556,18 +578,18 @@ require("lazy").setup({
-- other -- other
bmap("n", "K", vim.lsp.buf.hover) bmap("n", "K", vim.lsp.buf.hover)
bmap("n", "<M-r>", vim.lsp.buf.rename) 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) bmap("n", "<leader>ca", vim.lsp.buf.code_action)
vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) 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" }) end, { desc = "Format current buffer with LSP" })
bmap("n", "<leader>f", ":Format<cr>")
if if
client.server_capabilities.documentFormattingProvider client.server_capabilities.documentFormattingProvider
or client.server_capabilities.documentRangeFormattingProvider or client.server_capabilities.documentRangeFormattingProvider
then then
vim.api.nvim_command([[augroup Format]]) vim.api.nvim_command([[augroup Format]])
vim.api.nvim_command([[autocmd! * <buffer>]]) 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]]) vim.api.nvim_command([[augroup END]])
end end
end end
@@ -586,8 +608,19 @@ require("lazy").setup({
}, },
lua_ls = { lua_ls = {
Lua = { 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 }, telemetry = { enable = false },
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
format = { -- disable formatting, stylua handles it
enable = false,
},
}, },
}, },
marksman = {}, marksman = {},
@@ -597,7 +630,6 @@ require("lazy").setup({
html = {}, html = {},
eslint = {}, eslint = {},
dockerls = {}, dockerls = {},
docker_compose_language_service = {},
cssls = {}, cssls = {},
bashls = {}, bashls = {},
} }
@@ -622,6 +654,33 @@ require("lazy").setup({
}) })
end, 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" },
},
}) })
-- ---------------------------------------- -- ----------------------------------------
@@ -663,11 +722,11 @@ vim.o.splitbelow = true -- Put new windows below current
vim.o.splitright = true -- Put new windows right of current vim.o.splitright = true -- Put new windows right of current
-- buffer -- buffer
vim.o.hidden = true -- Enable background buffers vim.o.hidden = true -- Enable background buffers
vim.o.wrap = false -- Disable line wrap vim.o.wrap = false -- Disable line wrap
vim.o.number = true -- Show line numbers vim.o.number = true -- Show line numbers
vim.o.relativenumber = true -- Relative line numbers vim.o.relativenumber = true -- Relative line numbers
vim.o.cursorline = false -- Highlight current line vim.o.cursorline = false -- Highlight current line
vim.o.switchbuf = "useopen" -- Use existing window if buffer is already open vim.o.switchbuf = "useopen" -- Use existing window if buffer is already open
vim.o.colorcolumn = "88" vim.o.colorcolumn = "88"
@@ -675,16 +734,16 @@ vim.o.colorcolumn = "88"
vim.o.diffopt = "internal,filler,closeoff,hiddenoff,vertical,algorithm:patience" vim.o.diffopt = "internal,filler,closeoff,hiddenoff,vertical,algorithm:patience"
-- tabs -- tabs
vim.o.expandtab = true -- Use spaces instead of tabs vim.o.expandtab = true -- Use spaces instead of tabs
vim.o.smartindent = false -- Avoid fucking with comment indents vim.o.smartindent = false -- Avoid fucking with comment indents
vim.o.shiftround = true -- Round indent vim.o.shiftround = true -- Round indent
vim.o.tabstop = 4 -- Number of spaces tabs count for vim.o.tabstop = 4 -- Number of spaces tabs count for
vim.o.shiftwidth = 4 -- Size of an indent vim.o.shiftwidth = 4 -- Size of an indent
vim.o.breakindent = true -- line breaks follow indents vim.o.breakindent = true -- line breaks follow indents
-- search -- search
vim.o.ignorecase = false -- Ignore case vim.o.ignorecase = false -- Ignore case
vim.o.smartcase = false -- Do not ignore case with capitals vim.o.smartcase = false -- Do not ignore case with capitals
vim.o.wildignorecase = true vim.o.wildignorecase = true
vim.opt.wildmode = { "full" } -- Command-line completion mode vim.opt.wildmode = { "full" } -- Command-line completion mode
vim.opt.wildignore = vim.opt.wildignore vim.opt.wildignore = vim.opt.wildignore
@@ -703,10 +762,10 @@ vim.opt.wildignore = vim.opt.wildignore
} }
-- cursor -- cursor
vim.o.scrolloff = 5 -- Lines of context vim.o.scrolloff = 5 -- Lines of context
vim.o.scrolljump = 1 -- Lines to scroll when cursor leaves screen vim.o.scrolljump = 1 -- Lines to scroll when cursor leaves screen
vim.o.sidescrolloff = 4 -- Columns of context vim.o.sidescrolloff = 4 -- Columns of context
vim.o.showmatch = true -- Show matching brackets / parentheses vim.o.showmatch = true -- Show matching brackets / parentheses
-- editing -- editing
vim.o.timeoutlen = 500 -- How long to wait during key combo vim.o.timeoutlen = 500 -- How long to wait during key combo
@@ -731,7 +790,7 @@ local cmd = vim.cmd
vim.api.nvim_command([[augroup MYAU]]) vim.api.nvim_command([[augroup MYAU]])
vim.api.nvim_command([[autocmd!]]) 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 FileType python setlocal indentkeys-=<:>]])
vim.api.nvim_command([[autocmd BufReadPost quickfix nmap <buffer> <cr> <cr>]]) vim.api.nvim_command([[autocmd BufReadPost quickfix nmap <buffer> <cr> <cr>]])
vim.api.nvim_command([[augroup END]]) 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", "<F4>", ":NullLsInfo<cr>", { noremap = true })
map("n", "<F5>", ":checkt<cr>", { noremap = true }) map("n", "<F5>", ":checkt<cr>", { noremap = true })
map("n", "<F6>", ":TodoQuickFix<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 })