Skip to content

Instantly share code, notes, and snippets.

@jdrouhard
Last active October 19, 2021 01:37
Show Gist options
  • Save jdrouhard/d5524ed2153bfb36ffa2cc492e4d5267 to your computer and use it in GitHub Desktop.
Save jdrouhard/d5524ed2153bfb36ffa2cc492e4d5267 to your computer and use it in GitHub Desktop.
local cmd = vim.cmd
local api = vim.api
local M = {}
function M.autocmd(group, cmds, clear)
clear = clear == nil and true or clear
if type(cmds) == 'string' then cmds = {cmds} end
cmd('augroup ' .. group)
if clear then cmd [[au!]] end
for _, c in ipairs(cmds) do cmd('autocmd ' .. c) end
cmd [[augroup END]]
end
function M.lsp_cancel_pending_requests(bufnr)
vim.schedule(function()
bufnr = (bufnr == nil or bufnr == 0) and vim.api.nvim_get_current_buf() or bufnr
for _, client in ipairs(vim.lsp.buf_get_clients(bufnr)) do
for id, request in pairs(client.requests or {}) do
if request.type == 'pending' and request.bufnr == bufnr then
client.cancel_request(id)
end
end
end
end)
end
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment