From 8a113cfce8671659d7be2488e2ff0c6be12b606a Mon Sep 17 00:00:00 2001 From: Roel de Cort Date: Thu, 18 Apr 2024 00:12:34 +0200 Subject: [PATCH] add lsp, update neo-tree config and add bufferline --- config/default.nix | 8 +++ config/plugins/editor/neo-tree.nix | 12 ++-- config/plugins/lsp/conform.nix | 23 ++++++++ config/plugins/lsp/lsp.nix | 94 ++++++++++++++++++++++++++++++ config/plugins/lsp/none-ls.nix | 50 ++++++++++++++++ config/plugins/ui/bufferline.nix | 90 ++++++++++++++++++++++++++++ 6 files changed, 270 insertions(+), 7 deletions(-) create mode 100644 config/plugins/lsp/conform.nix create mode 100644 config/plugins/lsp/lsp.nix create mode 100644 config/plugins/lsp/none-ls.nix create mode 100644 config/plugins/ui/bufferline.nix diff --git a/config/default.nix b/config/default.nix index 212d1e5..c5c75ac 100644 --- a/config/default.nix +++ b/config/default.nix @@ -12,6 +12,14 @@ ./plugins/editor/neo-tree.nix ./plugins/editor/treesitter.nix + # UI plugins + ./plugins/ui/bufferline.nix + + # LSP + ./plugins/lsp/lsp.nix + ./plugins/lsp/conform.nix + ./plugins/lsp/none-ls.nix + # Git ./plugins/git/lazygit.nix diff --git a/config/plugins/editor/neo-tree.nix b/config/plugins/editor/neo-tree.nix index 72488b8..a17edcc 100644 --- a/config/plugins/editor/neo-tree.nix +++ b/config/plugins/editor/neo-tree.nix @@ -1,14 +1,13 @@ -{ pkgs, ... }: { - +{ plugins.neo-tree = { enable = true; - sources = [ "filesystem" "buffers" "git_status" "document_symbols" ]; - addBlankLineAtTop = true; - + sources = ["filesystem" "buffers" "git_status" "document_symbols"]; + addBlankLineAtTop = false; + filesystem = { bindToCwd = false; }; - + defaultComponentConfigs = { indent = { expanderCollapsed = ""; @@ -17,5 +16,4 @@ }; }; }; - } diff --git a/config/plugins/lsp/conform.nix b/config/plugins/lsp/conform.nix new file mode 100644 index 0000000..a796a48 --- /dev/null +++ b/config/plugins/lsp/conform.nix @@ -0,0 +1,23 @@ +{ + plugins.conform-nvim = { + enable = true; + formatOnSave = { + lspFallback = true; + timeoutMs = 500; + }; + notifyOnError = true; + formattersByFt = { + liquidsoap = ["liquidsoap-prettier"]; + html = [["prettierd" "prettier"]]; + css = [["prettierd" "prettier"]]; + javascript = [["prettierd" "prettier"]]; + typescript = [["prettierd" "prettier"]]; + python = ["black"]; + lua = ["stylua"]; + nix = ["alejandra"]; + markdown = [["prettierd" "prettier"]]; + yaml = ["yamllint" "yamlfmt"]; + terraform = ["terraform-fmt"]; + }; + }; +} diff --git a/config/plugins/lsp/lsp.nix b/config/plugins/lsp/lsp.nix new file mode 100644 index 0000000..fde4eb3 --- /dev/null +++ b/config/plugins/lsp/lsp.nix @@ -0,0 +1,94 @@ +{ + plugins = { + lsp-format = {enable = true;}; + lsp = { + enable = true; + servers = { + html = {enable = true;}; + lua-ls = {enable = true;}; + nil_ls = {enable = true;}; + marksman = {enable = true;}; + pyright = {enable = true;}; + gopls = {enable = true;}; + terraformls = {enable = true;}; + tsserver = {enable = true;}; + ansiblels = {enable = true;}; + yamlls = {enable = true;}; + }; + keymaps = { + silent = true; + lspBuf = { + gd = { + action = "definition"; + desc = "Goto Definition"; + }; + gr = { + action = "references"; + desc = "Goto References"; + }; + gD = { + action = "declaration"; + desc = "Goto Declaration"; + }; + gI = { + action = "implementation"; + desc = "Goto Implementation"; + }; + gT = { + action = "type_definition"; + desc = "Type Definition"; + }; + K = { + action = "hover"; + desc = "Hover"; + }; + "cw" = { + action = "workspace_symbol"; + desc = "Workspace Symbol"; + }; + "cr" = { + action = "rename"; + desc = "Rename"; + }; + }; + diagnostic = { + "cd" = { + action = "open_float"; + desc = "Line Diagnostics"; + }; + "[d" = { + action = "goto_next"; + desc = "Next Diagnostic"; + }; + "]d" = { + action = "goto_prev"; + desc = "Previous Diagnostic"; + }; + }; + }; + }; + }; + extraConfigLua = '' + local _border = "rounded" + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( + vim.lsp.handlers.hover, { + border = _border + } + ) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( + vim.lsp.handlers.signature_help, { + border = _border + } + ) + + vim.diagnostic.config{ + float={border=_border} + }; + + require('lspconfig.ui.windows').default_options = { + border = _border + } + ''; +} diff --git a/config/plugins/lsp/none-ls.nix b/config/plugins/lsp/none-ls.nix new file mode 100644 index 0000000..d7c4245 --- /dev/null +++ b/config/plugins/lsp/none-ls.nix @@ -0,0 +1,50 @@ +{ + plugins.none-ls = { + enable = true; + enableLspFormat = true; + updateInInsert = false; + sources = { + code_actions = { + gitsigns.enable = true; + statix.enable = true; + }; + diagnostics = { + statix.enable = true; + yamllint.enable = true; + }; + formatting = { + alejandra.enable = true; + black = { + enable = true; + withArgs = '' + { + extra_args = { "--fast" }, + } + ''; + }; + prettier = { + enable = true; + disableTsServerFormatter = true; + withArgs = '' + { + extra_args = { "--no-semi", "--single-quote" }, + } + ''; + }; + stylua.enable = true; + yamlfmt.enable = true; + }; + }; + }; + keymaps = [ + { + mode = ["n" "v"]; + key = "cf"; + action = "lua vim.lsp.buf.format()"; + options = { + silent = true; + desc = "Format"; + }; + } + ]; +} diff --git a/config/plugins/ui/bufferline.nix b/config/plugins/ui/bufferline.nix new file mode 100644 index 0000000..542c777 --- /dev/null +++ b/config/plugins/ui/bufferline.nix @@ -0,0 +1,90 @@ +{ config, ... }: { + + plugins = { + bufferline = { + enable = true; + }; + }; + keymaps = [ + { + mode = "n"; + key = "]b"; + action = "BufferLineCycleNext"; + options = { + desc = "Cycle to next buffer"; + }; + } + + { + mode = "n"; + key = "[b"; + action = "BufferLineCyclePrev"; + options = { + desc = "Cycle to previous buffer"; + }; + } + + { + mode = "n"; + key = ""; + action = "BufferLineCycleNext"; + options = { + desc = "Cycle to next buffer"; + }; + } + + { + mode = "n"; + key = ""; + action = "BufferLineCyclePrev"; + options = { + desc = "Cycle to previous buffer"; + }; + } + + { + mode = "n"; + key = "bd"; + action = "bdelete"; + options = { + desc = "Delete buffer"; + }; + } + + { + mode = "n"; + key = "bl"; + action = "BufferLineCloseLeft"; + options = { + desc = "Delete buffers to the left"; + }; + } + + { + mode = "n"; + key = "bo"; + action = "BufferLineCloseOthers"; + options = { + desc = "Delete other buffers"; + }; + } + + { + mode = "n"; + key = "bp"; + action = "BufferLineTogglePin"; + options = { + desc = "Toggle pin"; + }; + } + + { + mode = "n"; + key = "bP"; + action = "BufferLineGroupClose ungrouped"; + options = { + desc = "Delete non-pinned buffers"; + }; + } + ]; +}