Skip to content

Duplicate code-lenses #259

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

Closed
TheBlueFireFox opened this issue Sep 20, 2023 · 12 comments
Closed

Duplicate code-lenses #259

TheBlueFireFox opened this issue Sep 20, 2023 · 12 comments
Assignees
Labels
bug Something isn't working support Need help setting up the plugin

Comments

@TheBlueFireFox
Copy link

Feature description

  1. Love the plugin, so thanks for writing and maintining it.
  2. Can you add a way to disable the inlay hints? In my setup it clashes with a different plugin (lvimuser/lsp-inlayhints.nvim) and then writes them twice.

Thanks

fyi I am using 2.x.x

image

@TheBlueFireFox TheBlueFireFox added the enhancement New feature or request label Sep 20, 2023
@mrcjkb
Copy link
Owner

mrcjkb commented Sep 20, 2023

Hi 👋

Thanks for the nice words 😄

I think what you're seeing are code lenses, not inlay hints. Afaik, haskell-language-server doesn't support inlay hints yet: haskell/haskell-language-server#2938

I'm not sure why you're seeing them twice, but you can disable codeLens auto-refresh in haskell-tools with

vim.g.haskell_tools = {
  tools = {
    codeLens = {
      autoRefresh = false,
    },
  },
}

@mrcjkb mrcjkb changed the title Deativate Inlay Hints Duplicate code-lenses Sep 20, 2023
@mrcjkb mrcjkb added support Need help setting up the plugin and removed enhancement New feature or request labels Sep 20, 2023
@TheBlueFireFox
Copy link
Author

Hello.
Thank you very much for the fast answer.
This seems to be working for some projects. And in others it completely deactivates the code lenses.

For me it is good enough and as such I am once again want to thank you for your hard work.

@mrcjkb
Copy link
Owner

mrcjkb commented Sep 23, 2023

Hmm, it sounds like it may be conflicting with another plugin. Which plugins do you have installed?

@mrcjkb mrcjkb added the bug Something isn't working label Sep 23, 2023
@mrcjkb mrcjkb self-assigned this Sep 23, 2023
@mrcjkb
Copy link
Owner

mrcjkb commented Sep 23, 2023

Or another question: Do the duplicate code lenses disappear when the inlay hints plugin is disabled?

@TheBlueFireFox
Copy link
Author

Hallo again

@mrcjkb For the first question I have a few plugins installed the one that I think might be the conflicting one is the (lvimuser/lsp-inlayhints.nvim). For the others I'd have to do some detective work (please tell me what I should search for If so required). (here is my config assuming you'd need it.)
About the second yes the duplicate code lenses do disapear when I deactivate the inlay hints plugin.

As always thank you very much for your help. <3

Please tell me if I can help with anything.

@mrcjkb
Copy link
Owner

mrcjkb commented Sep 26, 2023

I tried to reproduce it using a minimal config based on yours (see README.md#troubleshooting), but couldn't.

The minimal config
-- Minimal nvim config with lazy.nvim
-- Assumes a directory in $NVIM_DATA_MINIMAL
-- Start with
--
-- export NVIM_DATA_MINIMAL=$(mktemp -d)
-- export NVIM_APP_NAME="nvim-ht-minimal"
-- nvim -u minimal.lua
--
-- Then exit out of neovim and start again.

-- Ignore default config
local config_path = vim.fn.stdpath('config')
vim.opt.rtp:remove(config_path)

-- Ignore default plugins
local data_path = vim.fn.stdpath('data')
local pack_path = data_path .. '/site'
vim.opt.packpath:remove(pack_path)

-- bootstrap lazy.nvim
data_path = assert(os.getenv('NVIM_DATA_MINIMAL'), '$NVIM_DATA_MINIMAL environment variable not set!')
local lazypath = data_path .. '/lazy/lazy.nvim'
local uv = vim.uv
  ---@diagnostic disable-next-line: deprecated
  or vim.loop
if not uv.fs_stat(lazypath) then
  vim.fn.system {
    'git',
    'clone',
    '--filter=blob:none',
    '[email protected]:folke/lazy.nvim.git',
    '--branch=stable',
    lazypath,
  }
end
vim.opt.rtp:prepend(lazypath)

local lazy = require('lazy')

lazy.setup({
  {
    'mrcjkb/haskell-tools.nvim',
    branch = '2.x.x',
    dependencies = {
      'nvim-lua/plenary.nvim',
      -- Uncomment or add any optional dependencies needed to reproduce the issue
      -- 'nvim-telescope/telescope.nvim',
      -- 'akinsho/toggleterm.nvim',
    },
    ft = { 'haskell', 'lhaskell', 'cabal', 'cabalproject' },
  },
  {
        "lvimuser/lsp-inlayhints.nvim",
        event = { "BufReadPost", "BufNewFile" },
        opts = function()
            vim.api.nvim_set_hl(0, "LspInlayHintCustom", { link = "Comment" })
            vim.api.nvim_create_augroup("LspAttach_inlayhints", {})
            vim.api.nvim_create_autocmd("LspAttach", {
                group = "LspAttach_inlayhints",
                callback = function(args)
                    if not (args.data and args.data.client_id) then
                        return
                    end

                    local bufnr = args.buf
                    local client = vim.lsp.get_client_by_id(args.data.client_id)
                    require("lsp-inlayhints").on_attach(client, bufnr)
                end,
            })

            return {
                inlay_hints = {
                    parameter_hints = {
                        show = true,
                        prefix = "<- ",
                        separator = ", ",
                        remove_colon_start = true,
                        remove_colon_end = true,
                    },
                    type_hints = {
                        -- type and other hints
                        show = true,
                        prefix = "=> ",
                        separator = ", ",
                        remove_colon_start = true,
                        remove_colon_end = false,
                    },
                    -- highlight group
                    highlight = "LspInlayHintCustom",
                },
                debug_mode = true,
            }
        end,
    },
  -- Add any other plugins needed to reproduce the issue.
  -- see https://github.com/folke/lazy.nvim#-lazynvim for details.
}, { root = data_path, state = data_path .. '/lazy-state.json', lockfile = data_path .. '/lazy-lock.json' })

I also noticed you have the following in your config:

vim.g.haskell_tools = {
    hls = {
        tools = {
             inlay_hints = { auto = true },
        },
        capabilities = require("cmp_nvim_lsp").default_capabilities(),
    },
 }

There's no tools.inlay_hints setting, and the haskell-tools plugin will automatically add cmp_nvim_lsp capabilities if it detects the plugin. So you can remove the init function from your config.
I doubt that's what's causing the issue though...

@TheBlueFireFox
Copy link
Author

First sorry for the old config state. (I have already removed it locally, but forgot to update it online...)

Secondly I think we can simple close this issue... I am probably the only one who has this issue given my weird setup and I am fine with your solution above to just deactivate the autoreload for the codeLens.

Either way I once again want to thank you for all your effort in both my issue and also the general plugin.

@mrcjkb
Copy link
Owner

mrcjkb commented Sep 26, 2023

Alright, I'll close this for now 😄

By the way, it looks like inlay hints will be supported natively in neovim 0.10: neovim/neovim#23984

@mrcjkb mrcjkb closed this as completed Sep 26, 2023
@miguelbarao
Copy link

I'm using the lsp-zero plugin and also having this issue.

Had to disable the line capabilities = require("cmp_nvim_lsp").default_capabilities() from the lsp-zero recommended configuration to solve the duplicates in Haskell, but that has consequences to other filetypes, so still investigating how to properly solve it.

@mrcjkb
Copy link
Owner

mrcjkb commented Oct 27, 2024

@miguelbarao that's very strange. cmp_nvim_lsp is a completion plugin that has nothing to do with code lenses.

@miguelbarao
Copy link

@miguelbarao that's very strange. cmp_nvim_lsp is a completion plugin that has nothing to do with code lenses.

Sorry, I jumped to conclusions too fast. It seems to be some race condition, some times it shows duplicates, some times it doesn't, and coincided with commenting that line. I'm lost here.

@mrcjkb
Copy link
Owner

mrcjkb commented Oct 27, 2024

I recommend you follow the troubleshooting guide in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working support Need help setting up the plugin
Projects
None yet
Development

No branches or pull requests

3 participants