Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configuration/.config/nvim/core/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ local plugins = {
-- nvim LSP completition
{ import = "plugins/nvim-lspconfig-config" },

{ import = "plugins/cmp-ai" }, -- need to be before cmp-config
{ import = "plugins/cmp-config" },
{ import = "plugins/luasnip-config" },

Expand Down
48 changes: 48 additions & 0 deletions configuration/.config/nvim/lua/plugins/cmp-ai.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
return {
"tzachar/cmp-ai",
dependencies = {
"nvim-lua/plenary.nvim",
},
config = function()
local cmp_ai = require("cmp_ai.config")

cmp_ai:setup({
max_lines = 10,
provider = "Ollama",
provider_options = {
model = "llama3.2",
auto_unload = false, -- Set to true to automatically unload the model when exiting nvim.
stream = true,
-- prompt = function(lines_before, lines_after)
-- return lines_before
-- end,
-- suffix = function(lines_after)
-- vim.notify("lines_after", lines_after)
-- return lines_after
-- end,
-- prompt = "<|fim▁begin|>" .. lines_before .. "<|fim▁hole|>" .. lines_after .. "<|fim▁end|>",
-- raw_response_cb = function(response)
-- -- the `response` parameter contains the raw response (JSON-like) object.

-- vim.notify(vim.inspect(response)) -- show the response as a lua table

-- vim.g.ai_raw_response = response -- store the raw response in a global variable so that you can use it somewhere else (like statusline).
-- end,
options = {
temperature = 0.2,
},
},
notify = true,
notify_callback = function(msg)
vim.notify(msg)
end,
run_on_every_keystroke = true,
ignored_file_types = {
-- default is not to ignore
-- uncomment to ignore in lua:
-- lua = true
html = true,
},
})
end,
}
31 changes: 31 additions & 0 deletions configuration/.config/nvim/lua/plugins/cmp-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ return {
config = function()
local lspkind = require("lspkind")

-- for sorting the results
local compare = require("cmp.config.compare")

-- Set up nvim-cmp.
local cmp = require("cmp")

Expand Down Expand Up @@ -43,6 +46,13 @@ return {
behavior = cmp.ConfirmBehavior.Insert,
select = true, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
["<C-x>"] = cmp.mapping(cmp.mapping.complete({
config = {
sources = cmp.config.sources({
{ name = "cmp_ai" },
}),
},
})),
}),

-- you can also configure:
Expand All @@ -51,6 +61,7 @@ return {
-- max_item_count - useful when having to many results from specific section
sources = cmp.config.sources({
-- The order reflect in completion results
{ name = "cmp_ai" }, -- include input from cmp-ai plugin
{ name = "cmp_git" },
{ name = "nvim_lsp" },
{ name = "path" },
Expand Down Expand Up @@ -107,6 +118,11 @@ return {
Event = "",
Operator = "󰆕",
TypeParameter = "",
-- icons for cmp-ai completion
HF = "",
OpenAI = "",
Codestral = "",
Bard = "",
},

-- The function below will be called before any actual modifications from lspkind
Expand All @@ -124,6 +140,21 @@ return {
}),
},

sorting = {
priority_weight = 2,
comparators = {
require("cmp_ai.compare"),
compare.offset,
compare.exact,
compare.score,
compare.recently_used,
compare.kind,
compare.sort_text,
compare.length,
compare.order,
},
},

-- source: https://github.com/hrsh7th/nvim-cmp/issues/598
performance = {
trigger_debounce_time = 100, -- time after last key-input to next reload of available options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ return {
desc = "[g]o to [i]mplementation",
buffer = ev.buf,
})
keymap.set("n", "gr", vim.lsp.buf.references, {
desc = "[g]o to [r]eferences",
-- keymap.set("n", "gr", vim.lsp.buf.references, {
-- desc = "[g]o to [r]eferences",
-- buffer = ev.buf,
-- })
keymap.set("n", "gr", "<cmd>Telescope lsp_references<cr>", {
desc = "[g]o to telescope [r]eferences",
buffer = ev.buf,
})
keymap.set("n", "<leader>dl", "<cmd>Telescope diagnostics<cr>", {
Expand Down