Skip to content

Commit

Permalink
feat: update blink config
Browse files Browse the repository at this point in the history
  • Loading branch information
fcying committed Nov 1, 2024
1 parent d71c719 commit 915bab5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 68 deletions.
15 changes: 7 additions & 8 deletions lua/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,6 @@ function M.setup()

vim.diagnostic.config({ virtual_text = false })

local capabilities
if g.complete_engine == "blink" then
capabilities = nil
else
capabilities = require("cmp_nvim_lsp").default_capabilities()
end

local lsp_zero = require("lsp-zero")
local lsp_attach = function(client, bufnr) ---@diagnostic disable-line
local opts = { buffer = bufnr }
Expand Down Expand Up @@ -346,7 +339,13 @@ function M.setup()
if fn.index(Option.lsp, server_name) ~= -1 then
return
else
lspconfig[server_name].setup(lsp_opts[server_name] or {})
local config = lsp_opts[server_name] or {}
if g.complete_engine == "blink" then
config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities)
else
config.capabilities = require("cmp_nvim_lsp").default_capabilities()
end
lspconfig[server_name].setup(config)
end
end,
}
Expand Down
56 changes: 32 additions & 24 deletions lua/plugins/blink.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,30 @@ local opts = {
highlight = {
use_nvim_cmp_as_default = true,
},
-- set to 'mono' for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
nerd_font_variant = "normal",
-- accept = { auto_brackets = { enabled = true } },
trigger = { signature_help = { enabled = true } },

keymap = {
show = "<C-l>",
hide = "<C-e>",
accept = "<CR>",
select_prev = { "<Up>", "<C-p>", "<S-Tab>" },
select_next = { "<Down>", "<C-n>", "<Tab>" },
["<C-l>"] = { "show", "show_documentation", "hide_documentation" },
["<C-e>"] = { "hide" },
["<CR>"] = { "select_and_accept" },

show_documentation = {},
hide_documentation = {},
scroll_documentation_up = "<C-b>",
scroll_documentation_down = "<C-f>",
["<Up>"] = { "select_prev", "fallback" },
["<Down>"] = { "select_next", "fallback" },
["<C-p>"] = { "select_prev", "fallback" },
["<C-n>"] = { "select_next", "fallback" },
["<S-Tab>"] = { "select_prev", "snippet_backward", "fallback" },
["<Tab>"] = { "select_next", "snippet_forward", "fallback" },

snippet_forward = "<Tab>",
snippet_backward = "<S-Tab>",
["<C-b>"] = { "scroll_documentation_up", "fallback" },
["<C-f>"] = { "scroll_documentation_down", "fallback" },
},
sources = {
completion = {
enabled_providers = { "lsp", "path", "snippets", "buffer", "dictionary" },
},
providers = {
{ "blink.cmp.sources.lsp", name = "LSP", score_offset = 0 },
{ "blink.cmp.sources.buffer", name = "Buf", fallback_for = { "LSP" } },
{ "blink.cmp.sources.path", name = "Path", score_offset = 3 },
{
"blink.cmp.sources.snippets",
name = "Snip",
snippets = {
name = "Snippets",
module = "blink.cmp.sources.snippets",
score_offset = -3,
opts = {
friendly_snippets = true,
Expand All @@ -39,15 +35,27 @@ local opts = {
ignored_filetypes = {},
},
},
dictionary = {
name = "dictionary",
module = "blink.compat.source",
score_offset = 3,
opts = {
{ name = "dictionary" },
}
},
},
},
}

return {
"saghen/blink.cmp",
lazy = false,
dependencies = "rafamadriz/friendly-snippets",
version = nil,
build = "cargo build --release",
dependencies = {
"rafamadriz/friendly-snippets",
{ "saghen/blink.compat", opts = { impersontate_nvim_cmp = true, } },
{ import = "plugins.cmp_dictionary" },
},
version = "*",
-- build = "cargo build --release",
opts = opts,
}
37 changes: 1 addition & 36 deletions lua/plugins/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,6 @@ local luasnip_opts = function()
-- ]])
end

local cmp_dictionary = function()
local dict_path = vim.g.config_dir .. "/dict/"
local dict = {
["*"] = { dict_path .. "dictionary" },
["xmake"] = { dict_path .. "xmake.dict" },
["go"] = { dict_path .. "go.dict" },
["cmake"] = { dict_path .. "cmake.dict" },
}

local function get_dict_path(file)
local paths = {}
if file:find(".*xmake.lua") then
paths = dict.xmake
else
paths = dict[vim.bo.filetype] or {}
end
vim.list_extend(paths, dict["*"])
--vim.print(paths)
return paths
end

require("cmp_dictionary").setup({
paths = get_dict_path(vim.fn.expand("%")),
exact_length = 2,
first_case_insensitive = false,
})

vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*",
callback = function(ev)
require("cmp_dictionary").setup({ paths = get_dict_path(ev.file) })
end,
})
end

local cmp_opts = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
Expand Down Expand Up @@ -176,7 +141,7 @@ return {
{ "dmitmel/cmp-cmdline-history" },
-- { "hrsh7th/cmp-omni" },
-- { "quangnguyen30192/cmp-nvim-tags" },
{ "uga-rosa/cmp-dictionary", config = cmp_dictionary },
{ import = "plugins.cmp_dictionary" },
},
config = cmp_opts,
}
39 changes: 39 additions & 0 deletions lua/plugins/cmp_dictionary.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
local cmp_dictionary = function()
local dict_path = vim.g.config_dir .. "/dict/"
local dict = {
["*"] = { dict_path .. "dictionary" },
["xmake"] = { dict_path .. "xmake.dict" },
["go"] = { dict_path .. "go.dict" },
["cmake"] = { dict_path .. "cmake.dict" },
}

local function get_dict_path(file)
local paths = {}
if file:find(".*xmake.lua") then
paths = dict.xmake
else
paths = dict[vim.bo.filetype] or {}
end
vim.list_extend(paths, dict["*"])
--vim.print(paths)
return paths
end

require("cmp_dictionary").setup({
paths = get_dict_path(vim.fn.expand("%")),
exact_length = 2,
first_case_insensitive = false,
})

vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*",
callback = function(ev)
require("cmp_dictionary").setup({ paths = get_dict_path(ev.file) })
end,
})
end

return {
"uga-rosa/cmp-dictionary",
config = cmp_dictionary,
}

0 comments on commit 915bab5

Please sign in to comment.