mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2024-11-09 14:45:58 +01:00
feat(LSP): lspkind and sources
This commit is contained in:
parent
2df414b577
commit
104c21c904
11 changed files with 143 additions and 50 deletions
11
extra.nix
11
extra.nix
|
@ -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 = {
|
||||
enableLSP = true;
|
||||
enableFormat = true;
|
||||
|
@ -56,7 +66,6 @@ inputs: let
|
|||
smoothScroll.enable = true;
|
||||
cellularAutomaton.enable = true;
|
||||
fidget-nvim.enable = true;
|
||||
lspkind.enable = true;
|
||||
indentBlankline = {
|
||||
enable = true;
|
||||
fillChar = "";
|
||||
|
|
|
@ -7,8 +7,27 @@
|
|||
with lib;
|
||||
with builtins; let
|
||||
cfg = config.vim.autocomplete;
|
||||
lspkindEnabled = config.vim.lsp.enable && config.vim.lsp.lspkind.enable;
|
||||
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 {
|
||||
config = mkIf cfg.enable {
|
||||
vim.startPlugins = [
|
||||
|
@ -18,14 +37,28 @@ in {
|
|||
"cmp-path"
|
||||
];
|
||||
|
||||
vim.autocomplete.sources = [
|
||||
"nvim-cmp"
|
||||
"vsnip"
|
||||
"buffer"
|
||||
"path"
|
||||
];
|
||||
vim.autocomplete.sources = {
|
||||
"nvim-cmp" = null;
|
||||
"vsnip" = "[VSnip]";
|
||||
"buffer" = "[Buffer]";
|
||||
"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 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
|
||||
|
@ -80,23 +113,12 @@ in {
|
|||
completeopt = 'menu,menuone,noinsert',
|
||||
},
|
||||
formatting = {
|
||||
format = function(entry, vim_item)
|
||||
-- type of kind
|
||||
vim_item.kind = ${
|
||||
optionalString (config.vim.visuals.lspkind.enable)
|
||||
"require('lspkind').presets.default[vim_item.kind] .. ' ' .."
|
||||
} 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,
|
||||
format =
|
||||
${
|
||||
if lspkindEnabled
|
||||
then "lspkind.cmp_format(lspkind_opts)"
|
||||
else cfg.formatting.format
|
||||
},
|
||||
}
|
||||
})
|
||||
${optionalString (config.vim.autopairs.enable && config.vim.autopairs.type == "nvim-autopairs") ''
|
||||
|
|
|
@ -5,11 +5,7 @@
|
|||
...
|
||||
}:
|
||||
with lib;
|
||||
with builtins; let
|
||||
cfg = config.vim.autocomplete;
|
||||
builtSources =
|
||||
concatMapStringsSep "\n" (x: "{ name = '${x}'},") cfg.sources;
|
||||
in {
|
||||
with builtins; {
|
||||
options.vim = {
|
||||
autocomplete = {
|
||||
enable = mkOption {
|
||||
|
@ -25,9 +21,40 @@ in {
|
|||
};
|
||||
|
||||
sources = mkOption {
|
||||
description = "List of source names for nvim-cmp";
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
description = nvim.nmd.asciiDoc ''
|
||||
Attribute set of source names for nvim-cmp.
|
||||
|
||||
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
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
|
@ -54,7 +54,7 @@ in {
|
|||
|
||||
vim.startPlugins = ["crates-nvim"];
|
||||
|
||||
vim.autocomplete.sources = ["crates"];
|
||||
vim.autocomplete.sources = {"crates" = "[Crates]";};
|
||||
vim.luaConfigRC.rust-crates = nvim.dag.entryAnywhere ''
|
||||
require('crates').setup {
|
||||
null_ls = {
|
||||
|
|
|
@ -14,6 +14,7 @@ _: {
|
|||
./trouble
|
||||
./lsp-signature
|
||||
./lightbulb
|
||||
./lspkind
|
||||
|
||||
# flutter-tools
|
||||
./flutter-tools-nvim
|
||||
|
|
20
modules/lsp/lspkind/config.nix
Normal file
20
modules/lsp/lspkind/config.nix
Normal 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}'
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
6
modules/lsp/lspkind/default.nix
Normal file
6
modules/lsp/lspkind/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
_: {
|
||||
imports = [
|
||||
./config.nix
|
||||
./lspkind.nix
|
||||
];
|
||||
}
|
22
modules/lsp/lspkind/lspkind.nix
Normal file
22
modules/lsp/lspkind/lspkind.nix
Normal 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";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -14,7 +14,7 @@ in {
|
|||
["nvim-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
|
||||
vim.configRC.treesitter-fold = mkIf cfg.fold (nvim.dag.entryBefore ["basic"] ''
|
||||
|
|
|
@ -7,14 +7,6 @@ with lib; let
|
|||
cfg = config.vim.visuals;
|
||||
in {
|
||||
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 {
|
||||
vim.startPlugins = ["indent-blankline"];
|
||||
vim.luaConfigRC.indent-blankline = nvim.dag.entryAnywhere ''
|
||||
|
|
|
@ -18,12 +18,6 @@ with builtins; {
|
|||
default = false;
|
||||
};
|
||||
|
||||
lspkind.enable = mkOption {
|
||||
type = types.bool;
|
||||
description = "Enable vscode-like pictograms for lsp [lspkind]";
|
||||
default = false;
|
||||
};
|
||||
|
||||
scrollBar.enable = mkOption {
|
||||
type = types.bool;
|
||||
description = "Enable scrollbar [scrollbar.nvim]";
|
||||
|
|
Loading…
Reference in a new issue