debug_info_request.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Copyright (C) 2016-2017 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. from __future__ import unicode_literals
  18. from __future__ import print_function
  19. from __future__ import division
  20. from __future__ import absolute_import
  21. # Not installing aliases from python-future; it's unreliable and slow.
  22. from builtins import * # noqa
  23. from ycm.client.base_request import BaseRequest, BuildRequestData
  24. class DebugInfoRequest( BaseRequest ):
  25. def __init__( self, extra_data = None ):
  26. super( DebugInfoRequest, self ).__init__()
  27. self._extra_data = extra_data
  28. self._response = None
  29. def Start( self ):
  30. request_data = BuildRequestData()
  31. if self._extra_data:
  32. request_data.update( self._extra_data )
  33. self._response = self.PostDataToHandler( request_data,
  34. 'debug_info',
  35. display_message = False )
  36. def Response( self ):
  37. return self._response
  38. def FormatDebugInfoResponse( response ):
  39. if not response:
  40. return 'Server errored, no debug info from server\n'
  41. message = _FormatYcmdDebugInfo( response )
  42. completer = response[ 'completer' ]
  43. if completer:
  44. message += _FormatCompleterDebugInfo( completer )
  45. return message
  46. def _FormatYcmdDebugInfo( ycmd ):
  47. python = ycmd[ 'python' ]
  48. clang = ycmd[ 'clang' ]
  49. message = ( 'Server Python interpreter: {0}\n'
  50. 'Server Python version: {1}\n'
  51. 'Server has Clang support compiled in: {2}\n'
  52. 'Clang version: {3}\n'.format( python[ 'executable' ],
  53. python[ 'version' ],
  54. clang[ 'has_support' ],
  55. clang[ 'version' ] ) )
  56. extra_conf = ycmd[ 'extra_conf' ]
  57. extra_conf_path = extra_conf[ 'path' ]
  58. if not extra_conf_path:
  59. message += 'No extra configuration file found\n'
  60. elif not extra_conf[ 'is_loaded' ]:
  61. message += ( 'Extra configuration file found but not loaded\n'
  62. 'Extra configuration path: {0}\n'.format( extra_conf_path ) )
  63. else:
  64. message += ( 'Extra configuration file found and loaded\n'
  65. 'Extra configuration path: {0}\n'.format( extra_conf_path ) )
  66. return message
  67. def _FormatCompleterDebugInfo( completer ):
  68. message = '{0} completer debug information:\n'.format( completer[ 'name' ] )
  69. for server in completer[ 'servers' ]:
  70. name = server[ 'name' ]
  71. if server[ 'is_running' ]:
  72. address = server[ 'address' ]
  73. port = server[ 'port' ]
  74. if address and port:
  75. message += ' {0} running at: http://{1}:{2}\n'.format( name,
  76. address,
  77. port )
  78. else:
  79. message += ' {0} running\n'.format( name )
  80. message += ' {0} process ID: {1}\n'.format( name, server[ 'pid' ] )
  81. else:
  82. message += ' {0} not running\n'.format( name )
  83. message += ' {0} executable: {1}\n'.format( name, server[ 'executable' ] )
  84. logfiles = server[ 'logfiles' ]
  85. if logfiles:
  86. message += ' {0} logfiles:\n'.format( name )
  87. for logfile in logfiles:
  88. message += ' {0}\n'.format( logfile )
  89. else:
  90. message += ' No logfiles available\n'
  91. if 'extras' in server:
  92. for extra in server[ 'extras' ]:
  93. message += ' {0} {1}: {2}\n'.format( name,
  94. extra[ 'key' ],
  95. extra[ 'value' ] )
  96. for item in completer[ 'items' ]:
  97. message += ' {0}: {1}\n'.format( item[ 'key' ].capitalize(),
  98. item[ 'value' ] )
  99. return message
  100. def SendDebugInfoRequest( extra_data = None ):
  101. request = DebugInfoRequest( extra_data )
  102. # This is a blocking call.
  103. request.Start()
  104. return request.Response()