omni_completion_request.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2013 Google Inc.
  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. from ycmd.utils import ToUtf8IfNeeded
  18. from ycm.client.completion_request import CompletionRequest
  19. class OmniCompletionRequest( CompletionRequest ):
  20. def __init__( self, omni_completer, request_data ):
  21. super( OmniCompletionRequest, self ).__init__( request_data )
  22. self._omni_completer = omni_completer
  23. def Start( self ):
  24. self._results = self._omni_completer.ComputeCandidates( self.request_data )
  25. def Done( self ):
  26. return True
  27. def RawResponse( self ):
  28. return _ConvertVimDatasToCompletionDatas( self._results )
  29. def Response( self ):
  30. return self._results
  31. def ConvertVimDataToCompletionData( vim_data ):
  32. # see :h complete-items for a description of the dictionary fields
  33. completion_data = {}
  34. if 'word' in vim_data:
  35. completion_data[ 'insertion_text' ] = ToUtf8IfNeeded( vim_data[ 'word' ] )
  36. if 'abbr' in vim_data:
  37. completion_data[ 'menu_text' ] = ToUtf8IfNeeded( vim_data[ 'abbr' ] )
  38. if 'menu' in vim_data:
  39. completion_data[ 'extra_menu_info' ] = ToUtf8IfNeeded( vim_data[ 'menu' ] )
  40. if 'kind' in vim_data:
  41. completion_data[ 'kind' ] = [ ToUtf8IfNeeded( vim_data[ 'kind' ] ) ]
  42. if 'info' in vim_data:
  43. completion_data[ 'detailed_info' ] = ToUtf8IfNeeded( vim_data[ 'info' ] )
  44. return completion_data
  45. def _ConvertVimDatasToCompletionDatas( response_data ):
  46. return [ ConvertVimDataToCompletionData( x )
  47. for x in response_data ]