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

Error in inlay hints when enabled not in current window #27645

Open
echasnovski opened this issue Feb 27, 2024 · 2 comments
Open

Error in inlay hints when enabled not in current window #27645

echasnovski opened this issue Feb 27, 2024 · 2 comments
Labels
bug issues reporting wrong behavior lsp

Comments

@echasnovski
Copy link
Member

Problem

When inlay hints are enabled in case target buffer is not in current window, there is the following error:

Error in decoration provider vim_lsp_inlayhint.win:
Error executing lua: ...CVKwkT/usr/share/nvim/runtime/lua/vim/lsp/inlay_hint.lua:320: assertion failed!
stack traceback:
        [C]: in function 'assert'
        ...CVKwkT/usr/share/nvim/runtime/lua/vim/lsp/inlay_hint.lua:320: in function <...CVKwkT/usr/share/nvim/runtime/lua/vim/lsp/inlay_hint.lua:311>

Steps to reproduce

  • Create a small rust project. For example:
    • File 'Cargo.toml' with the following content:
      [package]
      name = "inlay-hint-repro"
      version = "0.1.0"
    • File 'hello-world.rs' with the following content:
      fn main() {
          println!("Hello, world!");
      }
  • Make sure rust-analyzer is installed.
  • Create a 'init.lua' with the following setup:
    vim.api.nvim_create_autocmd('FileType', {
      pattern = 'rust',
      callback = function()
        vim.lsp.start({
          name = 'rust-analyzer',
          cmd = 'rust-analyzer', -- Use custom path to 'rust-analyzer' executable
          root_dir = '.',
        })
      end,
    })
    
    vim.api.nvim_create_autocmd('LspAttach', {
      callback = function(args)
        -- Wait for LSP server to start (just to be sure)
        vim.defer_fn(function() vim.lsp.inlay_hint.enable(args.bufnr, true) end, 1000)
      end,
    })
  • Execute nvim --clean -u <path/to/init.lua> from the root of sample rust project.
  • :split
  • :call win_execute(1000, 'edit hello-world.rs') and wait for one second.

Expected behavior

Inlay hints can be automatically started even if target buffer is not current (is not in current window).

Neovim version (nvim -v)

NVIM v0.10.0-dev-2457+ga4b444252

Vim (not Nvim) behaves the same?

No (doesn't have this functionality)

Operating system/version

EndeavourOS Linux x86_64 (6.7.6-arch1-1)

Terminal name/version

st-0.9

$TERM environment variable

st-256color

Installation

appimage

@clason
Copy link
Member

clason commented Feb 27, 2024

Tangent: There is the same error -- from the decoration provider! -- if you do vim.lsp.inlay_hint.enable() in a buffer without an LSP server. This case should be gracefully handled much earlier with a warning (similar to hover()) instead.

@BigfootN

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior lsp
Projects
None yet
Development

No branches or pull requests

3 participants