Skip to content

Commit

Permalink
chore: cmp cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
willruggiano committed Aug 1, 2024
1 parent 3c88249 commit 8041d4e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 166 deletions.
38 changes: 4 additions & 34 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"rev": "3022dbc9166796b644a841a02de8dd1cc1d311fa",
"type": "git"
},
"cmp-fuzzy-path": {
"branch": "master",
"repo": "[email protected]:tzachar/cmp-fuzzy-path",
"rev": "9953c11a2510a04111b7b152cf50ae1e83f00798",
"cmp-cmdline": {
"branch": "main",
"repo": "[email protected]:hrsh7th/cmp-cmdline",
"rev": "d250c63aa13ead745e3a40f61fdd3470efde3923",
"type": "git"
},
"cmp-git": {
Expand All @@ -53,30 +53,12 @@
"rev": "39e2eda76828d88b773cc27a3f61d2ad782c922d",
"type": "git"
},
"cmp-nvim-lsp-signature-help": {
"branch": "main",
"repo": "[email protected]:hrsh7th/cmp-nvim-lsp-signature-help",
"rev": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7",
"type": "git"
},
"cmp-path": {
"branch": "main",
"repo": "[email protected]:hrsh7th/cmp-path",
"rev": "91ff86cd9c29299a64f968ebb45846c485725f23",
"type": "git"
},
"cmp-snippy": {
"branch": "master",
"repo": "[email protected]:dcampos/cmp-snippy",
"rev": "6e39210aa3a74e2bf6462f492eaf0d436cd2b7d3",
"type": "git"
},
"cmp-under-comparator": {
"branch": "master",
"repo": "[email protected]:lukas-reineke/cmp-under-comparator",
"rev": "6857f10272c3cfe930cece2afa2406e1385bfef8",
"type": "git"
},
"conform.nvim": {
"branch": "master",
"repo": "[email protected]:stevearc/conform.nvim",
Expand Down Expand Up @@ -119,12 +101,6 @@
"rev": "a9be4e76c30a128f1e51af448c8321bf8366bcd4",
"type": "git"
},
"fuzzy.nvim": {
"branch": "master",
"repo": "[email protected]:tzachar/fuzzy.nvim",
"rev": "68608f6a232f7e73ccf81437bf12108128f15bd4",
"type": "git"
},
"fzf": {
"branch": "master",
"repo": "[email protected]:junegunn/fzf",
Expand Down Expand Up @@ -515,12 +491,6 @@
"rev": "6c1584eb76b55629702716995cca4ae2798a9cca",
"type": "git"
},
"wilder.nvim": {
"branch": "master",
"repo": "ssh://[email protected]/gelguy/wilder.nvim",
"rev": "679f348dc90d80ff9ba0e7c470c40a4d038dcecf",
"type": "git"
},
"zen-mode.nvim": {
"branch": "main",
"repo": "[email protected]:folke/zen-mode.nvim",
Expand Down
108 changes: 25 additions & 83 deletions plugins/cmp.lua
Original file line number Diff line number Diff line change
@@ -1,95 +1,28 @@
return function()
local cmp = require "cmp"
local snippy = require "snippy"

local cmp_buffer_locality_comparator = function(...)
return require("cmp_buffer"):compare_locality(...)
end
local cmp_clangd_comparator = require "clangd_extensions.cmp_scores"
local cmp_fuzzy_path_comparator = require "cmp_fuzzy_path.compare"
local cmp_under_comparator = require("cmp-under-comparator").under

vim.opt.completeopt = { "menu", "menuone", "noselect" }
vim.opt.shortmess:append "c"

require("cmp_git").setup()
-- TODO: Enable these:
-- require("cmp_shell").setup()
-- require("nix-flake-prefetch.cmp").setup()
local cmp = require "cmp"

cmp.setup {
snippet = {
expand = function(args)
snippy.expand_snippet(args.body)
end,
sources = {
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "buffer" },
},
mapping = {
["<C-d>"] = cmp.mapping.scroll_docs(5),
["<C-u>"] = cmp.mapping.scroll_docs(-5),
["<C-c>"] = cmp.mapping.close(),
["<C-y>"] = function(fallback)
if cmp.visible() then
return cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
}(fallback)
else
return fallback()
end
end,
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
["<C-y>"] = cmp.mapping(
cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true,
},
{ "i", "c" }
),
["<C-space>"] = cmp.mapping {
---@diagnostic disable-next-line: missing-parameter
i = cmp.mapping.complete(),
},
-- TODO: vim.snippet?
["<C-n>"] = cmp.mapping {
i = function(fallback)
if snippy.can_expand_or_advance() then
snippy.expand_or_advance()
elseif cmp.visible() then
return cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert }(fallback)
else
return fallback()
end
end,
},
["<C-p>"] = cmp.mapping {
i = function(fallback)
if snippy.can_jump(-1) then
snippy.previous()
elseif cmp.visible() then
return cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert }(fallback)
else
return fallback()
end
end,
},
},
sources = cmp.config.sources({
{ name = "shell" },
{ name = "nix_flake_prefetch" },
}, {
{ name = "nvim_lsp" },
{ name = "nvim_lsp_signature_help" },
{ name = "snippy" },
-- { name = "cody" },
}, {
{ name = "path" },
{ name = "buffer" },
}),
sorting = {
priority_weight = 2,
comparators = {
cmp_buffer_locality_comparator,
cmp_fuzzy_path_comparator,
cmp.config.compare.offset,
cmp.config.compare.exact,
cmp_clangd_comparator,
cmp_under_comparator,
cmp.config.compare.kind,
cmp.config.compare.sort_text,
cmp.config.compare.length,
cmp.config.compare.order,
},
},
formatting = {
format = require("lspkind").cmp_format {
Expand All @@ -103,12 +36,21 @@ return function()
nvim_lua = "[nvim]",
path = "[path]",
shell = "[ sh]",
snippy = "[snip]",
},
},
},
}

cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
matching = { disallow_symbol_nonprefix_matching = false },
})

cmp.setup.filetype("gitcommit", {
sources = {
{ name = "cmp_git" },
Expand Down
72 changes: 23 additions & 49 deletions plugins/spec.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
config,
inputs',
lib,
pkgs,
...
}: let
Expand Down Expand Up @@ -47,44 +46,19 @@ in rec {
config = ./cmp.lua;
dependencies = {
# inherit sg;
cmp-buffer = {
src = sources.cmp-buffer;
};
cmp-fuzzy-path = {
src = sources.cmp-fuzzy-path;
dependencies = {
fuzzy_nvim = {
src = sources."fuzzy.nvim";
};
inherit fzy-lua-native;
};
};
cmp-buffer.src = sources.cmp-buffer;
cmp-cmdline.src = sources.cmp-cmdline;
cmp-git = {
src = sources.cmp-git;
config = true;
};
cmp-nvim-lsp = {
src = sources.cmp-nvim-lsp;
dependencies = {
inherit lspkind;
};
};
cmp-nvim-lsp-signature-help = {
src = sources.cmp-nvim-lsp-signature-help;
};
cmp-path = {
src = sources.cmp-path;
};
cmp-snippy = {
src = sources.cmp-snippy;
dependencies = {
snippy = {
src = sources.nvim-snippy;
};
};
};
cmp-under-comparator = {
src = sources.cmp-under-comparator;
};
cmp-path.src = sources.cmp-path;
};
};

Expand Down Expand Up @@ -119,6 +93,7 @@ in rec {
src = sources.nvim-dap;
config = ./dap.lua;
dependencies = {
inherit rapidjson;
dapui = {
src = sources.nvim-dap-ui;
};
Expand All @@ -145,7 +120,6 @@ in rec {
];
};
};
inherit rapidjson;
};
paths = with pkgs.haskellPackages; [
haskell-debug-adapter
Expand Down Expand Up @@ -198,17 +172,6 @@ in rec {
package = config.packages.luafun;
};

fzy-lua-native = let
package = pkgs.vimUtils.buildVimPlugin {
name = "fzy-lua-native";
version = sources.fzy-lua-native.rev;
src = sources.fzy-lua-native;
};
in {
inherit package;
cpath = "${package}/static/?.so";
};

gitsigns = {
src = sources."gitsigns.nvim";
config = ./gitsigns.lua;
Expand Down Expand Up @@ -552,13 +515,24 @@ in rec {
};
};

wilder = {
src = sources."wilder.nvim";
config = ./wilder.lua;
dependencies = {
cpsm.package = pkgs.vimPlugins.cpsm;
};
};
# Gonna give cmp-cmdline another try lol
# wilder = {
# src = sources."wilder.nvim";
# config = ./wilder.lua;
# dependencies = {
# cpsm.package = pkgs.vimPlugins.cpsm;
# fzy-lua-native = let
# package = pkgs.vimUtils.buildVimPlugin {
# name = "fzy-lua-native";
# version = sources.fzy-lua-native.rev;
# src = sources.fzy-lua-native;
# };
# in {
# inherit package;
# cpath = "${package}/static/?.so";
# };
# };
# };

zen-mode = {
src = sources."zen-mode.nvim";
Expand Down
6 changes: 6 additions & 0 deletions plugins/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ return function()
end,
{ desc = "Open Anything™" },
},
["<leader>f"] = {
function()
require("telescope.builtin").grep_string()
end,
{ desc = "Grep CWORD" },
},
["<leader>k"] = {
function()
require("telescope").extensions.docsets.find_word_under_cursor { previewer = false }
Expand Down

0 comments on commit 8041d4e

Please sign in to comment.