Skip to content

Latest commit

 

History

History
143 lines (116 loc) · 4.34 KB

index.md

File metadata and controls

143 lines (116 loc) · 4.34 KB

OVERVIEW

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

Default behavior:

  • Tabpages and windows inside - are traversed & checked for LSPs
  • The |'diff'| windows and |'readonly'| buffers are ignored - lsp-timeout takes no action
  • On focused writable windows (cursor put on) lsp-timeout finds and restarts available LSPs

INSTALL

Use your favorite package manager (Packer, Plug, Lazy.nvim etc.); it's advised to uselatest tag

"hinell/lsp-timeout.nvim"

Requirements:

{
    "hinell/lsp-timeout.nvim",
    dependencies={ "neovim/nvim-lspconfig" },
    init = function()
        vim.g.lspTimeoutConfig = {
        -- see config below
        }
    end
}

WARNING Packer.nvim is archived

Packer:

-- $HOME/.config/nvim/lua/user/init.lua
-- Don't forget to run :PackerCompile
packer.setup(function(use)
    use({
      "hinell/lsp-timeout.nvim",
      requires={ "neovim/nvim-lspconfig" },
      setup = function()
        vim.g.lspTimeoutConfig = {
        -- see config belos 
        }
      end
    })
end)

UPDATE

Repo of this plugin may be force-pushed & force-rebased, rendering all previous commits obsolete so manual updates are advised; See DEVELOPMENT.md for more info.

CONFIGURATION

vim.g.lspTimeoutConfig = {
    stopTimeout  = 1000 * 60 * 5, -- ms, timeout before stopping all LSPs 
    startTimeout = 1000 * 10,     -- ms, timeout before restart
    silent       = false          -- true to suppress notifications
    filetypes    = {
        ignore = {                -- filetypes to ignore; empty by default
                                  -- lsp-timeout is disabled completely
        }                         -- for these filetypes
    }
}

-- Buffer local configuration; overrides global
bufnr = vim.api.nvim_get_current_buf() 
vim.b[bufnr].lspTimeoutConfig = {
    -- ..
}
-- Optionally, validate the config
local Config = require("lsp-timeout.config").Config
      Config:new(vim.g.lspTimeoutConfig):validate()

Augroups

Plugin setups two augroups:

  • LSPTimeout - global augroup for various events
  • LSPTimeoutBufferLocal - buffer-local groups, temporary

TROUBLESHOOTING

Note IF SOME PLUGIN FAILED BECAUSE OF STOPPED LSP, PLEASE, FILL AN ISSUE IN A RESPECTIVE PLUGIN REPO

  • Run LspInfo to find (in)active LSPs
  • Use map <...> to check what keymaps are setup/lost upon restart
  • If you hook into |LspAttach| and |LspDetach| events, make sure to store & clean up buffer-local variables or keymaps only once per every cycle

TROUBLESHOOTING PLUGINS

  • Some plugins that require active LSP servers like ones used for signs may fail if they don't hook into |LspAttach| or |LspDetach| events or vim.lsp.get_clients(...) properly
  • Some LSP servers may misbehave upon restart if they don't keep cache
  • Some LSP plugins may hook into serveral LSPs at the same time and fail upon restart
  • See also: https://github.com/neovim/nvim-lspconfig#troubleshooting

Plugins that are known to misbehave:

require("lspconfig")[serverName].setup({
  on_attach = function(client, bufnr)
    -- ...
    if client.server_capabilities["documentSymbolProvider"] then
      require("nvim-navic").attach(client, bufnr)
    end
  end,
  • pmizio/typescript-tools.nvim:
    run lspconfig["typescript-tools"].setup({ filetypes = })
    make sure that filetypes are specified in the setup config
    see: #12 (comment)

September 26, 2023
Copyright © - Alexander Davronov, et.al.