jose-elias-alvarez / nvim-lsp-ts-utils

Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
The Unlicense
438 stars 18 forks source link

feat(organize imports): configurable timeout, and return status #111

Closed agriffis closed 2 years ago

agriffis commented 2 years ago

Use the default timeout of 1000 for buf_request_sync(), but allow caller to override.

Return the result or status/err pair so that the caller can handle.

I am now using this in my own formatting function:

function my.format_code()
  local bufnr = vim.api.nvim_get_current_buf()
  local tsserver_is_attached = false
  for _, client in ipairs(vim.lsp.buf_get_clients(bufnr)) do
    if client.name == "tsserver" then
      tsserver_is_attached = true
      break
    end
  end
  if tsserver_is_attached then
    local status, err = require('nvim-lsp-ts-utils').organize_imports_sync(bufnr)
    if not status then
      my.error("organize_imports_sync failed with: " .. err)
    end
  end
  vim.lsp.buf.formatting_seq_sync(nil, 5000)
end

See https://github.com/jose-elias-alvarez/nvim-lsp-ts-utils/discussions/109

jose-elias-alvarez commented 2 years ago

Perfect, thank you!