nvim: formatting

nixos
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 wk.register({
-- prefere lsp formatting over external formatter K = { vim.lsp.buf.hover, "show info" },
if client.server_capabilities.documentFormattingProvider then ["<leader>"] = {
local modes = { "n", "v" } l = {
for _, mode in ipairs(modes) do name = "lsp",
wk.register({ 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() function()
vim.lsp.buf.format({ async = true }) vim.lsp.buf.format({ async = true })
end, end,
"format (lsp)", "format (lsp)",
mode = { "n", "v" },
}, },
}, table_merge(buffer_options, { mode = mode })) },
end w = {
end name = "workspace",
a = { vim.lsp.buf.add_workspace_folder, "add workspace folder" },
wk.register({ r = { vim.lsp.buf.remove_workspace_folder, "remove workspace folder" },
K = { vim.lsp.buf.hover, "show info" }, l = {
["<leader>l"] = { function()
name = "lsp", print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
d = { vim.diagnostic.open_float, "open diagnostic window" }, end,
n = { vim.diagnostic.goto_next, "next error" }, "list workspace folders",
p = { vim.diagnostic.goto_prev, "prev error" }, },
c = { vim.lsp.buf.code_action, "code action" }, },
r = { vim.lsp.buf.rename, "rename" }, 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 = {