Zeioth/garbage-day.nvim

Add ignorance for file type like `NvimTree` and etc.

niksingh710 opened this issue · 15 comments

I am using this plugin and it is great. (recommended by a friend)
I use aggressive_mode = true as grace_period=3 does not work in 3 secs for me atleast.

but if i use aggressive_mode = true then i won't get diagnostics in NvimTree like plugins.
an opts to ignore certain file types would be a nice addition.
e.g

ignore_ft = {
	"NvimTree",
}

This option was removed in v1.0.6 in favor of the option excluded_lsp_clients, which is the same but provides you more control.

Aditionally, please ensure you have a plugin like noice.nvim to see what lsp clients you are executing.

If you stop having diagnostics, it means a LSP server you need has been stopped, which it should never happen for the buffer you have focused.

return {
  -- TODO: if fork merged fix the url
  "Zeioth/garbage-day.nvim",
  -- dir = "~/repos/garbage-day.nvim/",
  dependencies = "neovim/nvim-lspconfig",
  event = "VeryLazy",
  opts = {
    aggressive_mode = true,
    notifications = true,
    -- grace_period = 3,
    excluded_lsp_clients = {
      "NvimTree",
    },
  },
}

Here is my config
and what i expect is that if i open NvimTree window (either in floating mode or any how)`
it should not stop any of lsp that is running.

Ok I understand you case of use now:

Because aggresive mode stop LSP when you change to a different filetype, it is stopping lsp when you change to NvimTree.

You want to avoid this because garbage collection would trigger excessively.

Ok I understand you case of use now:

Because aggresive mode stop LSP when you change to a different filetype, it is stopping lsp when you change to NvimTree.

You want to avoid this because garbage collection would trigger excessively.

Yep exactly.

So you will be considering the pr?
Or will be extending the functionality of excluded_lsp_clients?

@niksingh710 I tested it last night.

The PR works fine when you keep the sidebar open. But if you close/open it, garbage collection triggers and I'm trying to figure out why.

@niksingh710 I tested it last night.

The PR works fine when you keep the sidebar open. But if you close/open it, garbage collection triggers and I'm trying to figure out why.

aah this seems to be an issue.
just faced as you mentioned.
ig it is happening because I have only implemented the check if the new_filetype is in the ignore_ft table.

so what happens is

when going from lua file to NvimTree (Opening Nvim Tree)
currbuf_ft(lua) -> switched_to(NvimTree)
current_filetype -> new_filetype (garbage collection ignored as new_filetype in ignore_ft)

when going from NvimTree to lua file (Closing Nvim Tree)
currbuf_ft(NvimTree) -> switched_to(Lua)
current_filetype -> new_filetype (garbage collection activated as new_filetype is not in ignore_ft)

Now have to resolve this issue.
Not getting a clean solution at the top of my head.

The latest commit in my pr should resolve this issue.
also have to use event="BufEnter" in lazy instead of event="VeryLazy"
as lazy loading garbage-day was causing the issue once, then everything was as expected

Ok I got a quick dirty fix:

-- ignore some filetypes
if vim.tbl_contains(config.excluded_filetypes, vim.bo.filetype) then
  return
end
if current_filetype == "" then return end -- this is the fix.

That seems to do the trick, I'm gonna refine a bit more and see if I can communicate the new feature effectively.

yeah, this seems to be a cleaner solution to exist.
will be waiting for the update to be pushed.

@niksingh710 I'm starting to find all kind of unfixable border cases for this feature:

For example, if we implement it like:

-- ignore some filetypes
if vim.tbl_contains(config.excluded_filetypes, vim.bo.filetype) then
  was_prev_ignored = true
  -- BUG: If you close the ignored buffer in this point it will trigger gc.
  return
end
if was_prev_ignored then
  was_prev_ignored = false
  return
end

So I think we are leaving it out.

Why

Aggressive_mode was never designed to be the main mode. It was included because it can be used successfully in most languages. That's not the case for neodev, where loading LSP is very slow and it would trigger constant reloads.

Alternatives

I advice disabling aggressive_mode in your scenario. If you need, you can use the API we expose to stop lsp clients more often that garbage-day.nvim does by default.

Example

vim.api.nvim_create_autocmd("BufEnter", {
  callback = function()

    if my_condition then
      require("garbage-day.utils").stop_lsp()  -- stop all lsp clients.
      require("garbage-day.utils").start_lsp() -- start lsp clients for the current buffer.
    end  

  end,
})

It's also cool to fork it and modify it.

I undertand the feature is convenient, but the priority is that anything we ship is 100% reliable.

I am fine with a fork.
But in my testing

        if vim.tbl_contains(config.excluded_filetypes, vim.bo.filetype) or vim.tbl_contains(config.excluded_filetypes, new_filetype) then
          return
        end

This Snippet is working as expected for me
have added in my fork. (if this seems to be an acceptable solution, then tell will merge.)

@niksingh710 I found the solution to all issues in the previous solution without the need to add a new option, using a single line.

if vim.bo.buftype == "nofile" or vim.bo.buftype == "" then return end

I guess I was tired the other day. Preparing new version.

@niksingh710 I found the solution to all issues in the previous solution without the need to add a new option, using a single line.

if vim.bo.buftype == "nofile" or vim.bo.buftype == "" then return end

I guess I was tired the other day. Preparing new version.

vim.bo.buftype for lua type file is also returning ""
didn't got the time to test but will test it.