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

bug: Signature help autocommands not getting created? #342

Closed
3 tasks done
matthewsia98 opened this issue Jan 31, 2023 · 5 comments · Fixed by #351 or #639
Closed
3 tasks done

bug: Signature help autocommands not getting created? #342

matthewsia98 opened this issue Jan 31, 2023 · 5 comments · Fixed by #351 or #639
Labels
bug Something isn't working

Comments

@matthewsia98
Copy link

matthewsia98 commented Jan 31, 2023

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
@matthewsia98 matthewsia98 added the bug Something isn't working label Jan 31, 2023
@matthewsia98
Copy link
Author

matthewsia98 commented Feb 1, 2023

Did more digging today.
Why is the LspAttach event only fired for copilot here?
Could it be that noice hasn't been required when the other 2 attached?
LspInfo shows that all 3 clients are attached.

image

@max397574
Copy link
Contributor

it would really help if you'd provide a minimal config

@matthewsia98
Copy link
Author

Updated the original post with minimal config and more information.
I can't reliably reproduce the issue.
Sometimes it will work 20 times in a row before it fails once.

@max397574
Copy link
Contributor

I guess there is a running condition between VeryLazy and BufRead
you should fix the order of how you load the plugin I guess

@folke folke closed this as completed in f69f1a5 Feb 7, 2023
@folke
Copy link
Owner

folke commented Feb 7, 2023

Should be fixed now. When noice loads, it will now also attach to existing buffers / lsp clients as expected

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.

3 participants