diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-02-10 11:22:07 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-02-10 11:22:07 +0200 |
| commit | 7cee6e5a673defef72c803eca094d1247c31bb9c (patch) | |
| tree | 1dbc97c5ece5f574ef5091d549fb434a8b59a625 /.config/nvim/lua/plugins/scripts/toggleLsp.lua | |
| parent | b91ee8da3ef2c1c154833b4b6e99250fe2c280e7 (diff) | |
| parent | f76f2c4bbc1ddde4b5c0882863060e4c58a11733 (diff) | |
| download | dotfiles-7cee6e5a673defef72c803eca094d1247c31bb9c.tar.gz dotfiles-7cee6e5a673defef72c803eca094d1247c31bb9c.zip | |
Add '.config/nvim/' from commit 'e707f3abc83e0621eab64b4828defd0c80dff5c0'
git-subtree-dir: .config/nvim
git-subtree-mainline: bb29321714929e1b7b962dd47b486325fd77e67a
git-subtree-split: e707f3abc83e0621eab64b4828defd0c80dff5c0
Diffstat (limited to '.config/nvim/lua/plugins/scripts/toggleLsp.lua')
| -rw-r--r-- | .config/nvim/lua/plugins/scripts/toggleLsp.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/scripts/toggleLsp.lua b/.config/nvim/lua/plugins/scripts/toggleLsp.lua new file mode 100644 index 0000000..28af698 --- /dev/null +++ b/.config/nvim/lua/plugins/scripts/toggleLsp.lua @@ -0,0 +1,40 @@ +local M = {} + +local check_function = function(bufnr, _) + local ok, result = pcall(vim.api.nvim_buf_get_var, bufnr, 'lsp_enabled') + -- No buffer local variable set, so just enable by default + if not ok then + return true + end + + return result +end + +vim.lsp.handlers["textDocument/publishDiagnostics"] = + vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + underline = check_function, + virtual_text = check_function, + signs = check_function + }) + +function M.Enable() + vim.b.lsp_enabled = true +end + +function M.Disable() + vim.b.lsp_enabled = false +end + +function M.Toggle() + if vim.b.lsp_enabled == false then + M.Enable() + else + M.Disable() + end +end + +vim.cmd [[ + command! -nargs=* ToggleLsp lua require'lsp.toggle'.Toggle() +]] + +return M |
