function enable_autocomplete(client, buf) if client.supports_method('textDocument/completion') then vim.lsp.completion.enable(true, client.id, buf, {autotrigger = true}) end end function enable_autoformat(client, buf) if client.supports_method('textDocument/formatting') then vim.api.nvim_create_autocmd('BufWritePre', { buffer = buf, callback = function() vim.lsp.buf.format({bufnr = buf, id = client.id}) end, }) end end vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) local buf = args.buf -- enable_autocomplete(client, buf) enable_autoformat(client, buf) end, })