Skip to content

bug: Statusline symbols from previous buffer shown on buffer with buftype = 'nofile' #602

@cameronr

Description

@cameronr

Did you check docs and existing issues?

  • I have read all the trouble.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of trouble.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.10.2 Build type: Release LuaJIT 2.1.1727870382

Operating system/version

MacOS 15.0.1

Describe the bug

Statusline symbols from a previous buffer are shown on the current buffer if the buftype of the current buffer is 'nofile'. First noticed when using Neogit but also happens with :checkhealth:

Screenshot 2024-11-16 at 13 42 09
Screenshot 2024-11-16 at 13 42 15

In the above example, :=require('trouble.view.main'):get() returns:

{
  buf = 1,
  cursor = { 15, 0 },
  filename = "/Users/cam/.local/share/nvim-cam/lazy/trouble.nvim/lua/trouble/config/init.lua
",
  win = 1000
}

:=require('trouble.view.main')._main:

{
  buf = 1,
  cursor = { 15, 0 },
  filename = "/Users/cam/.local/share/nvim-cam/lazy/trouble.nvim/lua/trouble/config/init.lua
",
  win = 1005
}

:=require('trouble.view.main')._buf:

nil

It seems like it's happening because buffers with buftype ~= "" are being ignored. Commenting out this buftype ~= "" check fixes it:

if vim.bo[buf].buftype ~= "" then
return false
end

But I don't know if that's the "right" way to fix it.

EDIT: Finally got around to looking at this more closely. I think the right fix is to only look for windows up to the current tabpage rather than all windows. PR #652

Steps To Reproduce

  1. nvim -u repro.lua lua/trouble/config/init.lua
  2. Wait for lua_ls to index project
  3. place the cursor on a line that displays symbols on the statusline (e.g. lua/trouble/config/init.lua:15)
  4. run :checkhealth

Note: I was getting some weirdness where mason wouldn't correctly install lua_ls with repro.lua. If you get an error about lua_ls, just :MasonInstall lua-language-server to fix it.

Expected Behavior

No statusline symbols are displayed for the health window

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    -- minimal mason/lsp setup
    {
      "neovim/nvim-lspconfig",
      dependencies = {
        "williamboman/mason.nvim",
        "williamboman/mason-lspconfig.nvim",
        -- just for ls status
        { "j-hui/fidget.nvim", opts = {} },
      },
      config = function()
        require("mason").setup()

          require("mason-lspconfig").setup({
            ensure_installed = { "lua_ls" },
            handlers = {
              function(server_name)
                require("lspconfig")[server_name].setup({})
              end,
            },
          })
      end,
    },
    { "folke/trouble.nvim", opts = {} },
    {
      "nvim-lualine/lualine.nvim",
      opts = function()
        local trouble = require("trouble")
        local symbols = trouble.statusline({
          mode = "lsp_document_symbols",
          groups = {},
          title = false,
          filter = { range = true },
          format = "{kind_icon}{symbol.name:Normal}",
          -- The following line is needed to fix the background color
          -- Set it to the lualine section you want to use
          hl_group = "lualine_c_normal",
        })
        return {
          sections = {
            lualine_c = {
              { "filename" },
              {
                symbols.get,
                cond = symbols.has,
              },
            },
          },
        }
      end,
    },
  },
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions