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

Memory leak+freezing with lsp intelephense or phpactor #286

Closed
Catvert opened this issue Dec 28, 2022 · 6 comments · Fixed by #278 or #639
Closed

Memory leak+freezing with lsp intelephense or phpactor #286

Catvert opened this issue Dec 28, 2022 · 6 comments · Fixed by #278 or #639
Labels
bug Something isn't working

Comments

@Catvert
Copy link

Catvert commented Dec 28, 2022

Describe the bug
Hello, when I use your plugin with the lsp intelephense or phpactor, noice trigger a memory leak in some specific situations.

For example, the memory leak (quickly consumes all my ram, in about 10 seconds + nvim freeze) is triggered with lsp.signature.enabled = true or doc hover with the following settings :

override = { 
 ["vim.lsp.util.convert_input_to_markdown_lines"] = true, 
 ["vim.lsp.util.stylize_markdown"] = true, 
 ["cmp.entry.get_documentation"] = true, 
},  

This seems to be relative to your plugin for all things that affects the lsp.
If you need more information, don't hesitate to ask me. Thanks to you!

Which version of Neovim are you using?
nvim stable + nightly(28/12/22)

To Reproduce
Steps to reproduce the behavior:

  1. Installing noice.nvim + lsp intelephense/phpactor
  2. Insert mode inside a function or doc hover
  3. Memory leak is triggered :(

Screenshots
Example, entering the insert mode inside a function (resulting in a crash) :
image

Noice Log
impossible to get because nvim crashes directly.

@Catvert Catvert added the bug Something isn't working label Dec 28, 2022
@folke
Copy link
Owner

folke commented Dec 28, 2022

Please provide a minimal init lua. See the wiki

@Catvert
Copy link
Author

Catvert commented Dec 28, 2022

Ok, seems to be relative with the combo noice + tree-sitter + lsp intelephense/phpactor.
Please note that I don't have this problem when noice.nvim is disabled. For example, with ray-x/lsp_signature.nvim, I have no crashes.

Here is the minimal init lua :

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",

    {
        "folke/noice.nvim",
        dependencies = {
            "MunifTanjim/nui.nvim",
            "rcarriga/nvim-notify",
        }, config = function()
            require('noice').setup({
                lsp = {
                    signature = { enabled = true }
                },
            });
        end
    },

    { 'neovim/nvim-lspconfig', config = function()
        require('lspconfig').intelephense.setup {}
    end },

    { -- Highlight, edit, and navigate code
        'nvim-treesitter/nvim-treesitter',
        build = function()
            pcall(require('nvim-treesitter.install').update { with_sync = true })
        end, config = function()
            require('nvim-treesitter.configs').setup {
                ensure_installed = { 'php' },
            }
        end
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.opt.termguicolors = true
vim.cmd([[colorscheme tokyonight]])
require("noice").setup()

@folke
Copy link
Owner

folke commented Dec 30, 2022

I'm not able to reproduce this. I also had to change some of your repro code.

Can you give me an example php file that shows this behavior and that can be reproduced with the code below?

updated init.lua
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for , name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG
%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
"folke/tokyonight.nvim",

{
"folke/noice.nvim",
dir = "~/projects/noice.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
"rcarriga/nvim-notify",
},
config = function()
require("noice").setup({
lsp = {
signature = { enabled = true },
override = {
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
["vim.lsp.util.stylize_markdown"] = true,
["cmp.entry.get_documentation"] = true,
},
},
})
end,
},

{
"neovim/nvim-lspconfig",
config = function()
require("lspconfig").intelephense.setup({})
end,
dependencies = {
{ "williamboman/mason.nvim", config = true },
{ "williamboman/mason-lspconfig.nvim", config = true },
},
},

{ -- Highlight, edit, and navigate code
"nvim-treesitter/nvim-treesitter",
build = function()
pcall(require("nvim-treesitter.install").update({ with_sync = true }))
end,
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = { "php" },
})
end,
},
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.keymap.set("n", "K", vim.lsp.buf.hover)

vim.opt.termguicolors = true
vim.cmd([[colorscheme tokyonight]])
require("noice").setup()

@Catvert
Copy link
Author

Catvert commented Dec 31, 2022

Ok, after investigation, I didn't cleanup my .repro between my attempts. Your init.lua doesn't crash for me. I noticed that the treesitter-parser 'html' has to be installed too (no idea why) to cause the crash. Here is an updated version of your init.lua :

local root = vim.fn.fnamemodify("./.repro", ":p")

for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local lazypath = root .. "/plugins/lazy.nvim"

if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end

vim.opt.runtimepath:prepend(lazypath)

local plugins = {
    "folke/tokyonight.nvim",
    {
        "folke/noice.nvim",
        -- dir = "~/projects/noice.nvim",
        dependencies = {
            "MunifTanjim/nui.nvim",
            "rcarriga/nvim-notify",
        },

        config = function()
            require("noice").setup({
                lsp = {
                    signature = { enabled = true },
                    override = {
                        ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
                        ["vim.lsp.util.stylize_markdown"] = true,
                        ["cmp.entry.get_documentation"] = true,
                    },
                },
            })
        end,
    },
    {
        "neovim/nvim-lspconfig",
        config = function()
            require("lspconfig").intelephense.setup({})
        end,
        dependencies = {
            { "williamboman/mason.nvim", config = true },
            { "williamboman/mason-lspconfig.nvim", config = true },
        },
    },
    {
        "nvim-treesitter/nvim-treesitter",
        build = function()
            pcall(require("nvim-treesitter.install").update({ with_sync = true }))
        end,
        config = function()
            require("nvim-treesitter.configs").setup({
                ensure_installed = { "php", "html" },
            })
        end,
    },
}

require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.keymap.set("n", "K", vim.lsp.buf.hover)

vim.opt.termguicolors = true
vim.cmd([[colorscheme tokyonight]])
require("noice").setup()

Note that the vim.lsp.buf.hover does not crash with this configuration. It is only the lsp-signature that crashes.

Here is a simple php example project that trigger the crash : https://github.com/Catvert/noice-crash-php

@folke
Copy link
Owner

folke commented Dec 31, 2022

Thanks. I can reproduce it now!

@folke
Copy link
Owner

folke commented Dec 31, 2022

This is triggered somewhere inside Neovim's treesitter code. I couldn't fix the root cause yet, but I disabled any injections when formatting code with treesitter for Noice.

That at least will fix the issue for now, but some injected languages would not be shown right 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

Successfully merging a pull request may close this issue.

2 participants