Skip to content

bug: Signature help autocommands not getting created? #342

@matthewsia98

Description

@matthewsia98

Did you check docs and existing issues?

  • I have read all the noice.nvim docs
  • I have searched the existing issues of noice.nvim
  • I have searched the exsiting issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.0-dev-825+g843c9025a

Operating system/version

6.1.8-arch1-1

Describe the bug

Signature help autotrigger not working because autocommands not getting created.

I created my own LspAttach autocmd and you can see that the event is getting fired.
But somehow this does not run?

Image below shows config.options.lsp.signature.auto_open.trigger = true but the InsertEnter autocommand is never created.

image

I think the problem has to do with lazy loading.

From my testing,
When loading noice with event = "VeryLazy", sometimes it works sometimes it doesn't.
If loading noice with lazy = false, it always works.

I suspect that depending on startup times, there could be a scenario where the LspAttach event fires and noice has not been loaded yet?
My other lsp stuff are being loaded with event = "BufReadPre"

Steps To Reproduce

  1. Save file as minimal.lua
  2. Open file with nvim -u minimal.lua minimal.lua
  3. Go to first blank line (line 7)
  4. type print(
  5. if signature autotriggers quit :q!
  6. repeat 2-4 until it fails

Expected Behavior

Autocommands to be created for signature help when plugin is lazy loaded.

Repro

-- DO NOT change the paths and don't remove the colorscheme
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", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

-- options
vim.opt.termguicolors = true
vim.opt.completeopt = ""
vim.opt.wildmenu = false

-- install plugins
local plugins = {
    "nvim-lua/plenary.nvim",
    "folke/tokyonight.nvim",
    {
        "nvim-treesitter/nvim-treesitter",
        build = ":TSUpdate",
        dependencies = {
            "p00f/nvim-ts-rainbow",
        },
        event = "BufReadPost",
        config = function()
            require("nvim-treesitter.configs").setup({
                rainbow = { enable = true },
            })
        end,
    },
    {
        "hrsh7th/nvim-cmp",
        dependencies = {
            "hrsh7th/cmp-nvim-lsp",
        },
        event = { "InsertEnter", "CmdlineEnter" },
        config = function()
            local cmp = require("cmp")
            cmp.setup({
                completion = {
                    completeopt = "menu,menuone,noselect",
                },
                sources = {
                    { name = "nvim_lsp" },
                },
                mapping = {
                    ["<C-p>"] = cmp.mapping.select_prev_item(),
                    ["<C-n>"] = cmp.mapping.select_next_item(),
                },
            })
        end,
    },
    {
        "neovim/nvim-lspconfig",
        dependencies = {
            "williamboman/mason.nvim",
            "williamboman/mason-lspconfig.nvim",
        },
        event = "BufReadPre",
        config = function()
            require("mason").setup()

            -- install mason packages
            local show_ui = true
            local packages = {
                "lua-language-server",
            }
            for _, package_name in ipairs(packages) do
                local package = require("mason-registry").get_package(package_name)
                if not package:is_installed() then
                    if show_ui then
                        vim.cmd("Mason")
                        show_ui = false
                    end
                    package:install()
                end
            end

            require("mason-lspconfig").setup()

            require("lspconfig").sumneko_lua.setup({
                on_attach = function(client, bufnr)
                    -- Disable semantic highlighting by server
                    -- sumneko lua highlights comments when toggling
                    local servers_disable_semantic_highlighting = { "sumneko_lua" }
                    if vim.tbl_contains(servers_disable_semantic_highlighting, client.name) then
                        client.server_capabilities.semanticTokensProvider = nil
                    end

                    vim.keymap.set("i", "<C-s>", function()
                        vim.lsp.buf.signature_help()
                    end, { buffer = bufnr })
                end,
                capabilities = require("cmp_nvim_lsp").default_capabilities(),
                handlers = {},
                flags = { allow_incremental_sync = true, debounce_text_changes = 150 },
                settings = {
                    Lua = {
                        runtime = {
                            version = "LuaJIT",
                        },
                        diagnostics = {
                            enable = true,
                            globals = {},
                            workspaceDelay = -1,
                        },
                        format = {
                            enable = false,
                        },
                        workspace = {
                            useGitIgnore = true,
                            checkThirdParty = false,
                        },
                        telemetry = {
                            enable = false,
                        },
                    },
                },
            })
        end,
    },
    {
        "folke/noice.nvim",
        dependencies = {
            "MunifTanjim/nui.nvim",
            {
                "rcarriga/nvim-notify",
                lazy = false,
                config = function()
                    local notify = require("notify")
                    notify.setup({
                        timeout = 3000,
                    })
                    vim.notify = notify
                end,
            },
        },
        event = "VeryLazy",
        config = function()
            require("noice").setup({
                notify = { enabled = true },
                cmdline = { enabled = true },
                messages = { enabled = true },
                lsp = {
                    progress = {
                        enabled = true,
                        -- view = "mini",
                    },
                    documentation = {
                        opts = {
                            border = { style = "rounded" },
                            position = { row = 2 },
                        },
                    },
                    signature = { enabled = true },
                    hover = { enabled = true },
                    override = {
                        ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
                        ["vim.lsp.util.stylize_markdown"] = true,
                        ["cmp.entry.get_documentation"] = true,
                    },
                },
            })
        end,
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
    defaults = { lazy = true },
    ui = { border = "rounded" },
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions