omni_completion_request.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2013 Google Inc.
  4. #
  5. # This file is part of YouCompleteMe.
  6. #
  7. # YouCompleteMe is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # YouCompleteMe is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  19. from ycmd.utils import ToUtf8IfNeeded
  20. from ycm.client.completion_request import CompletionRequest
  21. class OmniCompletionRequest( CompletionRequest ):
  22. def __init__( self, omni_completer, request_data ):
  23. super( OmniCompletionRequest, self ).__init__( request_data )
  24. self._omni_completer = omni_completer
  25. def Start( self ):
  26. self._results = self._omni_completer.ComputeCandidates( self.request_data )
  27. def Done( self ):
  28. return True
  29. def RawResponse( self ):
  30. return _ConvertVimDatasToCompletionDatas( self._results )
  31. def Response( self ):
  32. return self._results
  33. def ConvertVimDataToCompletionData( vim_data ):
  34. # see :h complete-items for a description of the dictionary fields
  35. completion_data = {}
  36. if 'word' in vim_data:
  37. completion_data[ 'insertion_text' ] = ToUtf8IfNeeded( vim_data[ 'word' ] )
  38. if 'abbr' in vim_data:
  39. completion_data[ 'menu_text' ] = ToUtf8IfNeeded( vim_data[ 'abbr' ] )
  40. if 'menu' in vim_data:
  41. completion_data[ 'extra_menu_info' ] = ToUtf8IfNeeded( vim_data[ 'menu' ] )
  42. if 'kind' in vim_data:
  43. completion_data[ 'kind' ] = [ ToUtf8IfNeeded( vim_data[ 'kind' ] ) ]
  44. if 'info' in vim_data:
  45. completion_data[ 'detailed_info' ] = ToUtf8IfNeeded( vim_data[ 'info' ] )
  46. return completion_data
  47. def _ConvertVimDatasToCompletionDatas( response_data ):
  48. return [ ConvertVimDataToCompletionData( x )
  49. for x in response_data ]