GithubHelp home page GithubHelp logo

hinell / lsp-timeout.nvim Goto Github PK

View Code? Open in Web Editor NEW
189.0 4.0 6.0 1.94 MB

Start/stop LSP servers upon demand; keeps RAM usage low

License: Other

Makefile 23.00% Lua 77.00%
lsp neovim-plugin nvim-plugin

lsp-timeout.nvim's Introduction

lsp-timeout.nvim

lsp-timeout-demo.mov

PayPal License

Nvim plugin for nvim-lspconfig: stop idle servers & restart upon focus; keep your RAM usage low

Overview

Some LSP servers are terribly inefficient at memory management and can easily take up gigabytes of RAM MBs if left unattended (just like VS Code huh?!). This plugin prevents excessive memory usage by stopping and restarting LSP servers automatically upon gaining or loosing window focus, keeping neovim fast.

⚡Features

  • Stop & start LSP servers upon demand
  • Lower RAM usage by unsed Neovim system window

🔒Requirements

📦 Installation

require("lazy").setup(
    {
	"hinell/lsp-timeout.nvim",
	dependencies={ "neovim/nvim-lspconfig" }
    }
)
-- $HOME/.config/nvim/lua/user/init.lua
packer.setup(function(use)
    use({
        "hinell/lsp-timeout.nvim",
        requires={ "neovim/nvim-lspconfig" }
    })
end)
Plug "hinell/lsp-timeout.nvim"

SUPPORT DISCLAIMER

NO GUARANTEES UNTIL PAID. This project is supported and provided AS IS. See also LICENSE.


September 26, 2023
Copyright © - Alexander Davronov (a.k.a Hinell), et.al.

lsp-timeout.nvim's People

Contributors

hinell 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

lsp-timeout.nvim's Issues

Option to exclude certain languages

Summary

New option exclude = { 'markdown', ... }.

So the plugin doesn't trigger for said language.

Why

There are many scenarios where this is necessary. I'm gonna describe two.

scenario 1

Imagine you are editing a markdown file.

You don't have a markdown lsp server, but you have prettierd as formatter.

When lsp-timeout run :LspStop, this is gonna also stop prettierd.

But it won't be possible to restore it with a LspAttach autocmd like next, because there is not lsp server at all.

      vim.api.nvim_create_autocmd({ "LspAttach" }, {
        desc = "Ensure null-ls start its sources a lsp client starts",
        callback = function()
           pcall(function() require("null-ls").enable({}) end)
        end,
      })

scenario 2

Some LSP servers might just miss behave, and it would be a good idea to be able to ignore the language entirely.

  • For example, java jdtls restores correctly, but it will send error notifications for a while.
    screenshot_2023-10-29_01-11-44_136919706

New bug report

Summary

On neovim 0.94 I am getting an error message that comes up any time my neovim window loses focus:

Error detected while processing FocusLost Autocommands for "*":
Error executing lua callback: .../share/nvim/lazy/lsp-timeout.nvim/plugin/lsp-timeout.lua:83: attempt to call field 'get_clients' (a nil value)
stack traceback:
.../share/nvim/lazy/lsp-timeout.nvim/plugin/lsp-timeout.lua:83: in function <.../share/nvim/lazy/lsp-timeout.nvim/plugin/lsp-timeout.lua:72>

I'm loading lsp-timeout with lazy and this error comes up as soon as I switch away from my terminal.

Steps to reproduce

Launch neovim in terminal, open a file (or don't), then switch to another app.

Versions

Neovim 0.94

Does not work with `zbirenbaum/copilot.lua`

I've read TROUBLESHOOTING instructions

  • Yes

Summary

This plugin works fantastically well with every LSP server, but it seems to mess with Copilot when timing out all servers. When restarting, Copilot does not work again and querying its status simply outputs "Offline". Attempting to manually re-trigger Copilot (e.g., Copilot! attach) also outputs "Offline" and does not restart Copilot. I need to quit nvim and launch it again for Copilot to work. Any idea why this happens? Is there any way to also restart Copilot?

Steps to reproduce

Use this plugin along with zbirenbaum/copilot.lua, wait for this plugin to timeout the servers and then attempt to use Copilot again.

zbirenbaum/copilot.lua config:

require("copilot").setup({
  panel = {
    enabled = true,
    auto_refresh = true,
    keymap = {
      jump_prev = "[[",
      jump_next = "]]",
      accept = "<CR>",
      refresh = "R",
      open = "<M-c>",
    },
    layout = {
      position = "right",
      ratio = 0.3,
    },
  },
  suggestion = {
    enabled = true,
    auto_trigger = true,
    keymap = {
      accept = "<M-l>",
      next = "<M-]>",
      prev = "<M-[>",
      dismiss = "<M-h>",
    },
  },
  filetypes = {
    yaml = true,
    markdown = true,
    help = false,
    gitcommit = true,
    gitrebase = true,
    hgcommit = true,
    svn = true,
    cvs = true,
    ["."] = false,
  },
  server_opts_overrides = {
    autostart = true,
  },
})

This plugin's config is the default one.

Versions

nvim v0.10, latest versions of zbirenbaum/copilot.lua and this plugin.

Specify operating system/environment

MacOS

Lots of LSP not restarting.

Summary

Lots of LSP not restarting.

Before timeout :
Capture d’écran 2023-10-19 à 16 13 21

After timeout :
Capture d’écran 2023-10-19 à 16 24 35

lsp-timeout config :

  vim.g["lsp-timeout-config"] = {
    stopTimeout = 1000 * 60 * 5, -- ms, timeout before stopping all LSP servers
    startTimeout = 1000 * 10,  -- ms, timeout before restart
    silent = false,            -- true to suppress notifications
  }

Package manager : LazyNvim
Actually using lsp-zero if it can help

Steps to reproduce

.

Versions

NVIM v0.10.0-dev-1379+ga8fc94a2f-dirty Build type: RelWithDebInfo LuaJIT 2.1.1696795921

Not worked

I've read TROUBLESHOOTING instructions

  • Yes

Summary

Hello, I install lsp-timeout and config it by lazy.nvim, but it seems not worked.

Steps to reproduce

I using below config

        {
            "hinell/lsp-timeout.nvim",
            init = function()
                vim.g["lsp-timeout-config"] = {
                    stopTimeout = 1000,        -- Stop unused lsp servers after 1s (for testing).
                    startTimeout = 2000,             -- Force server restart if nvim can't in 2s.
                    silent = true,                   -- Notifications disabled
                    filetypes = {                    -- Exclude servers that miss behave on LSP stop/start.
                        ignore = { 'markdown', 'java' }
                    },
                }
            end,
            config = function ()
            end,
            dependencies = { "neovim/nvim-lspconfig" },
        },

When I run the LspInfo command, the lsp is always active.

I have focused on Nvim-tree, but lua_ls is still actived.
image

Versions

NVIM v0.10.0-dev-2000+g6fa0f303d
Build type: RelWithDebInfo
LuaJIT 2.1.1703358377

Specify operating system/environment

macos

1.2.0 Error when neovim loses focus

I've read TROUBLESHOOTING instructions

  • Yes

Summary

There seem to be a bug when the current neovim screen loses focus.
screenshot_2023-10-29_20-35-20_742103937

Config

  {
    "hinell/lsp-timeout.nvim",
    dependencies={ "neovim/nvim-lspconfig" },
    event = "User BaseFile",
    init = function()
      vim.g["lsp-timeout-config"] = {
        stopTimeout = 1000,        -- Stop unused lsp servers after 1s (for testing).
        startTimeout = 2000,             -- Force server restart if nvim can't in 2s.
        silent = true,                   -- Notifications disabled
        filetypes = {                    -- Exclude servers that miss behave on LSP stop/start.
          ignore = { 'markdown', 'java' }
        },
      }
    end
  },

More info

I've tested with a few languages with the same result.

Steps to reproduce

  1. Use my config
  2. Open any file that has an active lsp client.
  3. move the mouse outside of neovim.

(it seems to be unrelated with the new option filetypes.)

Versions

NVIM v0.10.0-dev-1418+g15983cf2c6
Build type: RelWithDebInfo
LuaJIT 2.1.1697887905
Run "nvim -V1 -v" for more info

Specify operating system/environment

Archlinux

LSPs not restarting / null-ls

Summary

Since last update, I can't get my LSPs to restart on refocus, only inside .tsx files.

Actually, I have to manually use LspStart to restart the timedout servers.
Please see (.tsx file) :

Enregistrement.de.l.ecran.2023-10-26.a.15.18.01.mov

See the difference (.lua file) :

Enregistrement.de.l.ecran.2023-10-26.a.15.24.11.mov

EDIT : It seems that if lsp-timeout stop the servers and we don't use LspStop command to check if it's working, on refocus the LSPs are not restarted too.

Steps to reproduce

Stop LSP servers inside .tsx file (or typescript project ?) , switch focus and then refocus the nvim window.

Versions

NVIM v0.10.0-dev-1418+g15983cf2c-dirty
Build type: RelWithDebInfo
LuaJIT 2.1.1697887905

Add ability to disable neovim on startup

idea is using tmux, i want to restore many neovim sessions without triggering lsp.

could add option to disable lsp at startup until the user-has-come-back trigger triggers

tsserver not restarting after switching from `jose-elias-alvarez/typescript.nvim` to `pmizio/typescript-tools.nvim`

Summary

EDIT : After some investigations tsserver is restarted, but the LSP typescript-tools is not.
EDIT 2 It seems that lua_ls doesn't restart too. Can it be related to the fact that it is handled by lsp-zero ? Or by the latest update of lsp-timeout?

Before switching from jose-elias-alvarez/typescript.nvim to pmizio/typescript-tools.nvim tsserver was restarting without any problems. Now it wont restart.

If it can help, here's typescript-tools config :

local M = {}

M.config = function()
  local lsp_zero = require("lsp-zero")
  lsp_zero.extend_lspconfig()
  require("typescript-tools").setup({
    settings = {
      tsserver_file_preferences = {
        includeInlayParameterNameHints = "all",
        includeCompletionsForModuleExports = true,
        includeInlayParameterNameHintsWhenArgumentMatchesName = true,
        includeInlayFunctionParameterTypeHints = true,
        includeInlayVariableTypeHints = true,
        includeInlayVariableTypeHintsWhenTypeMatchesName = true,
        includeInlayPropertyDeclarationTypeHints = true,
        includeInlayFunctionLikeReturnTypeHints = true,
        includeInlayEnumMemberValueHints = true,
      },
      tsserver_format_options = {
        allowIncompleteCompletions = false,
        allowRenameOfImportPath = true,
      },
      separate_diagnostic_server = true,
      publish_diagnostic_on = "insert_leave",
      expose_as_code_action = {},
      tsserver_max_memory = "auto",
      tsserver_locale = "fr",
      complete_function_calls = true,
      include_completions_with_insert_text = true,
      code_lens = "all",
      disable_member_code_lens = true,
    },
  })
end

return M

Steps to reproduce

I don't have any steps to reproduce the issue, all I can give you is my neovim configuration if you want to try.
You can find it here : ls-devs/nvim

Versions

NVIM v0.10.0-dev-1413+g684e93054-dirty
Build type: RelWithDebInfo
LuaJIT 2.1.1697887905

attempt to call field 'get_clients' (a nil value)

Summary

Error  15:39:31 msg_show.lua_error Error detected while processing FocusLost Autocommands for "*":
15:39:31 msg_show Error executing lua callback: .../share/nvim/lazy/lsp-timeout.nvim/plugin/lsp-timeout.lua:82: attempt to call field 'get_clients' (a nil value)
stack traceback:
	.../share/nvim/lazy/lsp-timeout.nvim/plugin/lsp-timeout.lua:82: in function <.../share/nvim/lazy/lsp-timeout.nvim/plugin/lsp-timeout.lua:72>

Steps to reproduce

No response

Setup

    {
	"hinell/lsp-timeout.nvim",
	dependencies={ "neovim/nvim-lspconfig" }
    }

[FEAT] Ignore filetypes

Add option to ignore filetypes

It would be great if this plugin could ignore some filetypes like NeoTree Telescope etc..
Actually if u loose focus on a window such like NeoTree Telescope , the plugin try to restart some LSP cause its found 0 servers (even if u just ALT-TAB quickly).
But it needs to restart LSPs if they stopped even if focus is regained on an ignored filetype.

null-ls sources don't reload after restoring lsp clients

Summary

This is my :NullLsInfo when I open my file (it's loading beautysh).

screenshot_2023-10-16_05-22-47_969674073

And this is the same lsp-timeout reload the clients (it doesn't load it anymore)
screenshot_2023-10-16_05-22-28_698973754

Just to clarify, null-ls itself works fine (for example, on C, it will work correctly after restoring lsp-timeout because it don't require sources).

If you could try to reproduce, I would be thankful.

Steps to reproduce

When restoring, you should be able to reproduce.

Versions

  • "lsp-timeout.nvim", version = "1.0.1"
  • "nvimtools/none-ls.nvim", commit = "f39f627bbdfb33cc4ae4a95b4708e7dba7b9aafc"
  • "jay-babu/mason-null-ls.nvim", version = "^2"

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.