simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 158 forks source link

rust-tools crashing with expected string, got table in inlay hints code #300

Closed ishanjain28 closed 1 year ago

ishanjain28 commented 1 year ago

Hey, This is crashing constantly at this line, https://github.com/simrat39/rust-tools.nvim/blob/99fd1238c6068d0637df30b6cee9a264334015e9/lua/rust-tools/inlay_hints.lua#L216

with the error, "Expected string, Got Table`.

It tries to read the string in o_hint.label but this field not a string anymore for some reason? It now looks like, o_hint.label.value.

I am using latest rust nightly, latest rust analyzer and neovim-nightly-bin 0.9.0+dev+546+g98daaa798-1.

I tried this patch. It's not crashing any more but I don't really know which hints this code is responsible for and if it's still working :thinking: I'll take a deeper look tomorrow, for now this makes it usable :shrug:

  -- show other hints with commas and a thicc arrow
  if not vim.tbl_isempty(other_hints) then
    virt_text = virt_text .. opts.other_hints_prefix
    for i, o_hint in ipairs(other_hints) do
      if o_hint.label.value == nil then
              goto skip_to_next
      end

      if string.sub(o_hint.label.value, 1, 2) == ": " then
        virt_text = virt_text .. o_hint.label:sub(3)
      else
        virt_text = virt_text .. o_hint.label
      end
      if i ~= #other_hints then
        virt_text = virt_text .. ", "
      end
      ::skip_to_next::
    end
  end
KokaKiwi commented 1 year ago

It seems this was introduced by https://github.com/rust-lang/rust-analyzer/pull/13699 I fixed this by setting rust-analyzer.inlayHints.locationLinks to false

owittek commented 1 year ago

It seems this was introduced by rust-lang/rust-analyzer#13699 I fixed this by setting rust-analyzer.inlayHints.locationLinks to false

This doesn't seem to work for me unfortunately, maybe I've set the setting in a wrong way.

figsoda commented 1 year ago

@owittek make sure you are setting it like this

rust_tools.setup({
  server = {
    settings = {
      ["rust-analyzer"] = {
        inlayHints = { locationLinks = false },
      },
    },
  },
})
owittek commented 1 year ago
server = {
    settings = {
      ["rust-analyzer"] = {
        inlayHints = { locationLinks = false },
      },
    },
  },

unfortunately still broken for me, I'm using AstroNvim so I integrated it like that and tried some other things too:

        ["simrat39/rust-tools.nvim"] = {
                after = "mason-lspconfig.nvim",
                config = function()
                        require("rust-tools").setup {
                                server = astronvim.lsp.server_settings "rust_analyzer" {
                                        settings = {
                                                ["rust-analyzer"] = {
                                                        inlayHints = { locationLinks = false },
                                                },
                                        },
                                },
                        }
                end
        },

PS: sorry about the formatting, I have no clue why my LSP formats it like that lmao

figsoda commented 1 year ago

I am not familiar with astronvim, but looking at the docs, I don't think that's how server_settings are supposed to be used

you might need to configure lsp["server-settings"].rust_analyzer in the astronvim config instead and do something like this

rust_tools.setup({
  server = {
    settings = astronvim.lsp.server_settings("rust_analyzer"),
  },
})
owittek commented 1 year ago

I am not familiar with astronvim, but looking at the docs, I don't think that's how server_settings are supposed to be used

you might need to configure lsp["server-settings"].rust_analyzer in the astronvim config instead and do something like this

rust_tools.setup({
  server = {
    settings = astronvim.lsp.server_settings("rust_analyzer"),
  },
})

oh yeah by that I'm assuming that I'm assuming that I can put

return {
  inlayHints = { locationLinks = false },
}

in server-settings/rust-analyzer.lua but it doesn't work.

wizard-28 commented 1 year ago

@owittek I use AstroNvim too, here's how I fixed it.

My user/plugins/init.lua:

  ["simrat39/rust-tools.nvim"] = {
    after = { "mason-lspconfig.nvim" },
    ft = { "rust" },
    config = function() require("rust-tools").setup(require "user.plugins.rust-tools") end,
  },

My user/plugins/rust-tools.lua:


return {
  server = astronvim.lsp.server_settings "rust_analyzer",
}

My user/lsp/server-settings/rust_analyzer.lua:


return {
  settings = {
    ["rust-analyzer"] = {
      -- HACK: https://github.com/simrat39/rust-tools.nvim/issues/300
      inlayHints = { locationLinks = false },
    },
  },
}
owittek commented 1 year ago

@wizard-28 Thanks, it worked! I'm too inexperienced in lua so I formatted my server-settings in a wrong way :D

alealv commented 1 year ago

@owittek make sure you are setting it like this

rust_tools.setup({
  server = {
    settings = {
      ["rust-analyzer"] = {
        inlayHints = { locationLinks = false },
      },
    },
  },
})

Thanks!

TornaxO7 commented 1 year ago

Hey, This is crashing constantly at this line,

https://github.com/simrat39/rust-tools.nvim/blob/99fd1238c6068d0637df30b6cee9a264334015e9/lua/rust-tools/inlay_hints.lua#L216

with the error, "Expected string, Got Table`.

It tries to read the string in o_hint.label but this field not a string anymore for some reason? It now looks like, o_hint.label.value.

I am using latest rust nightly, latest rust analyzer and neovim-nightly-bin 0.9.0+dev+546+g98daaa798-1.

I tried this patch. It's not crashing any more but I don't really know which hints this code is responsible for and if it's still working thinking I'll take a deeper look tomorrow, for now this makes it usable shrug

  -- show other hints with commas and a thicc arrow
  if not vim.tbl_isempty(other_hints) then
    virt_text = virt_text .. opts.other_hints_prefix
    for i, o_hint in ipairs(other_hints) do
      if o_hint.label.value == nil then
              goto skip_to_next
      end

      if string.sub(o_hint.label.value, 1, 2) == ": " then
        virt_text = virt_text .. o_hint.label:sub(3)
      else
        virt_text = virt_text .. o_hint.label
      end
      if i ~= #other_hints then
        virt_text = virt_text .. ", "
      end
      ::skip_to_next::
    end
  end

Would it be worth it to use your patch for a PR?

owittek commented 1 year ago

@TornaxO7 There's an open PR from 2 weeks ago: https://github.com/simrat39/rust-tools.nvim/pull/296#issue-1499492250

TornaxO7 commented 1 year ago

but it seems to fix something else, if I'm seeing that correctly and the PR doesn't fix my issue here :(

owittek commented 1 year ago

Oh I checked the changes but since I don't know the source code I assumed by the title that it references the same issue and that the author of the PR simply found the cause on a lower layer.

@SDGLBL could you please tell us if this is related?

burnthoney commented 1 year ago

i seem to be having the same issue. and as a result im unable to use it.

My config (im using lsp-zero)

--  LSP Rust Settings
local lsp_rust = lsp.build_options('rust_analyzer', {
    settings = {
        ["rust_analyzer"] = {
            checkOnSave = {command = "clippy"},
            inlayHints = {locationLinks = false}
        }
    }
})

require("rust-tools").setup({server = lsp_rust})

image

SDGLBL commented 1 year ago

Oh I checked the changes but since I don't know the source code I assumed by the title that it references the same issue and that the author of the PR simply found the cause on a lower layer.

@SDGLBL could you please tell us if this is related? It seems that my pull request has nothing to do with this issue. And I found that rust-tools.nvim no longer needed my pull request after updating the latest rust-analyzer. So I'll turn it off later.

figsoda commented 1 year ago

@reji-zero might be a typo ["rust_analyzer"] -> ["rust-analyzer"]

kdarkhan commented 1 year ago

Should be fixed by this PR https://github.com/simrat39/rust-tools.nvim/pull/307

simrat39 commented 1 year ago

Should be fixed in https://github.com/simrat39/rust-tools.nvim/commit/a47f5d61ce06a433998fb5711f723773e3156f46