responses.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2013 Strahinja Val Markovic <val@markovic.io>
  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. # TODO: Move this file under server/ and rename it responses.py
  20. def BuildGoToResponse( filepath, line_num, column_num, description = None ):
  21. response = {
  22. 'filepath': filepath,
  23. 'line_num': line_num,
  24. 'column_num': column_num
  25. }
  26. if description:
  27. response[ 'description' ] = description
  28. return response
  29. def BuildDescriptionOnlyGoToResponse( text ):
  30. return {
  31. 'description': text,
  32. }
  33. def BuildDisplayMessageResponse( text ):
  34. return {
  35. 'message': text
  36. }
  37. def BuildCompletionData( insertion_text,
  38. extra_menu_info = None,
  39. detailed_info = None,
  40. menu_text = None,
  41. kind = None ):
  42. completion_data = {
  43. 'insertion_text': insertion_text
  44. }
  45. if extra_menu_info:
  46. completion_data[ 'extra_menu_info' ] = extra_menu_info
  47. if menu_text:
  48. completion_data[ 'menu_text' ] = menu_text
  49. if detailed_info:
  50. completion_data[ 'detailed_info' ] = detailed_info
  51. if kind:
  52. completion_data[ 'kind' ] = kind
  53. return completion_data
  54. def BuildDiagnosticData( filepath,
  55. line_num,
  56. column_num,
  57. text,
  58. kind ):
  59. return {
  60. 'filepath': filepath,
  61. 'line_num': line_num,
  62. 'column_num': column_num,
  63. 'text': text,
  64. 'kind': kind
  65. }
  66. def BuildExceptionResponse( error_message, traceback ):
  67. return {
  68. 'message': error_message,
  69. 'traceback': traceback
  70. }