From f831bcd61f6a5b9cb5732ee9f235497201be0d4e Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 30 Jul 2018 13:42:27 +0200 Subject: [PATCH] Moved implementations of LanguageProtocol structures to .cc file --- src/source_language_protocol.cc | 23 +++++++++++++++++++++++ src/source_language_protocol.h | 29 ++++++----------------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/source_language_protocol.cc b/src/source_language_protocol.cc index fabec01..7e1bf00 100644 --- a/src/source_language_protocol.cc +++ b/src/source_language_protocol.cc @@ -16,6 +16,29 @@ const std::string flow_coverage_message = "Not covered by Flow"; +LanguageProtocol::Offset::Offset(const boost::property_tree::ptree &pt) : line(pt.get("line")), character(pt.get("character")) {} + +LanguageProtocol::Range::Range(const boost::property_tree::ptree &pt) : start(pt.get_child("start")), end(pt.get_child("end")) {} + +LanguageProtocol::Location::Location(const boost::property_tree::ptree &pt, std::string uri_) : range(pt.get_child("range")) { + if(uri_.empty()) { + uri = pt.get("uri"); + uri.erase(0, 7); + } + else + uri = std::move(uri_); +} + +LanguageProtocol::Diagnostic::RelatedInformation::RelatedInformation(const boost::property_tree::ptree &pt) : message(pt.get("message")), location(pt.get_child("location")) {} + +LanguageProtocol::Diagnostic::Diagnostic(const boost::property_tree::ptree &pt) : message(pt.get("message")), range(pt.get_child("range")), severity(pt.get("severity", 0)) { + auto related_information_it = pt.get_child("relatedInformation", boost::property_tree::ptree()); + for(auto it = related_information_it.begin(); it != related_information_it.end(); ++it) + related_informations.emplace_back(it->second); +} + +LanguageProtocol::TextEdit::TextEdit(const boost::property_tree::ptree &pt, std::string new_text_) : range(pt.get_child("range")), new_text(new_text_.empty() ? pt.get("newText") : std::move(new_text_)) {} + LanguageProtocol::Client::Client(std::string root_uri_, std::string language_id_) : root_uri(std::move(root_uri_)), language_id(std::move(language_id_)) { process = std::make_unique(language_id + "-language-server", root_uri, [this](const char *bytes, size_t n) { server_message_stream.write(bytes, n); diff --git a/src/source_language_protocol.h b/src/source_language_protocol.h index a4f1462..b98a973 100644 --- a/src/source_language_protocol.h +++ b/src/source_language_protocol.h @@ -16,30 +16,21 @@ namespace Source { namespace LanguageProtocol { class Offset { public: - Offset(const boost::property_tree::ptree &pt) : line(pt.get("line")), - character(pt.get("character")) {} + Offset(const boost::property_tree::ptree &pt); int line; int character; }; class Range { public: - Range(const boost::property_tree::ptree &pt) : start(pt.get_child("start")), - end(pt.get_child("end")) {} + Range(const boost::property_tree::ptree &pt); Range() = default; Offset start, end; }; class Location { public: - Location(const boost::property_tree::ptree &pt, std::string uri_ = {}) : range(pt.get_child("range")) { - if(uri_.empty()) { - uri = pt.get("uri"); - uri.erase(0, 7); - } - else - uri = std::move(uri_); - } + Location(const boost::property_tree::ptree &pt, std::string uri_ = {}); std::string uri; Range range; }; @@ -48,19 +39,12 @@ namespace LanguageProtocol { public: class RelatedInformation { public: - RelatedInformation(const boost::property_tree::ptree &pt) : message(pt.get("message")), - location(pt.get_child("location")) {} + RelatedInformation(const boost::property_tree::ptree &pt); std::string message; Location location; }; - Diagnostic(const boost::property_tree::ptree &pt) : message(pt.get("message")), - range(pt.get_child("range")), - severity(pt.get("severity", 0)) { - auto related_information_it = pt.get_child("relatedInformation", boost::property_tree::ptree()); - for(auto it = related_information_it.begin(); it != related_information_it.end(); ++it) - related_informations.emplace_back(it->second); - } + Diagnostic(const boost::property_tree::ptree &pt); std::string message; Range range; int severity; @@ -69,8 +53,7 @@ namespace LanguageProtocol { class TextEdit { public: - TextEdit(const boost::property_tree::ptree &pt, std::string new_text_ = {}) : range(pt.get_child("range")), - new_text(new_text_.empty() ? pt.get("newText") : std::move(new_text_)) {} + TextEdit(const boost::property_tree::ptree &pt, std::string new_text_ = {}); Range range; std::string new_text; };