1
0

inlay_hints_request.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2022, YouCompleteMe Contributors
  2. #
  3. # This file is part of YouCompleteMe.
  4. #
  5. # YouCompleteMe is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # YouCompleteMe is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. import logging
  18. from ycm.client.base_request import ( BaseRequest, DisplayServerException,
  19. MakeServerException )
  20. _logger = logging.getLogger( __name__ )
  21. # FIXME: This is copy/pasta from SemanticTokensRequest - abstract a
  22. # SimpleAsyncRequest base that does all of this generically
  23. class InlayHintsRequest( BaseRequest ):
  24. def __init__( self, request_data ):
  25. super().__init__()
  26. self.request_data = request_data
  27. self._response_future = None
  28. def Start( self ):
  29. self._response_future = self.PostDataToHandlerAsync( self.request_data,
  30. 'inlay_hints' )
  31. def Done( self ):
  32. return bool( self._response_future ) and self._response_future.done()
  33. def Reset( self ):
  34. self._response_future = None
  35. def Response( self ):
  36. if not self._response_future:
  37. return []
  38. response = self.HandleFuture( self._response_future,
  39. truncate_message = True )
  40. if not response:
  41. return []
  42. # Vim may not be able to convert the 'errors' entry to its internal format
  43. # so we remove it from the response.
  44. errors = response.pop( 'errors', [] )
  45. for e in errors:
  46. exception = MakeServerException( e )
  47. _logger.error( exception )
  48. DisplayServerException( exception, truncate_message = True )
  49. return response.get( 'inlay_hints' ) or []