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-cmp
copilot-lua copilot-lua
dashboard-nvim dashboard-nvim
formatter-nvim
lsp_lines-nvim lsp_lines-nvim
lspkind-nvim lspkind-nvim
lualine-lsp-progress lualine-lsp-progress
lualine-nvim lualine-nvim
luasnip luasnip
formatter-nvim
neogit neogit
noice-nvim noice-nvim
nui-nvim # for noice-nvim nui-nvim # for noice-nvim

View file

@ -206,39 +206,53 @@ wk.register({
["="] = { "<cmd>Format<cr>", "format (formatter)" }, ["="] = { "<cmd>Format<cr>", "format (formatter)" },
}, { noremap = true, silent = true }) }, { 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.. -- 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 capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
local on_attach_def = function(client, bufnr) local on_attach_def = function(_, bufnr)
local options = { noremap = true, silent = true } -- default options local options = { noremap = true, silent = true, buffer = bufnr }
local buffer_options = table_merge(options, { buffer = bufnr }) -- buffer specific options
-- 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({
["="] = {
function()
vim.lsp.buf.format({ async = true })
end,
"format (lsp)",
},
}, table_merge(buffer_options, { mode = mode }))
end
end
wk.register({ wk.register({
K = { vim.lsp.buf.hover, "show info" }, K = { vim.lsp.buf.hover, "show info" },
["<leader>l"] = { ["<leader>"] = {
l = {
name = "lsp", name = "lsp",
d = { vim.diagnostic.open_float, "open diagnostic window" }, d = { vim.diagnostic.open_float, "open diagnostic window" },
n = { vim.diagnostic.goto_next, "next error" }, n = { vim.diagnostic.goto_next, "next error" },
p = { vim.diagnostic.goto_prev, "prev error" }, p = { vim.diagnostic.goto_prev, "prev error" },
c = { vim.lsp.buf.code_action, "code action" }, c = { vim.lsp.buf.code_action, "code action" },
r = { vim.lsp.buf.rename, "rename" }, r = { vim.lsp.buf.rename, "rename" },
f = {
function()
vim.lsp.buf.format({ async = true })
end,
"format (lsp)",
mode = { "n", "v" },
},
},
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 = { g = {
name = "goto", name = "goto",
@ -248,7 +262,7 @@ local on_attach_def = function(client, bufnr)
i = { vim.lsp.buf.implementation, "implementation" }, i = { vim.lsp.buf.implementation, "implementation" },
t = { vim.lsp.buf.type_definition, "type defininition" }, t = { vim.lsp.buf.type_definition, "type defininition" },
}, },
}, buffer_options) }, options)
end end
local lspconfig_default_options = { 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({ require("dashboard").setup({
theme = "hyper", theme = "hyper",
config = { config = {