From b26149af9834734892973b5cce47ee10954eca9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sat, 18 Feb 2023 16:25:09 +0100 Subject: [PATCH] nvim: formatting --- modules/programs/nvim/default.nix | 2 +- modules/programs/nvim/init.lua | 76 +++++++++++++++---------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index c6a02ad..6a400f1 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -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 diff --git a/modules/programs/nvim/init.lua b/modules/programs/nvim/init.lua index 3326708..e4b557a 100644 --- a/modules/programs/nvim/init.lua +++ b/modules/programs/nvim/init.lua @@ -206,39 +206,53 @@ wk.register({ ["="] = { "Format", "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" }, + [""] = { + 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" }, - ["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 = "" }, -}) - require("dashboard").setup({ theme = "hyper", config = {