debug_info_request.py 4.3 KB

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