feat(LSP): lspkind and sources

This commit is contained in:
NotAShelf 2023-04-18 01:48:44 +03:00
parent 2df414b577
commit 104c21c904
No known key found for this signature in database
GPG key ID: F0D14CCB5ED5AA22
11 changed files with 143 additions and 50 deletions

View file

@ -29,6 +29,16 @@ inputs: let
}; };
}; };
vim.lsp = {
formatOnSave = true;
lspkind.enable = false;
lightbulb.enable = true;
lspsaga.enable = false;
nvimCodeActionMenu.enable = true;
trouble.enable = true;
lspSignature.enable = true;
};
vim.languages = { vim.languages = {
enableLSP = true; enableLSP = true;
enableFormat = true; enableFormat = true;
@ -56,7 +66,6 @@ inputs: let
smoothScroll.enable = true; smoothScroll.enable = true;
cellularAutomaton.enable = true; cellularAutomaton.enable = true;
fidget-nvim.enable = true; fidget-nvim.enable = true;
lspkind.enable = true;
indentBlankline = { indentBlankline = {
enable = true; enable = true;
fillChar = ""; fillChar = "";

View file

@ -7,8 +7,27 @@
with lib; with lib;
with builtins; let with builtins; let
cfg = config.vim.autocomplete; cfg = config.vim.autocomplete;
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
builtSources = builtSources =
concatMapStringsSep "\n" (x: "{ name = '${x}'},") cfg.sources; concatMapStringsSep
"\n"
(n: "{ name = '${n}'},")
(attrNames cfg.sources);
builtMaps =
concatStringsSep
"\n"
(mapAttrsToList
(n: v:
if v == null
then ""
else "${n} = '${v}',")
cfg.sources);
dagPlacement =
if lspkindEnabled
then nvim.dag.entryAfter ["lspkind"]
else nvim.dag.entryAnywhere;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = [ vim.startPlugins = [
@ -18,14 +37,28 @@ in {
"cmp-path" "cmp-path"
]; ];
vim.autocomplete.sources = [ vim.autocomplete.sources = {
"nvim-cmp" "nvim-cmp" = null;
"vsnip" "vsnip" = "[VSnip]";
"buffer" "buffer" = "[Buffer]";
"path" "crates" = "[Crates]";
]; "path" = "[Path]";
};
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
local nvim_cmp_menu_map = function(entry, vim_item)
-- name for each source
vim_item.menu = ({
${builtMaps}
})[entry.source.name]
print(vim_item.menu)
return vim_item
end
${optionalString lspkindEnabled ''
lspkind_opts.before = ${cfg.formatting.format}
''}
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (nvim.dag.entryAnywhere ''
local has_words_before = function() local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
@ -80,23 +113,12 @@ in {
completeopt = 'menu,menuone,noinsert', completeopt = 'menu,menuone,noinsert',
}, },
formatting = { formatting = {
format = function(entry, vim_item) format =
-- type of kind ${
vim_item.kind = ${ if lspkindEnabled
optionalString (config.vim.visuals.lspkind.enable) then "lspkind.cmp_format(lspkind_opts)"
"require('lspkind').presets.default[vim_item.kind] .. ' ' .." else cfg.formatting.format
} vim_item.kind },
-- name for each source
vim_item.menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
vsnip = "[VSnip]",
crates = "[Crates]",
path = "[Path]",
})[entry.source.name]
return vim_item
end,
} }
}) })
${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") '' ${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") ''

View file

@ -5,11 +5,7 @@
... ...
}: }:
with lib; with lib;
with builtins; let with builtins; {
cfg = config.vim.autocomplete;
builtSources =
concatMapStringsSep "\n" (x: "{ name = '${x}'},") cfg.sources;
in {
options.vim = { options.vim = {
autocomplete = { autocomplete = {
enable = mkOption { enable = mkOption {
@ -25,9 +21,40 @@ in {
}; };
sources = mkOption { sources = mkOption {
description = "List of source names for nvim-cmp"; description = nvim.nmd.asciiDoc ''
type = with types; listOf str; Attribute set of source names for nvim-cmp.
default = [];
If an attribute set is provided, then the menu value of
`vim_item` in the format will be set to the value (if
utilizing the `nvim_cmp_menu_map` function).
Note: only use a single attribute name per attribute set
'';
type = with types; attrsOf (nullOr str);
default = {};
example = ''
{nvim-cmp = null; buffer = "[Buffer]";}
'';
};
formatting = {
format = mkOption {
description = nvim.nmd.asciiDoc ''
The function used to customize the appearance of the completion menu.
If <<opt-vim.lsp.lspkind.enable>> is true, then the function
will be called before modifications from lspkind.
Default is to call the menu mapping function.
'';
type = types.str;
default = "nvim_cmp_menu_map";
example = ''
function(entry, vim_item)
return vim_item
end
'';
};
}; };
}; };
}; };

View file

@ -54,7 +54,7 @@ in {
vim.startPlugins = ["crates-nvim"]; vim.startPlugins = ["crates-nvim"];
vim.autocomplete.sources = ["crates"]; vim.autocomplete.sources = {"crates" = "[Crates]";};
vim.luaConfigRC.rust-crates = nvim.dag.entryAnywhere '' vim.luaConfigRC.rust-crates = nvim.dag.entryAnywhere ''
require('crates').setup { require('crates').setup {
null_ls = { null_ls = {

View file

@ -14,6 +14,7 @@ _: {
./trouble ./trouble
./lsp-signature ./lsp-signature
./lightbulb ./lightbulb
./lspkind
# flutter-tools # flutter-tools
./flutter-tools-nvim ./flutter-tools-nvim

View file

@ -0,0 +1,20 @@
{
pkgs,
config,
lib,
...
}:
with lib;
with builtins; let
cfg = config.vim.lsp;
in {
config = mkIf (cfg.enable && cfg.lspkind.enable) {
vim.startPlugins = ["lspkind"];
vim.luaConfigRC.lspkind = nvim.dag.entryAnywhere ''
local lspkind = require'lspkind'
local lspkind_opts = {
mode = '${cfg.lspkind.mode}'
}
'';
};
}

View file

@ -0,0 +1,6 @@
_: {
imports = [
./config.nix
./lspkind.nix
];
}

View file

@ -0,0 +1,22 @@
{
pkgs,
config,
lib,
...
}:
with lib;
with builtins; let
cfg = config.vim.lsp;
in {
options.vim.lsp = {
lspkind = {
enable = mkEnableOption "vscode-like pictograms for lsp [lspkind]";
mode = mkOption {
description = "Defines how annotations are shown";
type = with types; enum ["text" "text_symbol" "symbol_text" "symbol"];
default = "symbol_text";
};
};
};
}

View file

@ -14,7 +14,7 @@ in {
["nvim-treesitter"] ["nvim-treesitter"]
++ optional usingNvimCmp "cmp-treesitter"; ++ optional usingNvimCmp "cmp-treesitter";
vim.autocomplete.sources = ["treesitter"]; vim.autocomplete.sources = {"treesitter" = "[Treesitter]";};
# For some reason treesitter highlighting does not work on start if this is set before syntax on # For some reason treesitter highlighting does not work on start if this is set before syntax on
vim.configRC.treesitter-fold = mkIf cfg.fold (nvim.dag.entryBefore ["basic"] '' vim.configRC.treesitter-fold = mkIf cfg.fold (nvim.dag.entryBefore ["basic"] ''

View file

@ -7,14 +7,6 @@ with lib; let
cfg = config.vim.visuals; cfg = config.vim.visuals;
in { in {
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [
(mkIf cfg.lspkind.enable {
vim.startPlugins = ["lspkind"];
vim.luaConfigRC.lspkind = nvim.dag.entryAnywhere ''
-- lspkind
require'lspkind'.init()
'';
})
(mkIf cfg.indentBlankline.enable { (mkIf cfg.indentBlankline.enable {
vim.startPlugins = ["indent-blankline"]; vim.startPlugins = ["indent-blankline"];
vim.luaConfigRC.indent-blankline = nvim.dag.entryAnywhere '' vim.luaConfigRC.indent-blankline = nvim.dag.entryAnywhere ''

View file

@ -18,12 +18,6 @@ with builtins; {
default = false; default = false;
}; };
lspkind.enable = mkOption {
type = types.bool;
description = "Enable vscode-like pictograms for lsp [lspkind]";
default = false;
};
scrollBar.enable = mkOption { scrollBar.enable = mkOption {
type = types.bool; type = types.bool;
description = "Enable scrollbar [scrollbar.nvim]"; description = "Enable scrollbar [scrollbar.nvim]";