nvim: formatting

This commit is contained in:
Moritz Böhme 2023-02-18 16:25:09 +01:00
parent eb77aa8823
commit b26149af98
Signed by: moritz
GPG key ID: 970C6E89EB0547A9
2 changed files with 39 additions and 39 deletions

View file

@ -54,12 +54,12 @@ in
copilot-cmp
copilot-lua
dashboard-nvim
formatter-nvim
lsp_lines-nvim
lspkind-nvim
lualine-lsp-progress
lualine-nvim
luasnip
formatter-nvim
neogit
noice-nvim
nui-nvim # for noice-nvim

View file

@ -206,39 +206,53 @@ wk.register({
["="] = { "<cmd>Format<cr>", "format (formatter)" },
}, { noremap = true, silent = true })
local lsp_lines = require("lsp_lines")
lsp_lines.setup()
-- Disable virtual_text since it's redundant due to lsp_lines.
vim.diagnostic.config({
virtual_text = false,
})
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig")
local on_attach_def = function(client, bufnr)
local options = { noremap = true, silent = true } -- default options
local buffer_options = table_merge(options, { buffer = bufnr }) -- buffer specific options
local on_attach_def = function(_, bufnr)
local options = { noremap = true, silent = true, buffer = bufnr }
-- set format keybinding
-- prefere lsp formatting over external formatter
if client.server_capabilities.documentFormattingProvider then
local modes = { "n", "v" }
for _, mode in ipairs(modes) do
wk.register({
["="] = {
wk.register({
K = { vim.lsp.buf.hover, "show info" },
["<leader>"] = {
l = {
name = "lsp",
d = { vim.diagnostic.open_float, "open diagnostic window" },
n = { vim.diagnostic.goto_next, "next error" },
p = { vim.diagnostic.goto_prev, "prev error" },
c = { vim.lsp.buf.code_action, "code action" },
r = { vim.lsp.buf.rename, "rename" },
f = {
function()
vim.lsp.buf.format({ async = true })
end,
"format (lsp)",
mode = { "n", "v" },
},
}, table_merge(buffer_options, { mode = mode }))
end
end
wk.register({
K = { vim.lsp.buf.hover, "show info" },
["<leader>l"] = {
name = "lsp",
d = { vim.diagnostic.open_float, "open diagnostic window" },
n = { vim.diagnostic.goto_next, "next error" },
p = { vim.diagnostic.goto_prev, "prev error" },
c = { vim.lsp.buf.code_action, "code action" },
r = { vim.lsp.buf.rename, "rename" },
},
w = {
name = "workspace",
a = { vim.lsp.buf.add_workspace_folder, "add workspace folder" },
r = { vim.lsp.buf.remove_workspace_folder, "remove workspace folder" },
l = {
function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end,
"list workspace folders",
},
},
t = {
name = "toggle",
l = { lsp_lines.toggle, "lsp lines" },
},
},
g = {
name = "goto",
@ -248,7 +262,7 @@ local on_attach_def = function(client, bufnr)
i = { vim.lsp.buf.implementation, "implementation" },
t = { vim.lsp.buf.type_definition, "type defininition" },
},
}, buffer_options)
}, options)
end
local lspconfig_default_options = {
@ -302,20 +316,6 @@ lspconfig_setup("lua_ls", {
},
})
local lsp_lines = require("lsp_lines")
lsp_lines.setup()
-- Disable virtual_text since it's redundant due to lsp_lines.
vim.diagnostic.config({
virtual_text = false,
})
wk.register({
t = {
name = "toggle",
l = { lsp_lines.toggle, "lsp lines" },
},
{ prefix = "<leader>" },
})
require("dashboard").setup({
theme = "hyper",
config = {