debug_info_request.py 3.7 KB

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