Browse Source

Added LanguageProtocol::Diagnostic::code

pipelines/280567345
eidheim 5 years ago
parent
commit
6dd97e41e6
  1. 9
      src/source_language_protocol.cpp
  2. 2
      src/source_language_protocol.hpp

9
src/source_language_protocol.cpp

@ -41,7 +41,7 @@ LanguageProtocol::Location::Location(const boost::property_tree::ptree &pt, std:
LanguageProtocol::Diagnostic::RelatedInformation::RelatedInformation(const boost::property_tree::ptree &pt) : message(pt.get<std::string>("message")), location(pt.get_child("location")) {} LanguageProtocol::Diagnostic::RelatedInformation::RelatedInformation(const boost::property_tree::ptree &pt) : message(pt.get<std::string>("message")), location(pt.get_child("location")) {}
LanguageProtocol::Diagnostic::Diagnostic(const boost::property_tree::ptree &pt) : message(pt.get<std::string>("message")), range(pt.get_child("range")), severity(pt.get<int>("severity", 0)) { LanguageProtocol::Diagnostic::Diagnostic(const boost::property_tree::ptree &pt) : message(pt.get<std::string>("message")), range(pt.get_child("range")), severity(pt.get<int>("severity", 0)), code(pt.get<std::string>("code", "")) {
auto related_information_it = pt.get_child("relatedInformation", boost::property_tree::ptree()); 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) for(auto it = related_information_it.begin(); it != related_information_it.end(); ++it)
related_informations.emplace_back(it->second); related_informations.emplace_back(it->second);
@ -1008,7 +1008,12 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
escape_text(message); escape_text(message);
if(!diagnostics_string.empty()) if(!diagnostics_string.empty())
diagnostics_string += ','; diagnostics_string += ',';
diagnostics_string += "{\"range\":" + range + ",\"message\":\"" + message + "\"}"; diagnostics_string += "{\"range\":" + range + ",\"message\":\"" + message + "\"";
if(diagnostic.severity != 0)
diagnostics_string += ",\"severity\":" + std::to_string(diagnostic.severity);
if(!diagnostic.code.empty())
diagnostics_string += ",\"code\":\"" + diagnostic.code + "\"";
diagnostics_string += "}";
} }
if(diagnostics.size() != 1) { // Use diagnostic range if only one diagnostic, otherwise use whole buffer if(diagnostics.size() != 1) { // Use diagnostic range if only one diagnostic, otherwise use whole buffer
auto start = get_buffer()->begin(); auto start = get_buffer()->begin();

2
src/source_language_protocol.hpp

@ -69,7 +69,9 @@ namespace LanguageProtocol {
Diagnostic(const boost::property_tree::ptree &pt); Diagnostic(const boost::property_tree::ptree &pt);
std::string message; std::string message;
Range range; Range range;
/// 1: error, 2: warning, 3: information, 4: hint
int severity; int severity;
std::string code;
std::vector<RelatedInformation> related_informations; std::vector<RelatedInformation> related_informations;
std::map<std::string, std::set<Source::FixIt>> quickfixes; std::map<std::string, std::set<Source::FixIt>> quickfixes;
}; };

Loading…
Cancel
Save