1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-11 07:10:39 +02:00

feat: switch nvim to blink.cmp

This commit is contained in:
oddlama 2025-01-05 15:25:57 +01:00
parent d8e2c81593
commit 7e66c747ef
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
3 changed files with 264 additions and 172 deletions

View file

@ -53,7 +53,7 @@
# Status updates for LSP progress in right bottom corner. # Status updates for LSP progress in right bottom corner.
fidget.enable = true; fidget.enable = true;
# Show colors # Show colors
nvim-colorizer.enable = true; colorizer.enable = true;
# Breadcrumbs # Breadcrumbs
# TODO navic.enable = true; or dropbar? # TODO navic.enable = true; or dropbar?

View file

@ -1,182 +1,274 @@
{ {
programs.nixvim = { programs.nixvim = {
plugins = { plugins = {
luasnip = { blink-compat.enable = true;
blink-cmp = {
enable = true; enable = true;
settings = { settings = {
history = true; keymap = {
# Update dynamic snippets while typing preset = "enter";
updateevents = "TextChanged,TextChangedI"; "<A-Tab>" = [
enable_autosnippets = true; "snippet_forward"
}; "fallback"
}; ];
"<A-S-Tab>" = [
cmp_luasnip.enable = true; "snippet_backward"
cmp-dap.enable = true; "fallback"
cmp-cmdline.enable = true; ];
cmp-cmdline-history.enable = true; "<Tab>" = [
cmp-path.enable = true; "select_next"
cmp-emoji.enable = true; "fallback"
cmp-treesitter.enable = true; ];
cmp-nvim-lsp.enable = true; "<S-Tab>" = [
cmp-nvim-lsp-document-symbol.enable = true; "select_prev"
cmp-nvim-lsp-signature-help.enable = true; "fallback"
cmp = { ];
enable = true; };
settings = {
sources = [ appearance = {
{ name = "nvim_lsp_signature_help"; } use_nvim_cmp_as_default = true;
{ name = "nvim_lsp"; } nerd_font_variant = "mono";
{ name = "nvim_lsp_document_symbol"; } };
{ name = "path"; }
{ name = "treesitter"; } sources = {
{ name = "dap"; } default = [
# {name = "luasnip";} "lsp"
{ name = "emoji"; } "path"
]; "snippets"
mapping = { "emoji"
"<CR>" = "buffer"
# lua ];
'' providers = {
cmp.mapping.confirm({ emoji = {
behavior = cmp.ConfirmBehavior.Replace, name = "emoji";
select = false, module = "blink.compat.source";
}) };
''; };
"<C-d>" = };
# lua
"cmp.mapping.scroll_docs(-4)"; signature.enabled = true;
"<C-f>" = completion = {
# lua list.selection = "manual";
"cmp.mapping.scroll_docs(4)"; # menu = {
"<C-e>" = # border = "none";
# lua # draw = {
"cmp.mapping.abort()"; # gap = 1;
"<Tab>" = # treesitter = [ "lsp" ];
# lua # columns = [
'' # {
cmp.mapping(function(fallback) # __unkeyed-1 = "label";
local has_words_before = function() # }
local line, col = table.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 # __unkeyed-1 = "kind_icon";
end # __unkeyed-2 = "kind";
# gap = 1;
if cmp.visible() then # }
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) # { __unkeyed-1 = "source_name"; }
elseif require("luasnip").expandable() then # ];
require("luasnip").expand() # };
elseif require("luasnip").expand_or_locally_jumpable() then # };
require("luasnip").expand_or_jump() # trigger = {
--elseif has_words_before() then # show_in_snippet = false;
-- cmp.complete() # };
else documentation = {
fallback() auto_show = true;
end # window = {
end, {"i", "s"}) # border = "rounded";
''; # };
"<Down>" = };
# lua # accept = {
''cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), {'i'})''; # auto_brackets = {
"<Up>" = # enabled = true;
# lua # };
''cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), {'i'})''; # };
"<PageDown>" =
# lua
''cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select, count = -10 }), {'i'})'';
"<PageUp>" =
# lua
''cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select, count = 10 }), {'i'})'';
"<S-Tab>" =
# lua
''
cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {"i", "s"})
'';
}; };
formatting.fields = [
"abbr"
"kind"
"menu"
];
formatting.format =
# lua
''
function(_, vim_item)
local icons = {
Namespace = "󰌗",
Text = "󰉿",
Method = "󰆧",
Function = "󰆧",
Constructor = "",
Field = "󰜢",
Variable = "󰀫",
Class = "󰠱",
Interface = "",
Module = "",
Property = "󰜢",
Unit = "󰑭",
Value = "󰎠",
Enum = "",
Keyword = "󰌋",
Snippet = "",
Color = "󰏘",
File = "󰈚",
Reference = "󰈇",
Folder = "󰉋",
EnumMember = "",
Constant = "󰏿",
Struct = "󰙅",
Event = "",
Operator = "󰆕",
TypeParameter = "󰊄",
Table = "",
Object = "󰅩",
Tag = "",
Array = "󰅪",
Boolean = "",
Number = "",
Null = "󰟢",
String = "󰉿",
Calendar = "",
Watch = "󰥔",
Package = "",
Copilot = "",
Codeium = "",
TabNine = "",
}
vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)
return vim_item
end
'';
snippet.expand =
# lua
''
function(args)
require('luasnip').lsp_expand(args.body)
end
'';
}; };
}; };
# TODO use "ray-x/lsp_signature.nvim" cmp-emoji.enable = true;
lsp.capabilities = # lua
''
capabilities = require('blink.cmp').get_lsp_capabilities(capabilities)
'';
# luasnip = {
# enable = true;
# settings = {
# history = true;
# # Update dynamic snippets while typing
# updateevents = "TextChanged,TextChangedI";
# enable_autosnippets = true;
# };
# };
#
# cmp_luasnip.enable = true;
# cmp-dap.enable = true;
# cmp-cmdline.enable = true;
# cmp-cmdline-history.enable = true;
# cmp-path.enable = true;
# cmp-emoji.enable = true;
# cmp-treesitter.enable = true;
# cmp-nvim-lsp.enable = true;
# cmp-nvim-lsp-document-symbol.enable = true;
# cmp-nvim-lsp-signature-help.enable = true;
# cmp = {
# enable = true;
# settings = {
# sources = [
# { name = "nvim_lsp_signature_help"; }
# { name = "nvim_lsp"; }
# { name = "nvim_lsp_document_symbol"; }
# { name = "path"; }
# { name = "treesitter"; }
# { name = "dap"; }
# # {name = "luasnip";}
# { name = "emoji"; }
# ];
# mapping = {
# "<CR>" =
# # lua
# ''
# cmp.mapping.confirm({
# behavior = cmp.ConfirmBehavior.Replace,
# select = false,
# })
# '';
# "<C-d>" =
# # lua
# "cmp.mapping.scroll_docs(-4)";
# "<C-f>" =
# # lua
# "cmp.mapping.scroll_docs(4)";
# "<C-e>" =
# # lua
# "cmp.mapping.abort()";
# "<Tab>" =
# # lua
# ''
# cmp.mapping(function(fallback)
# local has_words_before = function()
# local line, col = table.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
# end
#
# if cmp.visible() then
# cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
# elseif require("luasnip").expandable() then
# require("luasnip").expand()
# elseif require("luasnip").expand_or_locally_jumpable() then
# require("luasnip").expand_or_jump()
# --elseif has_words_before() then
# -- cmp.complete()
# else
# fallback()
# end
# end, {"i", "s"})
# '';
# "<Down>" =
# # lua
# ''cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), {'i'})'';
# "<Up>" =
# # lua
# ''cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), {'i'})'';
# "<PageDown>" =
# # lua
# ''cmp.mapping(cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select, count = -10 }), {'i'})'';
# "<PageUp>" =
# # lua
# ''cmp.mapping(cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select, count = 10 }), {'i'})'';
# "<S-Tab>" =
# # lua
# ''
# cmp.mapping(function(fallback)
# if cmp.visible() then
# cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
# elseif luasnip.jumpable(-1) then
# luasnip.jump(-1)
# else
# fallback()
# end
# end, {"i", "s"})
# '';
# };
# formatting.fields = [
# "abbr"
# "kind"
# "menu"
# ];
# formatting.format =
# # lua
# ''
# function(_, vim_item)
# local icons = {
# Namespace = "󰌗",
# Text = "󰉿",
# Method = "󰆧",
# Function = "󰆧",
# Constructor = "",
# Field = "󰜢",
# Variable = "󰀫",
# Class = "󰠱",
# Interface = "",
# Module = "",
# Property = "󰜢",
# Unit = "󰑭",
# Value = "󰎠",
# Enum = "",
# Keyword = "󰌋",
# Snippet = "",
# Color = "󰏘",
# File = "󰈚",
# Reference = "󰈇",
# Folder = "󰉋",
# EnumMember = "",
# Constant = "󰏿",
# Struct = "󰙅",
# Event = "",
# Operator = "󰆕",
# TypeParameter = "󰊄",
# Table = "",
# Object = "󰅩",
# Tag = "",
# Array = "󰅪",
# Boolean = "",
# Number = "",
# Null = "󰟢",
# String = "󰉿",
# Calendar = "",
# Watch = "󰥔",
# Package = "",
# Copilot = "",
# Codeium = "",
# TabNine = "",
# }
# vim_item.kind = string.format("%s %s", icons[vim_item.kind], vim_item.kind)
# return vim_item
# end
# '';
# snippet.expand =
# # lua
# ''
# function(args)
# require('luasnip').lsp_expand(args.body)
# end
# '';
# };
# };
#
# # TODO use "ray-x/lsp_signature.nvim"
}; };
extraConfigLuaPost = '' # extraConfigLuaPost = ''
local cmp = require "cmp" # local cmp = require "cmp"
cmp.setup.cmdline(":", { # cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(), # mapping = cmp.mapping.preset.cmdline(),
sources = { # sources = {
{ name = "cmdline" }, # { name = "cmdline" },
{ name = "cmp-cmdline-history" }, # { name = "cmp-cmdline-history" },
}, # },
}) # })
''; # '';
}; };
} }

View file

@ -28,9 +28,9 @@
}; };
# Cargo.toml dependency completion # Cargo.toml dependency completion
crates-nvim = { crates = {
enable = true; enable = true;
extraOptions = { settings = {
completion.cmp.enabled = true; completion.cmp.enabled = true;
}; };
}; };