change: changed from nvimcmp to blinkcmp in one file with lsp configs (have two files for either blink or nvim-cmp)

This commit is contained in:
pika 2025-03-27 10:09:00 +01:00
parent b221457104
commit 96b01584c5
3 changed files with 572 additions and 132 deletions

View file

@ -0,0 +1,440 @@
return {
-- ╭───────────╮
-- │ blink.cmp │
-- ╰───────────╯
{
"saghen/blink.cmp",
-- optional: provides snippets for the snippet source
dependencies = { "rafamadriz/friendly-snippets" },
-- use a release tag to download pre-built binaries
version = "1.*",
-- AND/OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
-- build = 'cargo build --release',
-- If you use nix, you can build from source using latest nightly rust with:
-- build = 'nix run .#build-plugin',
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
-- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
-- 'super-tab' for mappings similar to vscode (tab to accept)
-- 'enter' for enter to accept
-- 'none' for no mappings
--
-- All presets have the following mappings:
-- C-space: Open menu or open docs if already open
-- C-n/C-p or Up/Down: Select next/previous item
-- C-e: Hide menu
-- C-k: Toggle signature help (if signature.enabled = true)
--
-- See :h blink-cmp-config-keymap for defining your own keymap
keymap = {
-- set to 'none' to disable the 'default' preset
preset = "super-tab",
["<C-k>"] = { "select_prev", "fallback" },
["<C-j>"] = { "select_next", "fallback" },
["<C-q>"] = { "hide", "fallback" },
-- disable a keymap from the preset
["<C-e>"] = {},
["<C-p>"] = {},
["<C-n>"] = {},
-- show with a list of providers
-- ["<C-space>"] = {
-- function(cmp)
-- cmp.show({ providers = { "snippets" } })
-- end,
-- },
-- control whether the next command will be run when using a function
-- ["<C-n>"] = {
-- function(cmp)
-- if some_condition then
-- return
-- end -- runs the next command
-- return true -- doesn't run the next command
-- end,
-- "select_next",
-- },
},
appearance = {
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- Adjusts spacing to ensure icons are aligned
nerd_font_variant = "mono",
highlight_ns = vim.api.nvim_create_namespace("blink_cmp"),
-- Sets the fallback highlight groups to nvim-cmp's highlight groups
-- Useful for when your theme doesn't support blink.cmp
-- Will be removed in a future release
use_nvim_cmp_as_default = true,
},
-- (Default) Only show the documentation popup when manually triggered
completion = {
documentation = {
auto_show = false,
auto_show_delay_ms = 230,
update_delay_ms = 50,
treesitter_highlighting = false,
draw = function(opts)
opts.default_implementation()
end,
window = {
min_width = 16,
max_width = 80,
max_height = 24,
border = "padded", -- Defaults to `vim.o.winborder` on nvim 0.11+ or 'padded' when not defined/<=0.10
winblend = 0,
winhighlight = "Normal:BlinkCmpDoc,FloatBorder:BlinkCmpDocBorder,EndOfBuffer:BlinkCmpDoc",
-- Note that the gutter will be disabled when border ~= 'none'
scrollbar = true,
},
},
ghost_text = {
enabled = true,
show_with_selection = true,
show_without_selection = true,
show_with_menu = true,
show_without_menu = true,
},
-- ─────────────────────────────────< mini-icons config >──────────────────────────────
menu = {
draw = {
columns = { { "kind_icon" }, { "label", gap = 1 } },
components = {
label = {
text = function(ctx)
return require("colorful-menu").blink_components_text(ctx)
end,
highlight = function(ctx)
return require("colorful-menu").blink_components_highlight(ctx)
end,
},
kind_icon = {
text = function(ctx)
local kind_icon, _, _ = require("mini.icons").get("lsp", ctx.kind)
return kind_icon
end,
-- (optional) use highlights from mini.icons
highlight = function(ctx)
local _, hl, _ = require("mini.icons").get("lsp", ctx.kind)
return hl
end,
},
-- kind = {
-- -- (optional) use highlights from mini.icons
-- highlight = function(ctx)
-- local _, hl, _ = require("mini.icons").get("lsp", ctx.kind)
-- return hl
-- end,
-- },
},
},
},
},
-- Default list of enabled providers defined so that you can extend it
-- elsewhere in your config, without redefining it, due to `opts_extend`
sources = {
default = { "lsp", "path", "snippets", "buffer" },
},
-- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
-- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
-- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
--
-- See the fuzzy documentation for more information
fuzzy = { implementation = "prefer_rust" },
},
opts_extend = { "sources.default" },
},
-- ─────────────────────────────────< colorful menu.nvim >─────────────────────────────────
{
"xzbdmw/colorful-menu.nvim",
opts = {
{
ls = {
lua_ls = {
-- Maybe you want to dim arguments a bit.
arguments_hl = "@comment",
},
gopls = {
-- By default, we render variable/function's type in the right most side,
-- to make them not to crowd together with the original label.
-- when true:
-- foo *Foo
-- ast "go/ast"
-- when false:
-- foo *Foo
-- ast "go/ast"
align_type_to_right = true,
-- When true, label for field and variable will format like "foo: Foo"
-- instead of go's original syntax "foo Foo". If align_type_to_right is
-- true, this option has no effect.
add_colon_before_type = false,
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
preserve_type_when_truncate = true,
},
-- for lsp_config or typescript-tools
ts_ls = {
-- false means do not include any extra info,
-- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
extra_info_hl = "@comment",
},
vtsls = {
-- false means do not include any extra info,
-- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
extra_info_hl = "@comment",
},
["rust-analyzer"] = {
-- Such as (as Iterator), (use std::io).
extra_info_hl = "@comment",
-- Similar to the same setting of gopls.
align_type_to_right = true,
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
preserve_type_when_truncate = true,
},
clangd = {
-- Such as "From <stdio.h>".
extra_info_hl = "@comment",
-- Similar to the same setting of gopls.
align_type_to_right = true,
-- the hl group of leading dot of "•std::filesystem::permissions(..)"
import_dot_hl = "@comment",
-- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
preserve_type_when_truncate = true,
},
zls = {
-- Similar to the same setting of gopls.
align_type_to_right = true,
},
roslyn = {
extra_info_hl = "@comment",
},
dartls = {
extra_info_hl = "@comment",
},
-- The same applies to pyright/pylance
basedpyright = {
-- It is usually import path such as "os"
extra_info_hl = "@comment",
},
-- If true, try to highlight "not supported" languages.
fallback = true,
-- this will be applied to label description for unsupport languages
fallback_extra_info_hl = "@comment",
},
-- If the built-in logic fails to find a suitable highlight group for a label,
-- this highlight is applied to the label.
fallback_highlight = "@variable",
-- If provided, the plugin truncates the final displayed text to
-- this width (measured in display cells). Any highlights that extend
-- beyond the truncation point are ignored. When set to a float
-- between 0 and 1, it'll be treated as percentage of the width of
-- the window: math.floor(max_width * vim.api.nvim_win_get_width(0))
-- Default 60.
max_width = 60,
},
},
-- config = function()
-- -- You don't need to set these options.
-- require("colorful-menu").setup({
-- ls = {
-- lua_ls = {
-- -- Maybe you want to dim arguments a bit.
-- arguments_hl = "@comment",
-- },
-- gopls = {
-- -- By default, we render variable/function's type in the right most side,
-- -- to make them not to crowd together with the original label.
--
-- -- when true:
-- -- foo *Foo
-- -- ast "go/ast"
--
-- -- when false:
-- -- foo *Foo
-- -- ast "go/ast"
-- align_type_to_right = true,
-- -- When true, label for field and variable will format like "foo: Foo"
-- -- instead of go's original syntax "foo Foo". If align_type_to_right is
-- -- true, this option has no effect.
-- add_colon_before_type = false,
-- -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
-- preserve_type_when_truncate = true,
-- },
-- -- for lsp_config or typescript-tools
-- ts_ls = {
-- -- false means do not include any extra info,
-- -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
-- extra_info_hl = "@comment",
-- },
-- vtsls = {
-- -- false means do not include any extra info,
-- -- see https://github.com/xzbdmw/colorful-menu.nvim/issues/42
-- extra_info_hl = "@comment",
-- },
-- ["rust-analyzer"] = {
-- -- Such as (as Iterator), (use std::io).
-- extra_info_hl = "@comment",
-- -- Similar to the same setting of gopls.
-- align_type_to_right = true,
-- -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
-- preserve_type_when_truncate = true,
-- },
-- clangd = {
-- -- Such as "From <stdio.h>".
-- extra_info_hl = "@comment",
-- -- Similar to the same setting of gopls.
-- align_type_to_right = true,
-- -- the hl group of leading dot of "•std::filesystem::permissions(..)"
-- import_dot_hl = "@comment",
-- -- See https://github.com/xzbdmw/colorful-menu.nvim/pull/36
-- preserve_type_when_truncate = true,
-- },
-- zls = {
-- -- Similar to the same setting of gopls.
-- align_type_to_right = true,
-- },
-- roslyn = {
-- extra_info_hl = "@comment",
-- },
-- dartls = {
-- extra_info_hl = "@comment",
-- },
-- -- The same applies to pyright/pylance
-- basedpyright = {
-- -- It is usually import path such as "os"
-- extra_info_hl = "@comment",
-- },
-- -- If true, try to highlight "not supported" languages.
-- fallback = true,
-- -- this will be applied to label description for unsupport languages
-- fallback_extra_info_hl = "@comment",
-- },
-- -- If the built-in logic fails to find a suitable highlight group for a label,
-- -- this highlight is applied to the label.
-- fallback_highlight = "@variable",
-- -- If provided, the plugin truncates the final displayed text to
-- -- this width (measured in display cells). Any highlights that extend
-- -- beyond the truncation point are ignored. When set to a float
-- -- between 0 and 1, it'll be treated as percentage of the width of
-- -- the window: math.floor(max_width * vim.api.nvim_win_get_width(0))
-- -- Default 60.
-- max_width = 60,
-- })
-- end,
},
-- ╭───────────╮
-- │ lspconfig │
-- ╰───────────╯
{
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
{ "saghen/blink.cmp" },
{ "antosha417/nvim-lsp-file-operations", config = true },
{ "folke/neodev.nvim", opts = {} },
},
config = function()
local lspconfig = require("lspconfig")
local capabilities = require("blink.cmp").get_lsp_capabilities()
local mason_lspconfig = require("mason-lspconfig")
-- Change the Diagnostic symbols in the sign column (gutter)
-- (not in youtube nvim video)
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
mason_lspconfig.setup_handlers({
function(server_name)
lspconfig[server_name].setup({
capabilities = capabilities,
})
end,
["svelte"] = function()
lspconfig["svelte"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.js", "*.ts" },
callback = function(ctx)
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
end,
})
end,
})
end,
["graphql"] = function()
lspconfig["graphql"].setup({
capabilities = capabilities,
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
})
end,
["emmet_ls"] = function()
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
filetypes = {
"html",
"typescriptreact",
"javascriptreact",
"css",
"sass",
"scss",
"less",
"svelte",
},
})
end,
["lua_ls"] = function()
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
},
},
},
})
end,
["cssls"] = function()
lspconfig["cssls"].setup({
capabilities = capabilities,
filetypes = { "css", "scss" },
})
end,
["intelephense"] = function()
lspconfig["intelephense"].setup({
capabilities = capabilities,
filetypes = { "php", "blade.php" },
})
end,
-- ["tsserver"] = function()
-- -- Replace tsserver with typescript-language-server
-- lspconfig["typescript-language-server"].setup({
-- capabilities = capabilities,
-- filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" },
-- })
-- end,
})
end,
},
}

View file

@ -1,132 +0,0 @@
return {
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
{
"hrsh7th/nvim-cmp",
dependencies = { "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip" },
},
{ "antosha417/nvim-lsp-file-operations", config = true },
{ "folke/neodev.nvim", opts = {} },
},
config = function()
local lspconfig = require("lspconfig")
local mason_lspconfig = require("mason-lspconfig")
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local keymap = vim.keymap
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf, silent = true }
opts.desc = "See available code actions"
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
opts.desc = "Smart rename"
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
opts.desc = "Show buffer diagnostics"
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
opts.desc = "Show line diagnostics"
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line
opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
opts.desc = "Restart LSP"
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
end,
})
-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()
-- Change the Diagnostic symbols in the sign column (gutter)
-- (not in youtube nvim video)
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
mason_lspconfig.setup_handlers({
function(server_name)
lspconfig[server_name].setup({
capabilities = capabilities,
})
end,
["svelte"] = function()
lspconfig["svelte"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.js", "*.ts" },
callback = function(ctx)
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
end,
})
end,
})
end,
["graphql"] = function()
lspconfig["graphql"].setup({
capabilities = capabilities,
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
})
end,
["emmet_ls"] = function()
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
filetypes = {
"html",
"typescriptreact",
"javascriptreact",
"css",
"sass",
"scss",
"less",
"svelte",
},
})
end,
["lua_ls"] = function()
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
},
},
},
})
end,
["cssls"] = function()
lspconfig["cssls"].setup({
capabilities = capabilities,
filetypes = { "css", "scss" },
})
end,
["intelephense"] = function()
lspconfig["intelephense"].setup({
capabilities = capabilities,
filetypes = { "php", "blade.php" },
})
end,
-- ["tsserver"] = function()
-- -- Replace tsserver with typescript-language-server
-- lspconfig["typescript-language-server"].setup({
-- capabilities = capabilities,
-- filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" },
-- })
-- end,
})
end,
}

View file

@ -136,4 +136,136 @@ return {
-- })
-- end,
-- },
{
"neovim/nvim-lspconfig",
event = { "BufReadPre", "BufNewFile" },
dependencies = {
{
"hrsh7th/nvim-cmp",
dependencies = { "hrsh7th/cmp-nvim-lsp", "L3MON4D3/LuaSnip", "saadparwaiz1/cmp_luasnip" },
},
{ "antosha417/nvim-lsp-file-operations", config = true },
{ "folke/neodev.nvim", opts = {} },
},
config = function()
local lspconfig = require("lspconfig")
local mason_lspconfig = require("mason-lspconfig")
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local keymap = vim.keymap
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf, silent = true }
opts.desc = "See available code actions"
keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
opts.desc = "Smart rename"
keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
opts.desc = "Show buffer diagnostics"
keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
opts.desc = "Show line diagnostics"
keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line
opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
opts.desc = "Restart LSP"
keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
end,
})
-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()
-- Change the Diagnostic symbols in the sign column (gutter)
-- (not in youtube nvim video)
local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
mason_lspconfig.setup_handlers({
function(server_name)
lspconfig[server_name].setup({
capabilities = capabilities,
})
end,
["svelte"] = function()
lspconfig["svelte"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.js", "*.ts" },
callback = function(ctx)
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.match })
end,
})
end,
})
end,
["graphql"] = function()
lspconfig["graphql"].setup({
capabilities = capabilities,
filetypes = { "graphql", "gql", "svelte", "typescriptreact", "javascriptreact" },
})
end,
["emmet_ls"] = function()
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
filetypes = {
"html",
"typescriptreact",
"javascriptreact",
"css",
"sass",
"scss",
"less",
"svelte",
},
})
end,
["lua_ls"] = function()
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
completion = {
callSnippet = "Replace",
},
},
},
})
end,
["cssls"] = function()
lspconfig["cssls"].setup({
capabilities = capabilities,
filetypes = { "css", "scss" },
})
end,
["intelephense"] = function()
lspconfig["intelephense"].setup({
capabilities = capabilities,
filetypes = { "php", "blade.php" },
})
end,
-- ["tsserver"] = function()
-- -- Replace tsserver with typescript-language-server
-- lspconfig["typescript-language-server"].setup({
-- capabilities = capabilities,
-- filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" },
-- })
-- end,
})
end,
},
}