Git Product home page Git Product logo

garbage-day.nvim's Introduction

garbage-day.nvim

Garbage collector that stops inactive LSP clients to free RAM

screenshot_2023-11-08_08-12-12_851558101

Why

In many scenarios, unmanaged LSP clients running on background can take several Gb of RAM. So I wrote this LSP garbage collector for NormalNvim to auto free it. But you can use it on any distro.

How to setup

Add this to lazy

{
  "zeioth/garbage-day.nvim",
  dependencies = "neovim/nvim-lspconfig",
  event = "VeryLazy",
  opts = {
    -- your options here
  }
},

We also support changing opts on execution time like :let g:garbage_day_config['option']='value'

Available options

Name Default Description
aggressive_mode false Set it to true to stop all lsp clients except the current buffer, every time you enter a buffer. aggressive_mode ignores grace_period, and it only triggers when entering a buffer with a different filetype than the current buffer. Ensures the maximum RAM save.
excluded_lsp_clients {"null-ls", "jdtls"} LSP clients that should never be stopped. Useful for LSP clients that miss behave.
grace_period 60*15 Seconds to wait before stopping all LSP clients after neovim loses focus.
wakeup_delay 0 Milliseconds to wait before restoring LSP after the mouse re-enters nvim. Useful to avoid waking up the LSP clients by accident when passing the mouse over it.

Debug options

You can tweak them in case some particular LSP client don't start/stop correctly on your machine.

Name Default Description
aggressive_mode_ignore here Buffers to ignore on aggressive_mode.
notifications false Set it to true to get a notification every time LSP garbage collection triggers.
retries 3 Times to try to start a LSP client before giving up.
timeout 1000 Milliseconds that will take for retries to complete. Example: by default we try 3 retries for 1000ms.

IMPORTANT: If you change the default values, make sure the value of grace_period is always bigger than timeout/1000. This ensures you are leaving enough time between stop_lsp()/start_lsp(), so they don't overlap.

FAQ

  • If it doesn't work This plugin has been tested with neovim 0.9 and 0.10. If you are in a neovim version superior to nvim 0.10, and it doesn't work, please open a issue tagging me and I will fix it.
  • Can I manually trigger garbage collection? Yes, you can do it like
require("garbage-day.utils").stop_lsp()  -- stop all lsp clients.
require("garbage-day.utils").start_lsp() -- start lsp clients for the current buffer.

🌟 Support the project

If you want to help me, please star this repository to increase the visibility of the project.

Stargazers over time

Where do that cheesy name come from?

Other alternatives

Roadmap

  • Once nvim 0.10 is oficially released and we drop 0.9 support, we must replace the deprecated function get_active_clients() by get_clients().

garbage-day.nvim's People

Contributors

zeioth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

niksingh710

garbage-day.nvim's Issues

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

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",
}

null-ls is unreliable - solution proposal

We are currently storing the stopped buffers this way

for _, client in pairs(vim.lsp.get_active_clients()) do
  for buf, _ in pairs(client.attached_buffers) do
    stopped_lsp_clients =  ----

Which it works. But I've noticed in order for null-ls to start reliably, the current language LSP server must be running first. This makes the order in which we store the stopped clients important. So I propose the next solution:

for _, buf in ipairs(vim.api.nvim_list_bufs()) do
  for _, client in ipairs(vim.lsp.get_clients()) do
    stopped_lsp_clients =  ----

Even though this code is slightly less intuitive, it should ensure the buffers are stored in the order they were originally started. I'll be testing this solution tomorrow.

Error when leaving neovim in background for grace period

If I leave a file open with neovim in the background for the grace period length then come back to neovim there is an error...

Error executing vim.schedule lua callback: ...are/nvim/lazy/garbage-day.nvim/lua/garbage-day/utils.lua:21: attempt to call field 'get_clients' (a nil value)

Screenshot 2023-11-05 at 8 07 47 PM

This is in a javascript file attached is my :LspInfo

Screenshot 2023-11-05 at 8 33 23 PM

[request] manually tell garbage-day when to start/stop (or pass it user autocmd events to respond to?)

Presently, when in a GitConflicted mode, I like to turn off diagnostics and turn off all attached LSP clients. Some of my lsps do weird things when the buffer has git conflict markers, etc. I use git-conflict.nvim presently to resolve conflicts and in their hooks, i do the manual start/stop of lsps.

Is it possible to either, a.) call manual start/stop functions for garbage-day, or; b.) pass in custom autocmd User events that tell tell garbage-day when to start/stop clients (similar to the existing FocusLost/FocusGained default events)?

Thanks!

Handle `lspconfig.autostart`

  1. Add autostart to lsp:
lspconfig.*.setup {
    autostart = false,
}
  1. Wait grace period
  2. Go to nvim

Expected: all not enabled (before step 2) clients stay not enabled
Actual: Not enabled clients (by autostart=false) started

Still detecting `null-ls`?

I am using LazyVim as my Neovim distro, so I didn't use null-ls at all. I use the configuration below:

return {
    "zeioth/garbage-day.nvim",
    dependencies = "neovim/nvim-lspconfig",
    event = "VeryLazy",
    opts = {
        -- your options here
        notifications = true,
        excluded_lsp_clients = { "jdtls" },
    },
}

but I always get the warning below:

 Warn 11:37:35 notify.warn LazyVim null-ls is no longer included by default in LazyVim.
Please install the lsp.none-ls extra if you still want to use it.

When I disabled the garbarge-day plugin, the warning disappears, so I am wondering maybe this plugin triggers the null-ls checking? However, I checked the source code, I didn't find anything wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.