From 4ea5d6026ad3a49f6a2648b27b2a7d0a7770fd48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Thu, 21 Mar 2024 15:34:32 +0100 Subject: [PATCH] feat: finally angular support --- home/programs/default.nix | 2 +- home/programs/nixvim/custom-highlights.lua | 65 ++++ .../{nixvim.nix => nixvim/default.nix} | 290 +++--------------- home/programs/nixvim/extra-config.lua | 60 ++++ home/programs/nixvim/keymaps.nix | 106 +++++++ 5 files changed, 279 insertions(+), 244 deletions(-) create mode 100644 home/programs/nixvim/custom-highlights.lua rename home/programs/{nixvim.nix => nixvim/default.nix} (55%) create mode 100644 home/programs/nixvim/extra-config.lua create mode 100644 home/programs/nixvim/keymaps.nix diff --git a/home/programs/default.nix b/home/programs/default.nix index e24a96f..830b562 100644 --- a/home/programs/default.nix +++ b/home/programs/default.nix @@ -4,7 +4,7 @@ rbw = import ./bitwarden.nix; git = import ./git.nix; lazygit.enable = true; - nixvim = import ./nixvim.nix {inherit pkgs;}; + nixvim = import ./nixvim {inherit pkgs;}; firefox = import ./firefox.nix {inherit pkgs;}; gpg.enable = true; btop = { diff --git a/home/programs/nixvim/custom-highlights.lua b/home/programs/nixvim/custom-highlights.lua new file mode 100644 index 0000000..0ee9a95 --- /dev/null +++ b/home/programs/nixvim/custom-highlights.lua @@ -0,0 +1,65 @@ +function(colors) + return { + CmpItemKindCopilot = { fg = colors.teal }, + CmpItemKindNpm = { fg = colors.maroon }, + + -- IntelliJ Theme + Constant = { fg = colors.mauve }, + Character = { link = "Keyword" }, + Number = { fg = colors.sapphire }, + Boolean = { link = "Keyword" }, + Identifier = { fg = colors.text }, + Function = { fg = colors.blue }, + Statement = { fg = colors.text }, + Conditional = { link = "Keyword" }, + Repeat = { link = "Keyword" }, + Label = { link = "Keyword" }, + Operator = { fg = colors.text }, + Keyword = { fg = colors.peach }, + Exception = { link = "Keyword" }, + Include = { link = "Keyword" }, + Structure = { fg = colors.yellow }, + Type = { fg = colors.teal }, + + SpellBad = { sp = colors.green, style = { "underdotted" } }, + SpellCap = { sp = colors.green, style = { "underdotted" } }, + SpellLocal = { sp = colors.green, style = { "underdotted" } }, + SpellRare = { sp = colors.green, style = { "underdotted" } }, + + ["@constructor"] = { link = "Keyword" }, + ["@constructor.typescript"] = { link = "@constructor" }, + ["@parameter"] = { link = "Identifier" }, + + ["@tag"] = { link = "Structure" }, + ["@tag.delimiter"] = { link = "Structure" }, + ["@tag.attribute"] = { fg = colors.mauve, style = { "italic" } }, -- Constant + + ["@keyword.function"] = { link = "Keyword" }, + ["@keyword.operator"] = { link = "Keyword" }, + ["@keyword.return"] = { link = "Keyword" }, + ["@keyword.export"] = { link = "Keyword" }, + + ["@punctuation.special"] = { link = "Operator" }, + ["@conditional.ternary"] = { link = "Operator" }, + + ["@type.builtin"] = { link = "Keyword" }, + ["@variable.builtin"] = { link = "Keyword" }, + ["@lsp.typemod.class.defaultLibrary"] = { fg = colors.yellow, style = { "bold" } }, -- Structure + ["@lsp.typemod.variable.defaultLibrary"] = { fg = colors.mauve, style = { "bold" } }, -- Constant + ["@lsp.typemod.function.defaultLibrary"] = { fg = colors.blue, style = { "bold" } }, -- Function + + ["@variable"] = { link = "Constant" }, + ["@field"] = { link = "Constant" }, + ["@label.json"] = { link = "Constant" }, + ["@label.jsonc"] = { link = "Constant" }, + ["@property"] = { link = "Constant" }, + ["@property.typescript"] = { link = "@property" }, + ["@lsp.type.property"] = { link = "Constant" }, + ["@lsp.type.interface"] = { link = "Structure" }, + ["@lsp.type.namespace"] = { link = "Structure" }, + ["@attribute.typescript"] = { link = "Structure" }, + + ["@lsp.mod.local"] = { fg = colors.text }, + ["@lsp.mod.readonly"] = { style = { "italic" } }, + } +end diff --git a/home/programs/nixvim.nix b/home/programs/nixvim/default.nix similarity index 55% rename from home/programs/nixvim.nix rename to home/programs/nixvim/default.nix index cd62cae..203f060 100644 --- a/home/programs/nixvim.nix +++ b/home/programs/nixvim/default.nix @@ -1,6 +1,6 @@ {pkgs}: let angular-ls = - (import ../packages/node-packages { + (import ../../packages/node-packages { inherit pkgs; nodejs = pkgs.nodejs_18; }) @@ -62,112 +62,7 @@ in { fillchars.eob = " "; }; - keymaps = [ - { - key = "u"; - mode = "n"; - action = ":UndotreeToggle"; - } - { - key = "ft"; - action = ":Neotree toggle"; - } - { - key = "s"; - action = ":SymbolsOutline"; - } - { - key = "J"; - mode = "v"; - action = ":m '>+1gv=gv"; - } - { - key = "K"; - mode = "v"; - action = ":m '<-2gv=gv"; - } - - { - key = ""; - mode = "n"; - action = "zz"; - } - { - key = ""; - mode = "n"; - action = "zz"; - } - { - key = "p"; - mode = "x"; - action = ''"_dP''; - } - { - key = "p"; - mode = "n"; - action = ''"_dP''; - } - { - key = "p"; - mode = "v"; - action = ''"_dP''; - } - { - key = "n"; - mode = "n"; - options.silent = true; - action = "vim.lsp.buf.hover"; - lua = true; - } - { - key = "hh"; - mode = "n"; - action = '':Telescope harpoon marks''; - } - { - key = "sa"; - mode = "n"; - options.silent = true; - lua = true; - action = "require('actions-preview').code_actions"; - } - { - key = "xx"; - mode = "n"; - lua = true; - action = "require('trouble').toggle"; - } - { - key = "xw"; - mode = "n"; - lua = true; - action = "function() require('trouble').toggle('workspace_diagnostics') end"; - } - { - key = "xd"; - mode = "n"; - lua = true; - action = "function() require('trouble').toggle('document_diagnostics') end"; - } - { - key = "xq"; - mode = "n"; - lua = true; - action = "function() require('trouble').toggle('quickfix') end"; - } - { - key = "xl"; - mode = "n"; - lua = true; - action = "function() require('trouble').toggle('loclist') end"; - } - { - key = "gR"; - mode = "n"; - lua = true; - action = "function() require('trouble').toggle('lsp_references') end"; - } - ]; + keymaps = import ./keymaps.nix; globals = { minimap_width = 10; @@ -204,66 +99,7 @@ in { set noshowmode ''; - extraConfigLua = '' - require("darkman").setup() - require("cmp-npm").setup({}) - require("rest-nvim").setup({}) - require("actions-preview").setup({}) - - if vim.g.neovide then - vim.api.nvim_create_autocmd("ColorScheme", { - pattern = "*", - callback = function() - local flavour = require("catppuccin").options.background[vim.o.background] - local palette = require("catppuccin.palettes").get_palette(flavour) - vim.cmd("hi Normal guibg=" .. palette.base) - vim.cmd("set pumblend=100") - end, - }) - end - - 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 - - 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"}) - - local Terminal = require('toggleterm.terminal').Terminal - local lazygit = Terminal:new({ - cmd = "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(term) - vim.cmd("startinsert!") - end, - }) - - - function _lazygit_toggle() - lazygit:toggle() - end - - vim.api.nvim_set_keymap("n", "g", "lua _lazygit_toggle()", {noremap = true, silent = true}) - ''; + extraConfigLua = builtins.readFile ./extra-config.lua; colorschemes.catppuccin = { enable = true; @@ -277,77 +113,7 @@ in { errors = ["undercurl"]; warnings = ["undercurl"]; }; - customHighlights = - /* - lua - */ - '' - function(colors) - return { - CmpItemKindCopilot = {fg = colors.teal}, - CmpItemKindNpm = {fg = colors.maroon}, - - -- IntelliJ Theme - Constant = {fg = colors.mauve}, - Character = {link = "Keyword"}, - Number = {fg = colors.sapphire}, - Boolean = {link = "Keyword"}, - Identifier = {fg = colors.text}, - Function = {fg = colors.blue}, - Statement = {fg = colors.text}, - Conditional = {link = "Keyword"}, - Repeat = {link = "Keyword"}, - Label = {link = "Keyword"}, - Operator = {fg = colors.text}, - Keyword = {fg = colors.peach}, - Exception = {link = "Keyword"}, - Include = {link = "Keyword"}, - Structure = {fg = colors.yellow}, - Type = {fg = colors.teal}, - - SpellBad = {sp = colors.green, style = {"underdotted"}}, - SpellCap = {sp = colors.green, style = {"underdotted"}}, - SpellLocal = {sp = colors.green, style = {"underdotted"}}, - SpellRare = {sp = colors.green, style = {"underdotted"}}, - - ["@constructor"] = {link = "Keyword"}, - ["@constructor.typescript"] = {link = "@constructor"}, - ["@parameter"] = {link = "Identifier"}, - - ["@tag"] = {link = "Structure"}, - ["@tag.delimiter"] = {link = "Structure"}, - ["@tag.attribute"] = {fg = colors.mauve, style = {"italic"}}, -- Constant - - ["@keyword.function"] = {link = "Keyword"}, - ["@keyword.operator"] = {link = "Keyword"}, - ["@keyword.return"] = {link = "Keyword"}, - ["@keyword.export"] = {link = "Keyword"}, - - ["@punctuation.special"] = {link = "Operator"}, - ["@conditional.ternary"] = {link = "Operator"}, - - ["@type.builtin"] = {link = "Keyword"}, - ["@variable.builtin"] = {link = "Keyword"}, - ["@lsp.typemod.class.defaultLibrary"] = {fg = colors.yellow, style = {"bold"}}, -- Structure - ["@lsp.typemod.variable.defaultLibrary"] = {fg = colors.mauve, style = {"bold"}}, -- Constant - ["@lsp.typemod.function.defaultLibrary"] = {fg = colors.blue, style = {"bold"}}, -- Function - - ["@variable"] = {link = "Constant"}, - ["@field"] = {link = "Constant"}, - ["@label.json"] = {link = "Constant"}, - ["@label.jsonc"] = {link = "Constant"}, - ["@property"] = {link = "Constant"}, - ["@property.typescript"] = {link = "@property"}, - ["@lsp.type.property"] = {link = "Constant"}, - ["@lsp.type.interface"] = {link = "Structure"}, - ["@lsp.type.namespace"] = {link = "Structure"}, - ["@attribute.typescript"] = {link = "Structure"}, - - ["@lsp.mod.local"] = {fg = colors.text}, - ["@lsp.mod.readonly"] = {style = {"italic"}}, - } - end - ''; + customHighlights = builtins.readFile ./custom-highlights.lua; }; plugins = { @@ -518,13 +284,45 @@ in { name = "angularls"; extraOptions = { cmd = [ - "${angular-ls}" + "ngserver" "--stdio" "--tsProbeLocations" - "${pkgs.nodePackages.typescript-language-server}" + "" "--ngProbeLocations" - "${angular-ls}" + "" ]; + on_new_config = { + __raw = + /* + lua + */ + '' + function(new_config, new_root_dir) + new_config.cmd = { + new_root_dir .. "/node_modules/@angular/language-server/bin/ngserver", + "--stdio", + "--tsProbeLocations", + new_root_dir .. "/node_modules", + "--ngProbeLocations", + new_root_dir .. "/node_modules", + } + end + ''; + }; + filetypes = ["typescript" "html" "typescriptreact" "typescript.tsx" "angular" "html.angular"]; + on_attach = { + __raw = + /* + lua + */ + '' + function(client, bufnr) + if vim.bo[bufnr].filetype == "html" then + vim.bo[bufnr].filetype = "angular" + end + end + ''; + }; }; } ]; @@ -626,9 +424,15 @@ in { nix.enable = true; }; - extraPackages = [angular-ls pkgs.nodePackages.typescript-language-server pkgs.nodePackages.stylelint pkgs.jq pkgs.html-tidy]; + extraPackages = [ + angular-ls + pkgs.nodePackages.typescript-language-server + pkgs.nodePackages.stylelint + pkgs.jq + pkgs.html-tidy + pkgs.alejandra + ]; extraPlugins = with pkgs.vimPlugins; [ - vim-startuptime vim-mergetool lualine-so-fancy darkman diff --git a/home/programs/nixvim/extra-config.lua b/home/programs/nixvim/extra-config.lua new file mode 100644 index 0000000..5b0175e --- /dev/null +++ b/home/programs/nixvim/extra-config.lua @@ -0,0 +1,60 @@ +require("darkman").setup() +require("cmp-npm").setup({}) +require("rest-nvim").setup({}) +require("actions-preview").setup({}) + +-- require("lspconfig").angularls.setup({}) + +if vim.g.neovide then + vim.api.nvim_create_autocmd("ColorScheme", { + pattern = "*", + callback = function() + local flavour = require("catppuccin").options.background[vim.o.background] + local palette = require("catppuccin.palettes").get_palette(flavour) + vim.cmd("hi Normal guibg=" .. palette.base) + vim.cmd("set pumblend=100") + end, + }) +end + +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 + +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" }) + +local Terminal = require('toggleterm.terminal').Terminal +local lazygit = Terminal:new({ + cmd = "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(term) + vim.cmd("startinsert!") + end, +}) + + +function _lazygit_toggle() + lazygit:toggle() +end + +vim.api.nvim_set_keymap("n", "g", "lua _lazygit_toggle()", { noremap = true, silent = true }) diff --git a/home/programs/nixvim/keymaps.nix b/home/programs/nixvim/keymaps.nix new file mode 100644 index 0000000..18a4682 --- /dev/null +++ b/home/programs/nixvim/keymaps.nix @@ -0,0 +1,106 @@ +[ + { + key = "u"; + mode = "n"; + action = ":UndotreeToggle"; + } + { + key = "ft"; + action = ":Neotree toggle"; + } + { + key = "s"; + action = ":SymbolsOutline"; + } + { + key = "J"; + mode = "v"; + action = ":m '>+1gv=gv"; + } + { + key = "K"; + mode = "v"; + action = ":m '<-2gv=gv"; + } + + { + key = ""; + mode = "n"; + action = "zz"; + } + { + key = ""; + mode = "n"; + action = "zz"; + } + { + key = "p"; + mode = "x"; + action = ''"_dP''; + } + { + key = "p"; + mode = "n"; + action = ''"_dP''; + } + { + key = "p"; + mode = "v"; + action = ''"_dP''; + } + { + key = "n"; + mode = "n"; + options.silent = true; + action = "vim.lsp.buf.hover"; + lua = true; + } + { + key = "hh"; + mode = "n"; + action = '':Telescope harpoon marks''; + } + { + key = "sa"; + mode = "n"; + options.silent = true; + lua = true; + action = "require('actions-preview').code_actions"; + } + { + key = "xx"; + mode = "n"; + lua = true; + action = "require('trouble').toggle"; + } + { + key = "xw"; + mode = "n"; + lua = true; + action = "function() require('trouble').toggle('workspace_diagnostics') end"; + } + { + key = "xd"; + mode = "n"; + lua = true; + action = "function() require('trouble').toggle('document_diagnostics') end"; + } + { + key = "xq"; + mode = "n"; + lua = true; + action = "function() require('trouble').toggle('quickfix') end"; + } + { + key = "xl"; + mode = "n"; + lua = true; + action = "function() require('trouble').toggle('loclist') end"; + } + { + key = "gR"; + mode = "n"; + lua = true; + action = "function() require('trouble').toggle('lsp_references') end"; + } +]