LanguageClient.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "LanguageClient.h"
  27. #include <AK/String.h>
  28. #include <AK/Vector.h>
  29. namespace HackStudio {
  30. void ServerConnection::handle(const Messages::LanguageClient::AutoCompleteSuggestions& message)
  31. {
  32. if (m_language_client)
  33. m_language_client->provide_autocomplete_suggestions(message.suggestions());
  34. }
  35. void LanguageClient::open_file(const String& path)
  36. {
  37. m_connection.post_message(Messages::LanguageServer::FileOpened(path));
  38. }
  39. void LanguageClient::set_file_content(const String& path, const String& content)
  40. {
  41. m_connection.post_message(Messages::LanguageServer::SetFileContent(path, content));
  42. }
  43. void LanguageClient::insert_text(const String& path, const String& text, size_t line, size_t column)
  44. {
  45. m_connection.post_message(Messages::LanguageServer::FileEditInsertText(path, text, line, column));
  46. }
  47. void LanguageClient::remove_text(const String& path, size_t from_line, size_t from_column, size_t to_line, size_t to_column)
  48. {
  49. m_connection.post_message(Messages::LanguageServer::FileEditRemoveText(path, from_line, from_column, to_line, to_column));
  50. }
  51. void LanguageClient::request_autocomplete(const String& path, size_t cursor_line, size_t cursor_column)
  52. {
  53. m_connection.post_message(Messages::LanguageServer::AutoCompleteSuggestions(path, cursor_line, cursor_column));
  54. }
  55. void LanguageClient::provide_autocomplete_suggestions(const Vector<String>& suggestions)
  56. {
  57. if (on_autocomplete_suggestions)
  58. on_autocomplete_suggestions(suggestions);
  59. // Otherwise, drop it on the floor :shrug:
  60. }
  61. }