folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.11k stars 173 forks source link

bug: Trouble throws an error when attaching to a buffer with some LSPs #480

Closed artursmirnov closed 4 weeks ago

artursmirnov commented 4 weeks ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0

Operating system/version

macOS 14.3

Describe the bug

When opening a file of a certain filetype (handlebars), Trouble throws an error:

...share/nvim/lazy/trouble.nvim/lua/trouble/sources/lsp.lua:420: table index is nil

stack traceback:
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:34: in function 'transition'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:48: in function 'reject'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:81: in function 'cb'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:31: in function 'transition'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:45: in function 'resolve'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:78: in function 'cb'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:31: in function 'transition'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:45: in function 'resolve'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:164: in function <...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:160>
    [C]: in function 'pcall'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:73: in function 'cb'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:31: in function 'transition'
    ...cal/share/nvim/lazy/trouble.nvim/lua/trouble/promise.lua:45: in function 'resolve'
    ...share/nvim/lazy/trouble.nvim/lua/trouble/sources/lsp.lua:141: in function 'handler'
    .../neovim/0.10.0/share/nvim/runtime/lua/vim/lsp/client.lua:685: in function ''
    vim/_editor.lua: in function <vim/_editor.lua:0>

Excerpt from the :LspInfo:

 Detected filetype:   handlebars

 3 client(s) attached to this buffer: 

 Client: tailwindcss (id: 2, bufnr: [5, 6])
    filetypes:       aspnetcorerazor, astro, astro-markdown, blade, clojure, django-html, htmldjango, edge, eelixir, elixir, ejs, erb, eruby, gohtml, gohtmltmpl, haml, handlebars, hbs, html, html-eex, heex, jade, leaf, liquid, mdx, mustache, njk, nunjucks, php, razor, slim, twig, css, less, postcss, sass, scss, stylus, sugarss, javascript, javascriptreact, reason, rescript, typescript, typescriptreact, vue, svelte, templ
    autostart:       true
    cmd:             /Users/artur/.local/share/nvim/mason/bin/tailwindcss-language-server --stdio

 Client: ember (id: 3, bufnr: [5, 6])
    filetypes:       handlebars, typescript, javascript, typescript.glimmer, javascript.glimmer
    autostart:       true
    cmd:             /Users/artur/.local/share/nvim/mason/bin/ember-language-server --stdio

 Client: glint (id: 4, bufnr: [5, 6])
    filetypes:       html.handlebars, handlebars, typescript, typescript.glimmer, javascript, javascript.glimmer
    autostart:       true
    cmd:             /Users/artur/.local/share/nvim/mason/bin/glint-language-server

 2 active client(s) not attached to this buffer: 

 Client: vtsls (id: 1, bufnr: [6])
    filetypes:       javascript, javascriptreact, javascript.jsx, typescript, typescriptreact, typescript.tsx
    autostart:       true
    cmd:             /Users/artur/.local/share/nvim/mason/bin/vtsls --stdio

 Client: eslint (id: 5, bufnr: [6])
    filetypes:       javascript, javascriptreact, javascript.jsx, typescript, typescriptreact, typescript.tsx, vue, svelte, astro
    autostart:       true
    cmd:             /Users/artur/.local/share/nvim/mason/bin/vscode-eslint-language-server --stdio

 Configured servers list: pylsp, html, vtsls, denols, pyright, volar, vuels, eslint, jsonls, yamlls, tailwindcss, ruff_lsp, emmet_language_server, ember, docker_compose_language_service, glint, dockerls, solargraph, clangd, marksman, ruff, lua_ls, cssls

LSP features work properly.

Steps To Reproduce

No particular steps, just opening a .hbs file.

Expected Behavior

No error should occur.

Repro

No response

folke commented 4 weeks ago

I can't reproduce this using glint and a simple file I created. Can you provide a test file?

The error can only happen when an invalid location is sent from the LSP server.

artursmirnov commented 4 weeks ago

@folke thank you for a swift response.

The error does not occur on a simple file. You need a simple Ember.js app. I think there should be an actual component invocation.

I was able to reproduce the issue in a clean setup with the following steps:

  1. Install clean LazyVim:
git clone https://github.com/LazyVim/starter ~/.config/nvim-test
  1. Launch it to install deps:
NVIM_APPNAME=nvim-test nvim
  1. Add the following configuration to plugins (I simply edited plugins/example.lua to return the following table):
 return {
   {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        -- lua stuff
        "lua-language-server",
        "stylua",

        -- web dev stuff
        "css-lsp",
        "tailwindcss-language-server",
        "html-lsp",
        "json-lsp",
        "typescript-language-server",
        "ember-language-server",
        "vetur-vls",
        "glint",
        "yaml-language-server",
        "python-lsp-server",
        "deno",
        "eslint_d",
        "prettier",
      },
    },
  },

  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = {
        "vim",
        "lua",
        "html",
        "css",
        "scss",
        "javascript",
        "typescript",
        "json",
        "jsonc",
        "python",
        "ruby",
        "vue",
        "tsx",
        "c",
        "markdown",
        "markdown_inline",
        "bash",
        "dockerfile",
        "yaml",
        "toml",
        "glimmer",
      },
    },
  },
}
  1. Install Ember CLI globally:
npm install -g ember-cli
  1. Create a new Ember app in any folder:
cd ~/test-app-folder
ember new test-app
  1. Launch neovim in the app folder:
cd ~/test-app-folder/test-app
NVIM_APPNAME=nvim-test nvim
  1. Open the app/templates/application.hbs file.

The error should be displayed.

artursmirnov commented 4 weeks ago

FWIW, it's been working properly in neovim 0.9.5. After upgrade to neovim 0.10.0 and updating Trouble from a8264a65a0b894832ea642844f5b7c30112c458f to the latest version, it started to error.

folke commented 4 weeks ago

Fixed. Worth mentioning is that :Telescope lsp_document_symbols also fails for this doc

artursmirnov commented 4 weeks ago

The fix is working perfectly, thank you so much @folke!