This commit is contained in:
Christian Nieves
2024-12-16 14:42:15 +00:00
parent 9ceca10f72
commit 664c555107
4 changed files with 353 additions and 352 deletions

View File

@ -1,3 +1,3 @@
{ {
"lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" } "lazy.nvim": { "branch": "main", "commit": "56ead98e05bb37a4ec28930a54d836d033cf00f2" }
} }

View File

@ -2,112 +2,115 @@ local use_google = require("utils").use_google
local flags = require("utils").flags local flags = require("utils").flags
return { return {
{ {
"saghen/blink.compat", "saghen/blink.compat",
-- use the latest release, via version = '*', if you also use the latest release for blink.cmp -- use the latest release, via version = '*', if you also use the latest release for blink.cmp
version = "*", version = "*",
-- lazy.nvim will automatically load the plugin when it's required by blink.cmp -- lazy.nvim will automatically load the plugin when it's required by blink.cmp
lazy = true, lazy = true,
-- make sure to set opts so that lazy.nvim calls blink.compat's setup -- make sure to set opts so that lazy.nvim calls blink.compat's setup
opts = {}, opts = {
cond = flags.blink, impersonate_nvim_cmp = use_google(), -- only cider needs this
}, },
{ cond = not use_google(),
"saghen/blink.cmp", },
lazy = false, -- lazy loading handled internally {
cond = flags.blink, "saghen/blink.cmp",
dependencies = { lazy = false, -- lazy loading handled internally
"Exafunction/codeium.nvim", cond = flags.blink,
"mikavilpas/blink-ripgrep.nvim", dependencies = {
"hrsh7th/cmp-cmdline", "Exafunction/codeium.nvim",
-- "FelipeLema/cmp-async-path", "mikavilpas/blink-ripgrep.nvim",
"chrisgrieser/cmp-nerdfont", "hrsh7th/cmp-cmdline",
"hrsh7th/cmp-emoji", -- "FelipeLema/cmp-async-path",
"rafamadriz/friendly-snippets", -- optional: provides snippets for the snippet source "chrisgrieser/cmp-nerdfont",
}, "hrsh7th/cmp-emoji",
version = "v0.*", -- use a release tag to download pre-built binaries "rafamadriz/friendly-snippets", -- optional: provides snippets for the snippet source
-- build = 'cargo build --release', },
version = "v0.*", -- use a release tag to download pre-built binaries
-- build = 'cargo build --release',
---@module 'blink.cmp' ---@module 'blink.cmp'
---@type blink.cmp.Config ---@type blink.cmp.Config
opts = { opts = {
keymap = { keymap = {
["<C-space>"] = { "show", "show_documentation", "hide_documentation" }, ["<C-space>"] = { "show", "show_documentation", "hide_documentation" },
["<C-e>"] = { "hide", "fallback" }, ["<C-e>"] = { "hide", "fallback" },
["<CR>"] = { "accept", "fallback" }, ["<CR>"] = { "accept", "fallback" },
["<Tab>"] = { "select_next", "snippet_forward", "accept", "fallback" }, ["<Tab>"] = { "select_next", "snippet_forward", "accept", "fallback" },
["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback" }, ["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback" },
["<Up>"] = { "select_prev", "fallback" }, ["<Up>"] = { "select_prev", "fallback" },
["<Down>"] = { "select_next", "fallback" }, ["<Down>"] = { "select_next", "fallback" },
["<S-Up>"] = { "scroll_documentation_up", "fallback" }, ["<S-Up>"] = { "scroll_documentation_up", "fallback" },
["<S-Down>"] = { "scroll_documentation_down", "fallback" }, ["<S-Down>"] = { "scroll_documentation_down", "fallback" },
}, },
sources = { sources = {
default = function(ctx) default = function(ctx)
local providerToEnable = { local providerToEnable = {
"lsp", "lsp",
"path", "path",
"crates", "crates",
"snippets", "snippets",
"ripgrep", "ripgrep",
"emoji", "emoji",
"nerdfont", "nerdfont",
"buffer", "buffer",
} }
print(vim.inspect(providerToEnable)) if use_google() then
if use_google() then table.insert(providerToEnable, "nvim_ciderlsp")
table.insert(providerToEnable, "nvim_ciderlsp") table.insert(providerToEnable, "buganizer")
table.insert(providerToEnable, "buganizer") else
else table.insert(providerToEnable, "codeium")
table.insert(providerToEnable, "codeium") end
end vim.notify("BOOOOOOP")
return providerToEnable vim.notify(vim.inspect(providerToEnable))
end, return providerToEnable
}, end,
providers = { },
-- dont show LuaLS require statements when lazydev has items providers = {
lsp = { fallback_for = { "lazydev" } }, -- dont show LuaLS require statements when lazydev has items
lazydev = { name = "LazyDev", module = "lazydev.integrations.blink" }, lsp = { fallback_for = { "lazydev" } },
ripgrep = { lazydev = { name = "LazyDev", module = "lazydev.integrations.blink" },
module = "blink-ripgrep", ripgrep = {
name = "Ripgrep", module = "blink-ripgrep",
-- the options below are optional, some default values are shown name = "Ripgrep",
---@module "blink-ripgrep" -- the options below are optional, some default values are shown
---@type blink-ripgrep.Options ---@module "blink-ripgrep"
opts = { ---@type blink-ripgrep.Options
prefix_min_len = 3, opts = {
context_size = 5, prefix_min_len = 3,
max_filesize = "1M", context_size = 5,
additional_rg_options = {}, max_filesize = "1M",
}, additional_rg_options = {},
}, },
nvim_ciderlsp = { },
name = "nvim_ciderlsp", nvim_ciderlsp = {
module = "blink.compat.source", name = "nvim_ciderlsp",
}, module = "blink.compat.source",
buganizer = { },
name = "nvim_buganizer", buganizer = {
module = "blink.compat.source", name = "nvim_buganizer",
}, module = "blink.compat.source",
codeium = { },
name = "codeium", codeium = {
module = "blink.compat.source", name = "codeium",
}, module = "blink.compat.source",
}, },
-- experimental signature help support },
signature = { enabled = true }, -- experimental signature help support
completion = { signature = { enabled = true },
trigger = { completion = {
show_on_x_blocked_trigger_characters = { "'", '"', "(", "{" }, trigger = {
}, show_on_x_blocked_trigger_characters = { "'", '"', "(", "{" },
}, },
}, },
},
-- allows extending the providers array elsewhere in your config -- allows extending the providers array elsewhere in your config
-- without having to redefine it -- without having to redefine it
opts_extend = { "sources.default" }, opts_extend = { "sources.default" },
}, },
} }

View File

@ -2,191 +2,191 @@ local use_google = require("utils").use_google
local flags = require("utils").flags local flags = require("utils").flags
return { return {
{ {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
event = { "InsertEnter", "CmdlineEnter" }, event = { "InsertEnter", "CmdlineEnter" },
cond = not flags.blink, cond = use_google(),
dependencies = { dependencies = {
"Exafunction/codeium.nvim", "Exafunction/codeium.nvim",
"FelipeLema/cmp-async-path", "FelipeLema/cmp-async-path",
"amarakon/nvim-cmp-buffer-lines", "amarakon/nvim-cmp-buffer-lines",
"chrisgrieser/cmp-nerdfont", "chrisgrieser/cmp-nerdfont",
"dmitmel/cmp-cmdline-history", "dmitmel/cmp-cmdline-history",
"f3fora/cmp-spell", "f3fora/cmp-spell",
"hrsh7th/cmp-buffer", "hrsh7th/cmp-buffer",
"hrsh7th/cmp-calc", "hrsh7th/cmp-calc",
"hrsh7th/cmp-cmdline", "hrsh7th/cmp-cmdline",
"hrsh7th/cmp-emoji", "hrsh7th/cmp-emoji",
"hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-nvim-lsp-document-symbol", "hrsh7th/cmp-nvim-lsp-document-symbol",
-- "hrsh7th/cmp-nvim-lsp-signature-help", -- "hrsh7th/cmp-nvim-lsp-signature-help",
"hrsh7th/cmp-nvim-lua", "hrsh7th/cmp-nvim-lua",
"lukas-reineke/cmp-under-comparator", "lukas-reineke/cmp-under-comparator",
"onsails/lspkind.nvim", "onsails/lspkind.nvim",
"ray-x/cmp-treesitter", "ray-x/cmp-treesitter",
}, },
config = function() config = function()
vim.opt.shortmess:append("c") vim.opt.shortmess:append("c")
vim.opt.completeopt = { "menu", "menuone", "noselect" } vim.opt.completeopt = { "menu", "menuone", "noselect" }
local cmp = require("cmp") local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
local compare = cmp.config.compare local compare = cmp.config.compare
local conditionalSources = {} local conditionalSources = {}
if use_google() then if use_google() then
table.insert(conditionalSources, { name = "nvim_ciderlsp", priority = 8 }) table.insert(conditionalSources, { name = "nvim_ciderlsp", priority = 8 })
table.insert(conditionalSources, { name = "buganizer", option = { notifications_enabled = true } }) table.insert(conditionalSources, { name = "buganizer", option = { notifications_enabled = true } })
else else
table.insert(conditionalSources, { name = "codeium", priority = 8 }) table.insert(conditionalSources, { name = "codeium", priority = 8 })
end end
local lspkind = require("lspkind") local lspkind = require("lspkind")
lspkind.init() lspkind.init()
cmp.setup.filetype("txt", { cmp.setup.filetype("txt", {
enabled = false, enabled = false,
}) })
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ "/", "?" }, { cmp.setup.cmdline({ "/", "?" }, {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = "treesitter" }, { name = "treesitter" },
{ name = "buffer" }, { name = "buffer" },
}), }),
}) })
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(":", { cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(), mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ sources = cmp.config.sources({
-- { name = "nvim_lsp_signature_help", priority = 9 }, -- { name = "nvim_lsp_signature_help", priority = 9 },
{ name = "async_path" }, { name = "async_path" },
{ name = "cmdline", option = { ignore_cmds = { "edit", "write", "tabedit" } } }, { name = "cmdline", option = { ignore_cmds = { "edit", "write", "tabedit" } } },
}), }),
}) })
cmp.setup({ cmp.setup({
preselect = cmp.PreselectMode.None, preselect = cmp.PreselectMode.None,
performance = { performance = {
-- debounce = 60, -- debounce = 60,
-- throttle = 30, -- throttle = 30,
fetching_timeout = 300, fetching_timeout = 300,
-- confirm_resolve_timeout = 80, -- confirm_resolve_timeout = 80,
-- async_budget = 1, -- async_budget = 1,
-- max_view_entries = 200, -- max_view_entries = 200,
}, },
sources = cmp.config.sources( sources = cmp.config.sources(
require("utils").TableConcat(conditionalSources, { require("utils").TableConcat(conditionalSources, {
-- { name = "nvim_lsp_signature_help", priority = 9 }, -- { name = "nvim_lsp_signature_help", priority = 9 },
-- Conditional sources injected here. -- Conditional sources injected here.
{ name = "luasnip", priority = 7 }, { name = "luasnip", priority = 7 },
{ name = "nvim_lsp", priority = 6 }, { name = "nvim_lsp", priority = 6 },
{ name = "async_path" }, { name = "async_path" },
{ name = "crates" }, { name = "crates" },
{ name = "calc" }, { name = "calc" },
}), }),
{ -- symbols/icons group { -- symbols/icons group
{ name = "nerdfont" }, { name = "nerdfont" },
{ name = "emoji" }, { name = "emoji" },
}, },
{ -- fallback { -- fallback
{ name = "treesitter" }, { name = "treesitter" },
{ name = "buffer" }, { name = "buffer" },
} }
), ),
sorting = { sorting = {
comparators = { comparators = {
-- compare.score_offset, -- not good at all -- compare.score_offset, -- not good at all
compare.priority, compare.priority,
compare.score, -- based on : score = score + ((#sources - (source_index - 1)) * sorting.priority_weight) compare.score, -- based on : score = score + ((#sources - (source_index - 1)) * sorting.priority_weight)
compare.recently_used, compare.recently_used,
compare.offset, compare.offset,
compare.order, compare.order,
-- compare.exact, -- compare.exact,
compare.kind, compare.kind,
-- compare.length, -- useless -- compare.length, -- useless
}, },
}, },
formatting = { formatting = {
format = lspkind.cmp_format({ format = lspkind.cmp_format({
menu = { menu = {
async_path = " path", async_path = " path",
buffer = " Buf", buffer = " Buf",
cmdline = " cmd", cmdline = " cmd",
codeium = "󰚩 Codeium", codeium = "󰚩 Codeium",
crates = " rust", crates = " rust",
luasnip = " snip", luasnip = " snip",
buganizer = " Buganizer", buganizer = " Buganizer",
nerdfont = "󰊪 nerdfont", nerdfont = "󰊪 nerdfont",
nvim_ciderlsp = "󰚩 Cider", nvim_ciderlsp = "󰚩 Cider",
nvim_lsp_signature_help = "󰊕", nvim_lsp_signature_help = "󰊕",
nvim_lsp = " LSP", nvim_lsp = " LSP",
nvim_lua = " lua", nvim_lua = " lua",
treesitter = "󰙅 ts", treesitter = "󰙅 ts",
}, },
}), }),
}, },
snippet = { snippet = {
expand = function(args) expand = function(args)
require("luasnip").lsp_expand(args.body) require("luasnip").lsp_expand(args.body)
end, end,
}, },
mapping = { mapping = {
["<S-Up>"] = cmp.mapping.scroll_docs(-4), ["<S-Up>"] = cmp.mapping.scroll_docs(-4),
["<S-Down>"] = cmp.mapping.scroll_docs(4), ["<S-Down>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping.close(), ["<C-e>"] = cmp.mapping.close(),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<CR>"] = cmp.mapping(function(fallback) ["<CR>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
if luasnip.expandable() then if luasnip.expandable() then
luasnip.expand() luasnip.expand()
else else
cmp.confirm({ cmp.confirm({
select = true, select = true,
}) })
end end
else else
fallback() fallback()
end end
end), end),
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback) ["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
else else
fallback() fallback()
end end
end, { "i", "s" }), end, { "i", "s" }),
["<Up>"] = cmp.mapping(function(fallback) ["<Up>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
else else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`. fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end end
end), end),
["<Down>"] = cmp.mapping(function(fallback) ["<Down>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
else else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`. fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end end
end), end),
}, },
}) })
end, end,
}, },
} }

View File

@ -1,102 +1,100 @@
local M = { local M = {
use_google_cache = nil, use_google_cache = nil,
flags = { flags = {},
blink = true,
},
} }
function M.exec(command, args) function M.exec(command, args)
local Job = require("plenary.job") local Job = require("plenary.job")
local job = Job:new({ local job = Job:new({
command = command, command = command,
args = args, args = args,
}) })
job:sync() job:sync()
job:wait() job:wait()
return job:result() return job:result()
end end
function M.map(mode, lhs, rhs, opts) function M.map(mode, lhs, rhs, opts)
local options = { noremap = true } local options = { noremap = true }
if opts then if opts then
options = vim.tbl_extend("force", options, opts) options = vim.tbl_extend("force", options, opts)
end end
-- vim.api.nvim_set_keymap(mode, lhs, rhs, options) -- vim.api.nvim_set_keymap(mode, lhs, rhs, options)
vim.keymap.set(mode, lhs, rhs, options) vim.keymap.set(mode, lhs, rhs, options)
end end
function M.use_google() function M.use_google()
if M.use_google_cache == nil then if M.use_google_cache == nil then
M.use_google_cache = M.file_exists(os.getenv("HOME") .. "/use_google") M.use_google_cache = M.file_exists(os.getenv("HOME") .. "/use_google")
end end
return M.use_google_cache return M.use_google_cache
end end
function M.file_exists(name) function M.file_exists(name)
local f = io.open(name, "r") local f = io.open(name, "r")
if f ~= nil then if f ~= nil then
io.close(f) io.close(f)
return true return true
else else
return false return false
end end
end end
function M.dump(o) function M.dump(o)
if type(o) == "table" then if type(o) == "table" then
local s = "{ " local s = "{ "
for k, v in pairs(o) do for k, v in pairs(o) do
if type(k) ~= "number" then if type(k) ~= "number" then
k = '"' .. k .. '"' k = '"' .. k .. '"'
end end
s = s .. "[" .. k .. "] = " .. M.dump(v) .. "," s = s .. "[" .. k .. "] = " .. M.dump(v) .. ","
end end
return s .. "} " return s .. "} "
else else
return tostring(o) return tostring(o)
end end
end end
function M.tprint(tbl, indent) function M.tprint(tbl, indent)
if not indent then if not indent then
indent = 0 indent = 0
end end
local toprint = string.rep(" ", indent) .. "{\r\n" local toprint = string.rep(" ", indent) .. "{\r\n"
indent = indent + 2 indent = indent + 2
for k, v in pairs(tbl) do for k, v in pairs(tbl) do
toprint = toprint .. string.rep(" ", indent) toprint = toprint .. string.rep(" ", indent)
if type(k) == "number" then if type(k) == "number" then
toprint = toprint .. "[" .. k .. "] = " toprint = toprint .. "[" .. k .. "] = "
elseif type(k) == "string" then elseif type(k) == "string" then
toprint = toprint .. k .. "= " toprint = toprint .. k .. "= "
end end
if type(v) == "number" then if type(v) == "number" then
toprint = toprint .. v .. ",\r\n" toprint = toprint .. v .. ",\r\n"
elseif type(v) == "string" then elseif type(v) == "string" then
toprint = toprint .. '"' .. v .. '",\r\n' toprint = toprint .. '"' .. v .. '",\r\n'
elseif type(v) == "table" then elseif type(v) == "table" then
toprint = toprint .. M.tprint(v, indent + 2) .. ",\r\n" toprint = toprint .. M.tprint(v, indent + 2) .. ",\r\n"
else else
toprint = toprint .. '"' .. tostring(v) .. '",\r\n' toprint = toprint .. '"' .. tostring(v) .. '",\r\n'
end end
end end
toprint = toprint .. string.rep(" ", indent - 2) .. "}" toprint = toprint .. string.rep(" ", indent - 2) .. "}"
return toprint return toprint
end end
function M.log(message) function M.log(message)
local log_file_path = vim.fn.expand("$HOME/nvim.log") local log_file_path = vim.fn.expand("$HOME/nvim.log")
local log_file = io.open(log_file_path, "a") local log_file = io.open(log_file_path, "a")
io.output(log_file) io.output(log_file)
io.write(message .. "\n") io.write(message .. "\n")
io.close(log_file) io.close(log_file)
end end
function M.TableConcat(t1, t2) function M.TableConcat(t1, t2)
for i = 1, #t2 do for i = 1, #t2 do
t1[#t1 + 1] = t2[i] t1[#t1 + 1] = t2[i]
end end
return t1 return t1
end end
return M return M