Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu takes too long to update on typing characters #539

Closed
2 tasks done
the-fuckin-nobody opened this issue Dec 13, 2024 · 4 comments
Closed
2 tasks done

Menu takes too long to update on typing characters #539

the-fuckin-nobody opened this issue Dec 13, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@the-fuckin-nobody
Copy link

Make sure you have done the following

  • I have updated to the latest version of blink.cmp
  • I have read the README

Bug Description

Here's a videos for demonstration of the bug:

recording.mp4

As seen in the video it takes too long to update the completion menu while typing without taking breaks.

Relevant configuration

local Plugin = {
	"Saghen/blink.cmp",
	cond = true,
	event = { "InsertEnter", "CmdLineEnter" },
	build = "cargo build --release",
}

Plugin.dependencies = {
	"rafamadriz/friendly-snippets",
	"L3MON4D3/LuaSnip",
	"echasnovski/mini.icons",
	-- { "Saghen/blink.compat", opts = { impersonate_nvim_cmp = true } },
}

Plugin.config = function()
	local blink_cmp = require("blink.cmp")
	local luasnip = require("luasnip")
	blink_cmp.setup({
		enabled = function()
			return vim.bo.buftype ~= "prompt"
		end,
		keymap = {
			preset = "default",
			["<m-k>"] = { "select_prev", "fallback" },
			["<m-j>"] = { "select_next", "fallback" },
			["<Tab>"] = {
				function(cmp)
					if vim.fn.getcmdtype() ~= "" then
						return cmp.select_next()
					elseif cmp.snippet_active() then
						return cmp.accept()
					else
						return cmp.snippet_forward()
					end
				end,
				"snippet_forward",
				"fallback",
			},
			["<CR>"] = {
				function(cmp)
					if vim.fn.getcmdtype() == "" then
						return cmp.select_and_accept()
					end
				end,
				"fallback",
			},
			["<S-Tab>"] = {
				function(cmp)
					if vim.fn.getcmdtype() ~= "" then
						cmp.select_next()
					end
				end,
				"snippet_backward",
				"fallback",
			},
			["<m-f>"] = { "scroll_documentation_down", "fallback" },
			["<m-b>"] = { "scroll_documentation_up", "fallback" },
			["<m-c>"] = { "show", "cancel", "fallback" },
		},
		snippets = {
			expand = function(snippet)
				luasnip.lsp_expand(snippet)
			end,
			active = function(filter)
				if filter and filter.direction then
					return luasnip.expandable() or luasnip.jumpable(filter.direction)
				end
				return luasnip.in_snippet()
			end,
			jump = function(direction)
				if luasnip.jumpable(direction) then
					luasnip.jump(direction)
				end
			end,
		},
		completion = {
			keyword = {
				range = "full",
				regex = "[-_]\\|\\k",
				exclude_from_prefix_regex = "[\\-]",
			},
			trigger = {
				show_in_snippet = true,
				prefetch_on_insert = true,
				show_on_keyword = true,
				show_on_trigger_character = true,
				show_on_accept_on_trigger_character = false,
				show_on_blocked_trigger_characters = { ",", "\t", "\n" },
				show_on_insert_on_trigger_character = true,
				show_on_x_blocked_trigger_characters = { "(", "'", '"' },
			},
			list = {
				max_items = 200,
				selection = 'auto_insert',
				cycle = {
					from_bottom = true,
					from_top = true,
				},
			},
			accept = {
				create_undo_point = true,
				auto_brackets = {
					enabled = vim.bo.buftype ~= "prompt" or vim.treesitter.get_node():type() ~= "arguments",
					default_brackets = { "(", ")", "{", "}" },
					override_brackets_for_filetypes = {},
					kind_resolution = {
						enabled = true,
						blocked_filetypes = { ".txt" },
					},
					semantic_token_resolution = {
						enabled = false,
						blocked_filetypes = {},
						timeout_ms = 400,
					},
					blocked_filetypes = { ".txt" },
					force_allow_filetypes = {},
				},
			},
			menu = {
				cmdline_position = function()
					if vim.g.ui_cmdline_pos ~= nil then
						local pos = vim.g.ui_cmdline_pos -- (1, 0)-indexed
						return { pos[1] - 1, pos[2] }
					end
					return { vim.o.lines - 1, 0 }
				end,
				enabled = true,
				min_width = 15,
				max_height = 10,
				border = "none",
				winblend = 0,
				winhighlight = "Normal:BlinkCmpMenu,FloatBorder:BlinkCmpMenuBorder,CursorLine:BlinkCmpMenuSelection,Search:None",
				scrollbar = true,
				scrolloff = 2,
				direction_priority = { "s", "n" },
				auto_show = true,
				draw = {
					align_to_component = "label",
					padding = 1,
					gap = 1,
					treesitter = false,
					columns = {
						{ "kind_icon", gap = 1 },
						{ "label", "label_description", gap = 1 },
						{ "kind", gap = 1 },
					},
					components = {
						kind_icon = {
							ellipsis = false,
							text = function(ctx)
								-- local kind = ctx.kind
								-- local kind_icon, _, _ = require("mini.icons").get("lsp", kind)
								-- return kind_icon

								return ctx.kind_icon
							end,
							highlight = function(ctx)
								return (
									require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
									or "BlinkCmpKind"
								) .. ctx.kind
								-- local _, hl, _ = require('mini.icons').get('lsp', ctx.kind)
								-- return hl
							end,
						},
						kind = {
							ellipsis = false,
							width = { fill = true },
							text = function(ctx)
								return "<" .. ctx.kind .. ">"
							end,
							highlight = function(ctx)
								return (
									require("blink.cmp.completion.windows.render.tailwind").get_hl(ctx)
									or "BlinkCmpKind"
								) .. ctx.kind
							end,
						},
						label = {
							ellipsis = true,
							width = { fill = true, max = 50 },
							text = function(ctx)
								return ctx.label .. ctx.label_detail
							end,
							highlight = function(ctx)
								local highlights = {
									{
										0,
										#ctx.label,
										group = ctx.deprecated and "BlinkCmpLabelDeprecated" or "BlinkCmpLabel",
									},
								}
								if ctx.label_detail then
									table.insert(
										highlights,
										{ #ctx.label, #ctx.label + #ctx.label_detail, group = "BlinkCmpLabelDetail" }
									)
								end
								for _, idx in ipairs(ctx.label_matched_indices) do
									table.insert(highlights, { idx, idx + 1, group = "BlinkCmpLabelMatch" })
								end
								return highlights
							end,
						},
						label_description = {
							ellipsis = true,
							width = { max = 30 },
							text = function(ctx)
								return ctx.label_description
							end,
							highlight = "BlinkCmpLabelDescription",
						},
					},
				},
				order = {
					n = "bottom_up",
					s = "top_down",
				},
			},
			documentation = {
				auto_show = true,
				auto_show_delay_ms = 400,
				treesitter_highlighting = true,
				update_delay_ms = 100,
				window = {
					min_width = 20,
					max_width = 75,
					max_height = 15,
					border = "single",
					winblend = 0,
					winhighlight = "Normal:BlinkCmpDoc,FloatBorder:BlinkCmpDocBorder,CursorLine:BlinkCmpDocCursorLine,Search:None",
					scrollbar = false,
					direction_priority = {
						menu_north = { "e", "w", "n", "s" },
						menu_south = { "e", "w", "s", "n" },
					},
					desired_min_height = 5,
					desired_min_width = 20,
				},
			},
			ghost_text = {
				enabled = true,
			},
		},
		signature = {
			enabled = false,
			trigger = {
				blocked_retrigger_characters = {},
				blocked_trigger_characters = {},
				show_on_insert_on_trigger_character = true,
			},
			window = {
				min_width = 5,
				max_width = 100,
				max_height = 10,
				border = "single",
				winblend = 0,
				winhighlight = "Normal:BlinkCmpSignatureHelp,FloatBorder:BlinkCmpSignatureHelpBorder",
				scrollbar = false,
				direction_priority = { "n", "s" },
				treesitter_highlighting = true,
			},
		},
		fuzzy = {
			use_typo_resistance = false,
			use_frecency = true,
			use_proximity = true,
			-- max_items = 100,
			sorts = { "score", "label", "kind" },
			prebuilt_binaries = {
				download = false,
			},
		},
		sources = {
			cmdline = function()
				local type = vim.fn.getcmdtype()
				if type == "/" or type == "?" then
					return { "buffer" }
				elseif type == ":" then
					return { "cmdline", "path" }
				end
				return {}
			end,
			default = function()
				local node_type = vim.treesitter.get_node():type()
				local providers_by_filetype = {
					["lua"] = {
						"lsp",
						"path",
						"luasnip",
						"snippets",
						"lazydev",
					},
					["text"] = {
						"path",
						"buffer",
					},
					["default"] = {
						"lsp",
						"path",
						"snippets",
						"luasnip",
					},
				}
				if vim.tbl_contains({ "comment", "line_comment", "block_comment", "comment_content" }, node_type) then
					return providers_by_filetype["text"]
				end
				return providers_by_filetype[vim.bo.filetype] or providers_by_filetype["default"]
			end,
			per_filetype = {},
			providers = {
				lsp = {
					name = "Lsp",
					module = "blink.cmp.sources.lsp",
					enabled = true,
					score_offset = 0,
					fallbacks = { "buffer" },
				},
				path = {
					name = "path",
					module = "blink.cmp.sources.path",
					enabled = true,
					score_offset = 3,
					opts = {
						trailing_slash = false,
						label_trailing_slash = true,
						get_cwd = function(ctx)
							return vim.fn.expand(("#%d:p:h").format(ctx.bufnr))
						end,
						show_show_hidden_files_by_default = true,
					},
					should_show_items = true,
				},
				snippets = {
					name = "Snip",
					module = "blink.cmp.sources.snippets",
					enabled = true,
					score_offset = -3,
					opts = {
						friendly_snippets = true,
						search_paths = { vim.fn.stdpath("config") .. "/snippets" },
					},
				},
				buffer = {
					name = "buffer",
					module = "blink.cmp.sources.buffer",
					score_offset = 5,
				},
				lazydev = {
					name = "lazydev",
					module = "lazydev.integrations.blink",
					fallbacks = { "lsp" },
				},
			},
		},
		appearance = {
			highlight_ns = vim.api.nvim_create_namespace("blink_cmp"),
			use_nvim_cmp_as_default = false,
			nerd_font_variant = "mono",
			kind_icons = {
				Array = "󰅪",
				Boolean = "",
				Class = "",
				Color = "",
				Constant = "",
				Constructor = "",
				Enum = "",
				EnumMember = "",
				Event = "",
				Field = "",
				File = "",
				Folder = "",
				Function = "󰡱",
				Interface = "",
				Key = "",
				Keyword = "",
				Method = "",
				Module = "",
				Namespace = "",
				Null = "󰟢",
				Number = "",
				Object = "",
				Operator = "",
				Package = "",
				Property = "󰯠",
				Reference = "",
				Snippet = "󰩫",
				String = "",
				Struct = "",
				Text = "󰦪",
				TypeParameter = "",
				Unit = "",
				Value = "",
				Variable = "󰫧",
			},
		},
	})
end

return Plugin

neovim version

NVIM v0.11.0-dev-1344+g17383870dd Build type: Release LuaJIT 2.1.1732813678 system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/share/nvim" Run :checkhealth for more info

blink.cmp version: branch, tag, or commit

latest git

@the-fuckin-nobody the-fuckin-nobody added the bug Something isn't working label Dec 13, 2024
@Saghen
Copy link
Owner

Saghen commented Dec 13, 2024

Does the issue still occur if you disable prefetch_on_insert? That's mostly a proof of concept, I'll add a warning

@the-fuckin-nobody
Copy link
Author

Does the issue still occur if you disable prefetch_on_insert? That's mostly a proof of concept, I'll add a warning

Yes it indeed occurs even after disabling prefetch_on_insert.

recording.mp4

@ribru17
Copy link

ribru17 commented Dec 13, 2024

@the-fuckin-nobody maybe you solution is similar to mine, my problem was similar at least: #540 (comment)

@the-fuckin-nobody
Copy link
Author

the-fuckin-nobody commented Dec 13, 2024

@the-fuckin-nobody maybe you solution is similar to mine, my problem was similar at least: #540 (comment)

Thanks @ribru17 , cant believe lua_ls was the reason behind that. Closing this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants