folke / noice.nvim

💥 Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
Apache License 2.0
4.29k stars 100 forks source link

Conflicts between noice.nvim and NvChad #575

Closed jnpngshiii closed 1 year ago

jnpngshiii commented 1 year ago

Q

If you use NvChad and add the following code to lua/custom/plugins.lua to use noice.nvim:

{
  "folke/noice.nvim",
  event = "VeryLazy",
  opts = {
    -- add any options here
  },
  dependencies = {
    -- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
    "MunifTanjim/nui.nvim",
    -- OPTIONAL:
    --   `nvim-notify` is only needed, if you want to use the notification view.
    --   If not available, we use `mini` as the fallback
    "rcarriga/nvim-notify",
    }
}

Then run checkhealth and you may get the following:

noice: require("noice.health").check()

noice.nvim ~
- OK **Neovim** >= 0.8.0
- OK You're using a GUI that should work ok
- OK **vim.go.lazyredraw** is not enabled
- OK **nvim-notify** is installed
- OK **TreeSitter vim** parser is installed
- OK **TreeSitter regex** parser is installed
- OK **TreeSitter lua** parser is installed
- OK **TreeSitter bash** parser is installed
- OK **TreeSitter markdown** parser is installed
- OK **TreeSitter markdown_inline** parser is installed
- OK `vim.notify` is set to **Noice**
- ERROR `vim.lsp.handlers["textDocument/hover"]` has been overwritten by another plugin?

  Either disable the other plugin or set `config.lsp.hover.enabled = false` in your **Noice** config.
  - plugin: nvim
  - file: /opt/homebrew/Cellar/neovim/0.9.1/share/nvim/runtime/lua/vim/lsp.lua
  - line: 2319
- ERROR `vim.lsp.handlers["textDocument/signatureHelp"]` has been overwritten by another plugin?

  Either disable the other plugin or set `config.lsp.signature.enabled = false` in your **Noice** config.
  - plugin: nvim
  - file: /opt/homebrew/Cellar/neovim/0.9.1/share/nvim/runtime/lua/vim/lsp.lua
  - line: 2319
- OK `vim.lsp.handlers["window/showMessage"]` is set to **Noice**
- WARNING `vim.lsp.util.convert_input_to_markdown_lines` is not configured to be handled by **Noice**
- WARNING `vim.lsp.util.stylize_markdown` is not configured to be handled by **Noice**

A

After many days of googling, I found the solution.

First, add the following configuration in lua/custom/plugins.lua:

  {
    "folke/noice.nvim",
    dependencies = {
      -- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
      "MunifTanjim/nui.nvim",
      -- OPTIONAL:
      --   `nvim-notify` is only needed, if you want to use the notification view.
      --   If not available, we use `mini` as the fallback
      "rcarriga/nvim-notify",
    },
    opts = {
      -- add any options here
      -- lsp = {
      --   signature = {
      --     enable = false,
      --   },
      -- },
    },
    event = "VeryLazy",
    config = function()
      require("noice").setup {
        lsp = {
          -- override markdown rendering so that **cmp** and other plugins use **Treesitter**
          override = {
            -- override the default lsp markdown formatter with Noice
            ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
            -- override the lsp markdown formatter with Noice
            ["vim.lsp.util.stylize_markdown"] = true,
            -- override cmp documentation with Noice (needs the other options to work)
            ["cmp.entry.get_documentation"] = true,
          },
          hover = { enabled = false }, -- <-- HERE!
          signature = { enabled = false }, -- <-- HERE!
        },
        -- you can enable a preset for easier configuration
        presets = {
          bottom_search = false, -- use a classic bottom cmdline for search
          command_palette = false, -- position the cmdline and popupmenu together
          long_message_to_split = true, -- long messages will be sent to a split
          inc_rename = false, -- enables an input dialog for inc-rename.nvim
          lsp_doc_border = true, -- add a border to hover docs and signature help
        },
      }
      -- See: https://github.com/folke/noice.nvim/issues/258
      require("noice.lsp").hover()
      -- See: https://github.com/NvChad/NvChad/issues/1656
      -- vim.notify = require("noice").notify
      -- vim.lsp.handlers["textDocument/hover"] = require("noice").hover
      -- vim.lsp.handlers["textDocument/signatureHelp"] = require("noice").signature
    end,
  },

Then, add the following configuration in lua/plugins/configs/lspconfig.lua, before require("lspconfig").lua_ls.setup:

require("noice").setup {
  lsp = {
    -- override markdown rendering so that **cmp** and other plugins use **Treesitter**
    override = {
      -- override the default lsp markdown formatter with Noice
      ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
      -- override the lsp markdown formatter with Noice
      ["vim.lsp.util.stylize_markdown"] = true,
      -- override cmp documentation with Noice (needs the other options to work)
      ["cmp.entry.get_documentation"] = true,
    },
    hover = { enabled = true }, -- <-- HERE!
    signature = { enabled = true }, -- <-- HERE!
  },
}

That's it, and you'll get a healthy neovim!

Other issues

  1. You may notice that it seems that some values are defined more than once and are defined as different values. For example: hover = { enabled = false/true }. Well, I actually don't know why this is necessary, but if you don't do it you'll get an error! I'm new to neovim & lua and don't know much about the various details. I would be very happy if someone could tell me the reason "why this strange approach avoids errors".
  2. Changing lua/plugins/configs/lspconfig.lua means that every time you update NvChad you need to manually merge some diffs.

Just to help those who may still be struggling with their sub-healthy neovim. Now I'm going to close this issue~

max397574 commented 1 year ago

the error message here is quite clear either you disable the handlers in noice (which you don't want afaict) or they are overwritten by another plugin like lsp-signature or lsp-saga or sth so the right way to fix this would be to just figure out which plugin overwrites the handlers and disable it non of this weird stuff with the double and different setup you do should be necessary

GeorgeAndreiBals commented 1 year ago

@jinpeng-s you can just do:

                -- override markdown rendering so that **cmp** and other plugins use **Treesitter**
                override = {
                    ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
                    ["vim.lsp.util.stylize_markdown"] = true,
                    ["cmp.entry.get_documentation"] = true,
                },
                signature = {
                    enabled = false,
                },
                hover = {
                    enabled = false,
                },
            },

Alternatively, if you don't want to disable these from noice as @max397574 pointed out, you can try to mess around with these functions in .config/nvim/lua/core/mappings.lua:

 ["K"] = {
      function()
        vim.lsp.buf.hover()
      end,
      "LSP hover",
    },

    ["<leader>ls"] = {
      function()
        vim.lsp.buf.signature_help()
      end,
      "LSP signature help",
    },