From 552e85b6b658ce01e7478840a0f296d215c5b06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Mon, 10 Jun 2024 18:30:00 +0200 Subject: [PATCH] feat: language injections --- modules/home-manager/programs/neovide.nix | 3 +- .../programs/nixvim/presets/auto-format.nix | 32 +++++++------ .../programs/nixvim/presets/auto-save.nix | 38 +++++++-------- .../nixvim/presets/base/completion.nix | 15 ++++-- .../nixvim/presets/base/diagnostics.nix | 44 +++++++++--------- .../nixvim/presets/base/status-line.nix | 9 +++- .../programs/nixvim/presets/base/tree.nix | 11 +++-- .../programs/nixvim/presets/lazygit.nix | 46 ++++++++++--------- .../programs/nixvim/presets/trouble.nix | 15 ++++-- .../programs/nixvim/presets/undotree.nix | 3 +- 10 files changed, 122 insertions(+), 94 deletions(-) diff --git a/modules/home-manager/programs/neovide.nix b/modules/home-manager/programs/neovide.nix index 7053f4c..74e973c 100644 --- a/modules/home-manager/programs/neovide.nix +++ b/modules/home-manager/programs/neovide.nix @@ -22,7 +22,8 @@ }; }; programs.nixvim = { - extraConfigLua = "if vim.g.neovide then vim.opt.linespace = -1 end"; + extraConfigLua = # lua + "if vim.g.neovide then vim.opt.linespace = -1 end"; globals.neovide_cursor_vfx_mode = "pixiedust"; }; } diff --git a/modules/home-manager/programs/nixvim/presets/auto-format.nix b/modules/home-manager/programs/nixvim/presets/auto-format.nix index b351f2c..a8d4c1e 100644 --- a/modules/home-manager/programs/nixvim/presets/auto-format.nix +++ b/modules/home-manager/programs/nixvim/presets/auto-format.nix @@ -18,15 +18,16 @@ in config = lib.mkIf cfg.enable { userCommands.${cfg.commandName} = { command = { - __raw = '' - function(args) - if args.bang then - vim.b.${cfg.varName} = not vim.b.${cfg.varName} - else - vim.g.${cfg.varName} = not vim.g.${cfg.varName} + __raw = # lua + '' + function(args) + if args.bang then + vim.b.${cfg.varName} = not vim.b.${cfg.varName} + else + vim.g.${cfg.varName} = not vim.g.${cfg.varName} + end end - end - ''; + ''; }; }; @@ -54,14 +55,15 @@ in }; }; - conform-nvim.formatAfterSave = '' - function(bufnr) - if vim.g.${cfg.varName} or vim.b[bufnr].${cfg.varName} then - return + conform-nvim.formatAfterSave = # lua + '' + function(bufnr) + if vim.g.${cfg.varName} or vim.b[bufnr].${cfg.varName} then + return + end + return { timeout_ms = 500, lsp_fallback = true }; end - return { timeout_ms = 500, lsp_fallback = true }; - end - ''; + ''; lualine.sections.lualine_x = lib.mkOrder 600 [ "(vim.g.${cfg.varName} or vim.b.${cfg.varName}) and '󱌓' or nil" diff --git a/modules/home-manager/programs/nixvim/presets/auto-save.nix b/modules/home-manager/programs/nixvim/presets/auto-save.nix index e52b933..dd424bf 100644 --- a/modules/home-manager/programs/nixvim/presets/auto-save.nix +++ b/modules/home-manager/programs/nixvim/presets/auto-save.nix @@ -23,18 +23,19 @@ in }; config = lib.mkIf cfg.enable { - extraConfigLua = '' - function AutoSave() - if not vim.b.${cfg.varName} and not vim.g.${cfg.varName} then - local bufnr = vim.api.nvim_get_current_buf() - local modified = vim.api.nvim_buf_get_option(bufnr, 'modified') - if modified then - vim.cmd('silent! w') - print("Auto save at " .. os.date("%H:%M:%S")) + extraConfigLua = # lua + '' + function AutoSave() + if not vim.b.${cfg.varName} and not vim.g.${cfg.varName} then + local bufnr = vim.api.nvim_get_current_buf() + local modified = vim.api.nvim_buf_get_option(bufnr, 'modified') + if modified then + vim.cmd('silent! w') + print("Auto save at " .. os.date("%H:%M:%S")) + end end end - end - ''; + ''; autoCmd = [ { @@ -47,15 +48,16 @@ in userCommands.${cfg.commandName} = { bang = true; command = { - __raw = '' - function(args) - if args.bang then - vim.b.${cfg.varName} = not vim.b.${cfg.varName} - else - vim.g.${cfg.varName} = not vim.g.${cfg.varName} + __raw = # lua + '' + function(args) + if args.bang then + vim.b.${cfg.varName} = not vim.b.${cfg.varName} + else + vim.g.${cfg.varName} = not vim.g.${cfg.varName} + end end - end - ''; + ''; }; }; diff --git a/modules/home-manager/programs/nixvim/presets/base/completion.nix b/modules/home-manager/programs/nixvim/presets/base/completion.nix index 5415c4e..919f739 100644 --- a/modules/home-manager/programs/nixvim/presets/base/completion.nix +++ b/modules/home-manager/programs/nixvim/presets/base/completion.nix @@ -18,10 +18,14 @@ in enable = true; settings = { mapping = { - "" = "cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select})"; - "" = "cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select})"; - "" = "cmp.mapping.confirm({select = true})"; - "" = "cmp.mapping.complete()"; + "" = # lua + "cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select})"; + "" = # lua + "cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select})"; + "" = # lua + "cmp.mapping.confirm({select = true})"; + "" = # lua + "cmp.mapping.complete()"; }; sources = [ { name = "path"; } @@ -34,7 +38,8 @@ in "abbr" "kind" ]; - snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end"; + snippet.expand = # lua + "function(args) require('luasnip').lsp_expand(args.body) end"; window = { completion.border = "rounded"; documentation.border = "rounded"; diff --git a/modules/home-manager/programs/nixvim/presets/base/diagnostics.nix b/modules/home-manager/programs/nixvim/presets/base/diagnostics.nix index b95f5b4..7690c61 100644 --- a/modules/home-manager/programs/nixvim/presets/base/diagnostics.nix +++ b/modules/home-manager/programs/nixvim/presets/base/diagnostics.nix @@ -13,36 +13,38 @@ in }; config = lib.mkIf cfg.enable { - extraConfigLua = '' - require("actions-preview").setup({}) + extraConfigLua = # lua + '' + require("actions-preview").setup({}) - local signs = { - { name = "DiagnosticSignError", text = "" }, - { name = "DiagnosticSignWarn", text = "" }, - { name = "DiagnosticSignHint", text = "󰌵" }, - { name = "DiagnosticSignInfo", text = "" }, - } + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "󰌵" }, + { name = "DiagnosticSignInfo", text = "" }, + } - for _, sign in ipairs(signs) do - vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) - end + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end - vim.diagnostic.config({ - virtual_text = true, - signs = true, - underline = true, - update_in_insert = true, - severity_sort = false, - }) - vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) - ''; + vim.diagnostic.config({ + virtual_text = true, + signs = true, + underline = true, + update_in_insert = true, + severity_sort = false, + }) + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) + ''; keymaps = [ { key = "sa"; mode = "n"; options.silent = true; lua = true; - action = "require('actions-preview').code_actions"; + action = # lua + "require('actions-preview').code_actions"; } { key = "sx"; diff --git a/modules/home-manager/programs/nixvim/presets/base/status-line.nix b/modules/home-manager/programs/nixvim/presets/base/status-line.nix index 1c39e45..97755e7 100644 --- a/modules/home-manager/programs/nixvim/presets/base/status-line.nix +++ b/modules/home-manager/programs/nixvim/presets/base/status-line.nix @@ -8,11 +8,18 @@ in }; config = lib.mkIf cfg.enable { + opts.showmode = false; plugins = { notify = { enable = true; - backgroundColour = "#000000"; + stages = "static"; }; + telescope = { + enable = true; + keymaps."n" = # vim + "notify"; + }; + which-key.registrations."n" = "Notifications"; lualine = { enable = true; globalstatus = true; diff --git a/modules/home-manager/programs/nixvim/presets/base/tree.nix b/modules/home-manager/programs/nixvim/presets/base/tree.nix index 31bea6d..952d508 100644 --- a/modules/home-manager/programs/nixvim/presets/base/tree.nix +++ b/modules/home-manager/programs/nixvim/presets/base/tree.nix @@ -23,11 +23,12 @@ in filteredItems.visible = true; }; popupBorderStyle = "rounded"; - eventHandlers.file_opened = '' - function() - require('neo-tree').close_all() - end - ''; + eventHandlers.file_opened = # lua + '' + function() + require('neo-tree').close_all() + end + ''; }; which-key.registrations."f".t = "Tree"; }; diff --git a/modules/home-manager/programs/nixvim/presets/lazygit.nix b/modules/home-manager/programs/nixvim/presets/lazygit.nix index e4f707f..c24c878 100644 --- a/modules/home-manager/programs/nixvim/presets/lazygit.nix +++ b/modules/home-manager/programs/nixvim/presets/lazygit.nix @@ -21,33 +21,35 @@ in }; config = lib.mkIf cfg.enable { - extraConfigLua = '' - LazygitTerminal = require("toggleterm.terminal").Terminal:new({ - cmd = "${lib.getExe pkgs.lazygit}", - dir = "git_dir", - direction = "float", + extraConfigLua = # lua + '' + LazygitTerminal = require("toggleterm.terminal").Terminal:new({ + cmd = "${lib.getExe pkgs.lazygit}", + dir = "git_dir", + direction = "float", - on_open = function(term) - vim.cmd("startinsert!") - vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "close", { noremap = true, silent = true }) - end, - on_close = function(_) - vim.cmd("startinsert!") - end, - }) + on_open = function(term) + vim.cmd("startinsert!") + vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "close", { noremap = true, silent = true }) + end, + on_close = function(_) + vim.cmd("startinsert!") + end, + }) - function LazygitToggle() - lazygit:toggle() - end - ''; + function LazygitToggle() + lazygit:toggle() + end + ''; userCommands.${cfg.commandName} = { command = { - __raw = '' - function() - LazygitTerminal:toggle() - end - ''; + __raw = # lua + '' + function() + LazygitTerminal:toggle() + end + ''; }; }; diff --git a/modules/home-manager/programs/nixvim/presets/trouble.nix b/modules/home-manager/programs/nixvim/presets/trouble.nix index 527e9b9..5fb503c 100644 --- a/modules/home-manager/programs/nixvim/presets/trouble.nix +++ b/modules/home-manager/programs/nixvim/presets/trouble.nix @@ -13,31 +13,36 @@ in key = "xx"; mode = "n"; lua = true; - action = "require('trouble').toggle"; + action = # lua + "require('trouble').toggle"; } { key = "xw"; mode = "n"; lua = true; - action = "function() require('trouble').toggle('workspace_diagnostics') end"; + action = # lua + "function() require('trouble').toggle('workspace_diagnostics') end"; } { key = "xd"; mode = "n"; lua = true; - action = "function() require('trouble').toggle('document_diagnostics') end"; + action = # lua + "function() require('trouble').toggle('document_diagnostics') end"; } { key = "xq"; mode = "n"; lua = true; - action = "function() require('trouble').toggle('quickfix') end"; + action = # lua + "function() require('trouble').toggle('quickfix') end"; } { key = "xl"; mode = "n"; lua = true; - action = "function() require('trouble').toggle('loclist') end"; + action = # lua + "function() require('trouble').toggle('loclist') end"; } ]; plugins = { diff --git a/modules/home-manager/programs/nixvim/presets/undotree.nix b/modules/home-manager/programs/nixvim/presets/undotree.nix index 9623490..3bec293 100644 --- a/modules/home-manager/programs/nixvim/presets/undotree.nix +++ b/modules/home-manager/programs/nixvim/presets/undotree.nix @@ -10,7 +10,8 @@ in config = lib.mkIf cfg.enable { opts = { undodir = { - __raw = "os.getenv('HOME') .. '/.config/nvim/undodir'"; + __raw = # lua + "os.getenv('HOME') .. '/.config/nvim/undodir'"; }; undofile = true; };