ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
1.91k stars 119 forks source link

Inlay hints disappear after saving #416

Open xtrats opened 6 months ago

xtrats commented 6 months ago

Inlay hints are displayed when the file is opened, but they disappear after saving without changing anything. I use init_lazy.lua to make the test.

neovim version: 0.9.5

2024-01-03_20-28-50 (1)

hoarse-boy commented 6 months ago

@xtrats if you really need the go inlay, you can use the inlay from neovim/nvim-lspconfig, and disable go.nvim's inlay.

xtrats commented 6 months ago

@jourdy-mago If I set enable = false of lsp_inlay_hints option in go.nvim, then the go inlay hints doesn't work at all.

Related config is as blow:

ray-x/go.nvim config:

lsp_inlay_hints = {
  enable = false,
}

neovim/nvim-lspconfig config:

opts = {
  inlay_hints = { enabled = true },
  -- ...
}

on_attach function:

if client.server_capabilities.inlayHintProvider then
  vim.lsp.inlay_hint.enable(bufnr, true)
end
hoarse-boy commented 6 months ago

@xtrats my bad, didn’t notice that you have neovim version: 0.9.5. from what i heard neovim/nvim-lspconfig only works on nvim nightly 0.10.

xtrats commented 6 months ago

@jourdy-mago Thanks for the reminder!

9mm commented 5 months ago

interesting.... so this is because i need to use nvim 0.10 nightly?

Thats great to know because i was just about to ask why everything disappears on save

ill go compile nvim 0.10 hopefully lots of new magic opens up

9mm commented 5 months ago

I tried, that was bit of disaster.. will have to table this for now as like 20 other things broke when using neovim 0.10. If anyone ever figures out how to get this to persist on save in meantime id love to hear

9mm commented 5 months ago

Also one other thing, even with neovim 0.10 they still disappeared on save

hoarse-boy commented 2 months ago

@9mm did you use the inlay from neovim/nvim-lspconfig and disable go.nvim's?

you can check my config here. I disabled go.nvim inlay hints and only use inlay from nvim-lspconfig

      require("go").setup({
        lsp_inlay_hints = {
          enable = false,
          style = "inlay",
        },
      })
-- ...
            if client.server_capabilities.inlayHintProvider then
              vim.lsp.inlay_hint.enable(bufnr, true)
            end
-- ...

i have just tested it, the go.nvim inlay is still buggy.

tr0b commented 2 weeks ago

I am also having the same issue, and I'm using nvim release 0.10.x

Attaching video recording.

https://github.com/ray-x/go.nvim/assets/60306480/ca02f716-f95a-4d82-90cc-42901abce7a6

    {
        "ray-x/go.nvim",
        ft = "go",
        config = function()
            require("go").setup({
                lsp_cfg = true,
                goimports = "gopls", -- goimport command, can be gopls[default] or goimport
                lsp_gofumpt = true, -- true: set default gofmt in gopls format to gofumpt
                lsp_document_formatting = false,
                lsp_on_attach = on_attach, -- use on_attach from go.nvim
                diagnostic = {
                    virtual_text = false,
                },
                luasnip = true,
                lsp_inlay_hints = {
                    parameter_hints_prefix = "󰊕",
                },
                diagnostic = diagnostic_config,
            })
            local cfg = require("go.lsp").config() -- config() return the go.nvim gopls setup
            require("lspconfig").gopls.setup(cfg)
            vim.diagnostic.config(diagnostic_config)
        end,
        lazy = true,
    },

my lazy nvim configs for ray-x/go.nvim if that helps

ray-x commented 2 weeks ago

@hoarse-boy If you want to use lsconfig, please disable lsp in go.nvim by setting lsp_cfg=false