From 4cb8fc4febd4f28366918b7cdda1eaf09c069baa Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 10 Nov 2022 18:22:45 +0000 Subject: [PATCH] lspkind: init plugin --- flake.lock | 12 +++--- plugins/completion/lspkind.nix | 71 ++++++++++++++++++++++++++++++++++ plugins/default.nix | 1 + tests/flake.lock | 48 +++++++++++------------ tests/flake.nix | 31 ++++++++++----- 5 files changed, 123 insertions(+), 40 deletions(-) create mode 100644 plugins/completion/lspkind.nix diff --git a/flake.lock b/flake.lock index 73627e2d..cc4141f4 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -32,11 +32,11 @@ "nmdSrc": { "flake": false, "locked": { - "lastModified": 1654807200, - "narHash": "sha256-RNLq09vfj21TyYuUCeD6BNTNC6Ew8bLhQULZytN4Xx8=", + "lastModified": 1666190571, + "narHash": "sha256-Z1hc7M9X6L+H83o9vOprijpzhTfOBjd0KmUTnpHAVjA=", "owner": "rycee", "repo": "nmd", - "rev": "91dee681dd1c478d6040a00835d73c0f4a4c5c29", + "rev": "b75d312b4f33bd3294cd8ae5c2ca8c6da2afc169", "type": "gitlab" }, "original": { diff --git a/plugins/completion/lspkind.nix b/plugins/completion/lspkind.nix new file mode 100644 index 00000000..4a5337b4 --- /dev/null +++ b/plugins/completion/lspkind.nix @@ -0,0 +1,71 @@ +{ config, pkgs, lib, helpers, ... }: +with lib; +let + cfg = config.plugins.lspkind; +in +{ + options.plugins.lspkind = { + enable = mkEnableOption "lspkind.nvim"; + mode = mkOption { + type = with types; nullOr (enum [ "text" "text_symbol" "symbol_text" "symbol" ]); + default = null; + description = "Defines how annotations are shown"; + }; + + preset = mkOption { + type = with types; nullOr (enum [ "default" "codicons" ]); + default = null; + description = "Default symbol map"; + }; + + symbolMap = mkOption { + type = with types; nullOr (attrsOf str); + default = null; + description = "Override preset symbols"; + }; + + cmp = { + enable = mkOption { + type = types.bool; + default = true; + description = "Integrate with nvim-cmp"; + }; + + maxWidth = mkOption { + type = with types; nullOr int; + default = null; + description = "Maximum number of characters to show in the popup"; + }; + + ellipsisChar = mkOption { + type = with types; nullOr str; + default = null; + description = "Character to show when the popup exceeds maxwidth"; + }; + }; + }; + + config = + let + doCmp = cfg.cmp.enable && config.plugins.nvim-cmp.enable; + options = { + mode = cfg.mode; + preset = cfg.preset; + symbol_map = cfg.symbolMap; + } // (if doCmp then { + maxwidth = cfg.cmp.maxWidth; + ellipsis_char = cfg.cmp.ellipsisChar; + } else { }); + in + mkIf cfg.enable { + extraPlugins = [ pkgs.vimPlugins.lspkind-nvim ]; + + extraConfigLua = optionalString (!doCmp) '' + require('lspkind').init(${helpers.toLuaObject options}) + ''; + + plugins.nvim-cmp.formatting.format = '' + require('lspkind').cmp_format(${helpers.toLuaObject options}) + ''; + }; +} diff --git a/plugins/default.nix b/plugins/default.nix index d3e02ee3..e1ba054b 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -14,6 +14,7 @@ ./completion/copilot.nix ./completion/nvim-cmp ./completion/nvim-cmp/sources + ./completion/lspkind.nix ./git/fugitive.nix ./git/gitgutter.nix diff --git a/tests/flake.lock b/tests/flake.lock index b4d67168..032d8e6b 100644 --- a/tests/flake.lock +++ b/tests/flake.lock @@ -2,11 +2,11 @@ "nodes": { "flake-utils": { "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -17,11 +17,11 @@ }, "flake-utils_2": { "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -32,11 +32,11 @@ }, "flake-utils_3": { "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", "type": "github" }, "original": { @@ -61,11 +61,11 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1665066044, - "narHash": "sha256-mkO0LMHVunMFRWLcJhHT0fBf2v6RlH3vg7EVpfSIAFc=", + "lastModified": 1668016843, + "narHash": "sha256-ioBuF+IAhmJO7s4ewEij1LkMxJvCCNCKXxMto/DU02I=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ed9b904c5eba055a6d6f5c1ccb89ba8f0a056dc6", + "rev": "fa842715565307b7e05cdb187b08c05f16ed08f1", "type": "github" }, "original": { @@ -97,12 +97,12 @@ }, "locked": { "lastModified": 0, - "narHash": "sha256-7vhOkX4qovJR5Vm44lk6c81w3DkuGcQTRxGEnRJI8ro=", - "path": "/nix/store/iz74dsm3s96n1f07w6blgw4bf9n2rl5c-source", + "narHash": "sha256-2xKbMFW3jSlyvl1ZKoe9sNe4h5k5Qk410Dom4TU3nls=", + "path": "/nix/store/89k711hq8f8j87h2kadz5kivkcpxjv58-source", "type": "path" }, "original": { - "path": "/nix/store/iz74dsm3s96n1f07w6blgw4bf9n2rl5c-source", + "path": "/nix/store/89k711hq8f8j87h2kadz5kivkcpxjv58-source", "type": "path" } }, @@ -116,23 +116,23 @@ }, "locked": { "lastModified": 0, - "narHash": "sha256-7vhOkX4qovJR5Vm44lk6c81w3DkuGcQTRxGEnRJI8ro=", - "path": "/nix/store/iz74dsm3s96n1f07w6blgw4bf9n2rl5c-source", + "narHash": "sha256-2xKbMFW3jSlyvl1ZKoe9sNe4h5k5Qk410Dom4TU3nls=", + "path": "/nix/store/89k711hq8f8j87h2kadz5kivkcpxjv58-source", "type": "path" }, "original": { - "path": "/nix/store/iz74dsm3s96n1f07w6blgw4bf9n2rl5c-source", + "path": "/nix/store/89k711hq8f8j87h2kadz5kivkcpxjv58-source", "type": "path" } }, "nmdSrc": { "flake": false, "locked": { - "lastModified": 1654807200, - "narHash": "sha256-RNLq09vfj21TyYuUCeD6BNTNC6Ew8bLhQULZytN4Xx8=", + "lastModified": 1666190571, + "narHash": "sha256-Z1hc7M9X6L+H83o9vOprijpzhTfOBjd0KmUTnpHAVjA=", "owner": "rycee", "repo": "nmd", - "rev": "91dee681dd1c478d6040a00835d73c0f4a4c5c29", + "rev": "b75d312b4f33bd3294cd8ae5c2ca8c6da2afc169", "type": "gitlab" }, "original": { @@ -144,11 +144,11 @@ "nmdSrc_2": { "flake": false, "locked": { - "lastModified": 1654807200, - "narHash": "sha256-RNLq09vfj21TyYuUCeD6BNTNC6Ew8bLhQULZytN4Xx8=", + "lastModified": 1666190571, + "narHash": "sha256-Z1hc7M9X6L+H83o9vOprijpzhTfOBjd0KmUTnpHAVjA=", "owner": "rycee", "repo": "nmd", - "rev": "91dee681dd1c478d6040a00835d73c0f4a4c5c29", + "rev": "b75d312b4f33bd3294cd8ae5c2ca8c6da2afc169", "type": "gitlab" }, "original": { diff --git a/tests/flake.nix b/tests/flake.nix index d611baa1..adff2976 100644 --- a/tests/flake.nix +++ b/tests/flake.nix @@ -154,21 +154,21 @@ nvim-cmp = { formatting = { format = '' - require("lspkind").cmp_format({ - mode="symbol", - maxwidth = 50, - ellipsis_char = "..." - }) - ''; + require("lspkind").cmp_format({ + mode="symbol", + maxwidth = 50, + ellipsis_char = "..." + }) + ''; }; auto_enable_sources = true; snippet = { expand = '' - function(args) - require("luasnip").lsp_expand(args.body) - end - ''; + function(args) + require("luasnip").lsp_expand(args.body) + end + ''; }; enable = true; sources = [ @@ -200,6 +200,17 @@ # extraConfigLua = (builtins.readFile ./nvim-extra-lua.lua); }; + + lspkind = build { + plugins = { + lsp = { + enable = true; + servers.clangd.enable = true; + }; + nvim-cmp.enable = true; + lspkind.enable = true; + }; + }; }; })) // { nixosConfigurations.nixvim-machine = nixpkgs.lib.nixosSystem {