feat(nvim): add cmp-async-path

dev-docs
Moritz Böhme 2023-04-17 14:37:06 +02:00
parent d6fbbb945c
commit f47c711d57
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
5 changed files with 74 additions and 39 deletions

View File

@ -98,6 +98,22 @@
"type": "github"
}
},
"cmp-async-path": {
"flake": false,
"locked": {
"lastModified": 1673896803,
"narHash": "sha256-dgAiVbdMiKjiKWk+dJf/Zz8T20+D4OalGH5dTzYi5aM=",
"owner": "FelipeLema",
"repo": "cmp-async-path",
"rev": "d8229a93d7b71f22c66ca35ac9e6c6cd850ec61d",
"type": "github"
},
"original": {
"owner": "FelipeLema",
"repo": "cmp-async-path",
"type": "github"
}
},
"copilot-lua": {
"flake": false,
"locked": {
@ -861,6 +877,7 @@
"arkenfox-userjs": "arkenfox-userjs",
"asus-touchpad-numpad-driver": "asus-touchpad-numpad-driver",
"attic": "attic",
"cmp-async-path": "cmp-async-path",
"copilot-lua": "copilot-lua",
"emacs": "emacs",
"flake-utils": "flake-utils_3",

View File

@ -51,6 +51,11 @@
hyprpaper.url = "github:hyprwm/hyprpaper";
hypr-contrib.url = "github:hyprwm/contrib";
attic.url = "github:zhaofengli/attic";
attic.inputs.nixpkgs.follows = "nixpkgs";
attic.inputs.nixpkgs-stable.follows = "stable";
attic.inputs.flake-utils.follows = "flake-utils";
nvim-treesitter-textsubjects.url = "github:RRethy/nvim-treesitter-textsubjects";
nvim-treesitter-textsubjects.flake = false;
@ -66,10 +71,8 @@
advanced-git-search-nvim.url = "github:aaronhallaert/advanced-git-search.nvim";
advanced-git-search-nvim.flake = false;
attic.url = "github:zhaofengli/attic";
attic.inputs.nixpkgs.follows = "nixpkgs";
attic.inputs.nixpkgs-stable.follows = "stable";
attic.inputs.flake-utils.follows = "flake-utils";
cmp-async-path.url = "github:FelipeLema/cmp-async-path";
cmp-async-path.flake = false;
};
outputs =

View File

@ -63,6 +63,7 @@ in
yamlfmt
];
plugins = with pkgs.vimPlugins; [
cmp-async-path
cmp-nvim-lsp
cmp_luasnip
copilot-cmp

View File

@ -1,5 +1,33 @@
require("impatient")
---merge tables
---@param ... table[]
---@return table
local function table_merge(...)
local tables_to_merge = { ... }
assert(#tables_to_merge > 1, "There should be at least two tables to merge them")
for k, t in ipairs(tables_to_merge) do
assert(type(t) == "table", string.format("Expected a table as function parameter %d", k))
end
local result = tables_to_merge[1]
for i = 2, #tables_to_merge do
local from = tables_to_merge[i]
for k, v in pairs(from) do
if type(v) == "table" then
result[k] = result[k] or {}
result[k] = table_merge(result[k], v)
else
result[k] = v
end
end
end
return result
end
require("nvim-treesitter.configs").setup({
sync_install = false,
auto_install = false,
@ -16,6 +44,13 @@ vim.api.nvim_create_autocmd("InsertEnter", {
local luasnip = require("luasnip")
require("copilot_cmp").setup()
local default_sources = {
{ name = "async_path", priority = 4 },
{ name = "copilot", priority = 3 },
{ name = "luasnip", priority = 2 },
{ name = "nvim_lsp", priority = 4 },
}
cmp.setup({
formatting = {
format = require("lspkind").cmp_format({
@ -58,45 +93,18 @@ vim.api.nvim_create_autocmd("InsertEnter", {
end
end, { "i", "s" }),
}),
sources = {
{ name = "buffer", priority = 1 },
{ name = "copilot", priority = 8 },
{ name = "luasnip", priority = 7 },
{ name = "nvim_lsp", priority = 9 },
{ name = "orgmode", priority = 9 },
},
sources = default_sources,
})
cmp.setup.filetype("org", {
sources = table_merge(default_sources, {
{ name = "buffer", priority = 5 },
{ name = "orgmode", priority = 5 },
}),
})
end,
})
---merge tables
---@param ... table[]
---@return table
local function table_merge(...)
local tables_to_merge = { ... }
assert(#tables_to_merge > 1, "There should be at least two tables to merge them")
for k, t in ipairs(tables_to_merge) do
assert(type(t) == "table", string.format("Expected a table as function parameter %d", k))
end
local result = tables_to_merge[1]
for i = 2, #tables_to_merge do
local from = tables_to_merge[i]
for k, v in pairs(from) do
if type(v) == "table" then
result[k] = result[k] or {}
result[k] = table_merge(result[k], v)
else
result[k] = v
end
end
end
return result
end
local lsp_lines = require("lsp_lines")
lsp_lines.setup()
-- Disable virtual_text since it's redundant due to lsp_lines.

View File

@ -31,5 +31,11 @@ with lib.my;
version = mkVersionInput inputs.advanced-git-search-nvim;
src = inputs.advanced-git-search-nvim;
};
cmp-async-path = prev.vimPlugins.cmp-path.overrideAttrs (old: {
pname = "cmp-async-path";
version = mkVersionInput inputs.cmp-async-path;
src = inputs.cmp-async-path;
});
};
}