-
Notifications
You must be signed in to change notification settings - Fork 162
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
Memory Usage Issue With Certain Completions #1039
Comments
I'm not familiar with Zig so a repro.lua and example file (or project, if the Zig LSP requires it), would be quite helpful |
I managed to get a The main culprit seems to be The specific issue is caused by selecting or attempting to scroll "through" the I am not having this issue with nvim-cmp, so I assumed it was related specific to blink.cmp Here is a minimal const std = @import("std");
fn main() !void {
const f = try std.fs.cwd().openFile("input.txt", .{});
// typing `f.l`, waiting for docs to show, then scrolling down to `close()`
} along with the -- Run with `nvim -u repro.lua`
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
---@diagnostic disable-next-line: missing-fields
require("lazy.minit").repro({
spec = {
{
"saghen/blink.cmp",
build = "cargo build --release",
event = { "InsertEnter", "CmdlineEnter" },
opts = {
completion = {
documentation = {
auto_show = true,
},
},
},
},
{
"neovim/nvim-lspconfig",
opts = {
servers = {
zls = {},
},
},
config = function(_, opts)
local lspconfig = require("lspconfig")
for server, config in pairs(opts.servers) do
-- passing config.capabilities to blink.cmp merges with the capabilities in your
-- `opts[server].capabilities, if you've defined it
config.capabilities = require("blink.cmp").get_lsp_capabilities()
lspconfig[server].setup(config)
end
end,
},
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "zig" } },
config = function(_, opts) require("nvim-treesitter.configs").setup(opts) end,
},
},
}) |
I experience the same issue:
minimal.lua: vim.api.nvim_create_autocmd("FileType", {
pattern = "zig",
callback = function()
vim.lsp.start({
name = "zls",
cmd = { "zls" },
root_dir = nil,
settings = vim.empty_dict(),
})
end,
})
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").setup({
spec = {
{
"saghen/blink.cmp",
version = "*",
opts = {},
},
},
})
bug.zig: const std = @import("std");
const File = std.fs.File;
File. Now going to the last line, typing "cl" should freeze up the editor. Edit: Also reproduces with zig I am thus fairly confident that a ZLS change is not at fault |
Digging further still, I got this stack trace from lldb, stopping while the memory leak/ freeze was happening:
This seems to indicate some problem with treesitter, but if it's in treesitter or in blink's interaction with treesitter I don't know |
Does the issue occur without treesitter enabled for drawing? I believe LazyVim enables it by default. |
Edit: I was looking in the wrong place |
Thanks, like you said, it seems likely this is an issue with treesitter's zig parser rather than with blink.cmp, but it's possible we're using the API incorrectly. It may make sense to open an issue in the treesitter repo if you're able to find a reproduction |
I'll have a look, thank you :) |
Correction, I was wrong. I had downgraded my entire configuration about a month, and there it worked. Applying this fix does not fix the issue |
I think I have found a workaround: Setting: both to false, seems to resolve my issue, at the cost of course of nice colored docs. Maybe this gives you an indication as to what's going on @Saghen ? |
I have found that this line, called from here is to blame. If I were to hazard a guess, it's a problem with the zig treesitter parser as you mentioned as well, since it seems somewhat out of date. That still doesn't explain the explosion of memory and maxing a core for 30 seconds, but that's an investigation for not 1 AM. As a workaround for anyone experiencing the same, I have this fork which applies this patch, disabling tree-stitter highlighting when a diff --git a/lua/blink/cmp/lib/window/docs.lua b/lua/blink/cmp/lib/window/docs.lua
index f250701..8f75571 100644
--- a/lua/blink/cmp/lib/window/docs.lua
+++ b/lua/blink/cmp/lib/window/docs.lua
@@ -50,6 +50,12 @@ function docs.render_detail_and_documentation(opts)
vim.api.nvim_buf_clear_namespace(opts.bufnr, highlight_ns, 0, -1)
if #detail_lines > 0 and opts.use_treesitter_highlighting then
+ if vim.bo.filetype == 'zig' then
+ local lines = vim.api.nvim_buf_get_lines(opts.bufnr, 0, #detail_lines, false)
+
+ if lines[1] and string.find(lines[1], 'File') then return end
+ end
+
docs.highlight_with_treesitter(opts.bufnr, vim.bo.filetype, 0, #detail_lines)
end
@@ -83,8 +89,12 @@ function docs.highlight_with_treesitter(bufnr, filetype, start_line, end_line)
local success, trees = pcall(vim.treesitter.get_parser, bufnr, root_lang)
if not success or not trees then return end
+ -- The freeze happened after this line
+
trees:parse({ start_line, end_line })
+ -- The freeze happened before this
+
trees:for_each_tree(function(tree, tstree)
local lang = tstree:lang()
local highlighter_query = vim.treesitter.query.get(lang, 'highlights') I won't make a PR of this, as the workaround is quite ridiculous and not even near the root cause. I'll see if I can get a repro in treesitter somewhere this week or next week |
Make sure you have done the following
blink.cmp
<C-k>
on https://cmp.saghen.dev)Bug Description
I am encountering this issue specifically with Zig's LSP (zls), and I am unsure if it happens in other instances.
I will be coding as usual, but then some completions (specifically related to the
std.fs.File.*
completions (such asopen()
orclose()
) will sometimes cause my neovim to freeze, RAM will go up by ~6GiB, and then after ~30 seconds, neovim will resume.Sometimes, the memory drops back down to usual, and remains good for a while until I restart neovim. Other times, blink will continue to use all that ram, and it will be unusably slow and laggy until a restart, after which this problem sometimes happens, and sometimes doesn't; it's very unpredictable.
I am not sure what causes this, but it's definitely getting in the way enough to make it unusable for long coding sessions, atleast in Zig.
Relevant configuration
neovim
versionv0.11.0-dev-1574+gac3859a441
blink.cmp
version2144c58
The text was updated successfully, but these errors were encountered: