mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 13:48:04 +00:00
[comments] Import mpark/variant and make MarkedString a variant (#200)
This commit is contained in:
parent
34052fbf27
commit
6636617b4d
@ -5,7 +5,8 @@
|
||||
#include "serializer.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <optional.h>
|
||||
#include "optional.h"
|
||||
#include "variant.h"
|
||||
#include <rapidjson/writer.h>
|
||||
|
||||
#include <algorithm>
|
||||
@ -982,11 +983,12 @@ MAKE_REFLECT_STRUCT(Out_TextDocumentPublishDiagnostics::Params,
|
||||
//
|
||||
// Note that markdown strings will be sanitized - that means html will be
|
||||
// escaped.
|
||||
struct lsMarkedString {
|
||||
struct lsMarkedString1 {
|
||||
std::string language;
|
||||
std::string value;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(lsMarkedString, language, value);
|
||||
using lsMarkedString = std::variant<std::string, lsMarkedString1>;
|
||||
MAKE_REFLECT_STRUCT(lsMarkedString1, language, value);
|
||||
|
||||
struct lsTextDocumentContentChangeEvent {
|
||||
// The range of the document that changed.
|
||||
|
@ -98,12 +98,11 @@ struct TextDocumentHoverHandler : BaseMessageHandler<Ipc_TextDocumentHover> {
|
||||
if (comments_hover.first || comments_hover.second.size()) {
|
||||
out.result = Out_TextDocumentHover::Result();
|
||||
if (comments_hover.first) {
|
||||
out.result->contents.emplace_back(
|
||||
lsMarkedString{"text", *comments_hover.first});
|
||||
out.result->contents.emplace_back(*comments_hover.first);
|
||||
}
|
||||
if (comments_hover.second.size()) {
|
||||
out.result->contents.emplace_back(
|
||||
lsMarkedString{file->def->language, comments_hover.second});
|
||||
lsMarkedString1{file->def->language, comments_hover.second});
|
||||
}
|
||||
out.result->range = *ls_range;
|
||||
break;
|
||||
|
@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <macro_map.h>
|
||||
#include <optional.h>
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/prettywriter.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "macro_map.h"
|
||||
#include "optional.h"
|
||||
#include "variant.h"
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/prettywriter.h"
|
||||
|
||||
using std::experimental::nullopt;
|
||||
using std::experimental::optional;
|
||||
|
||||
@ -112,10 +113,17 @@ void Reflect(Writer& visitor, std::vector<T>& values) {
|
||||
visitor.EndArray();
|
||||
}
|
||||
template <typename T>
|
||||
void Reflect(Writer& visitor, optional<T> value) {
|
||||
void Reflect(Writer& visitor, optional<T>& value) {
|
||||
if (value)
|
||||
Reflect(visitor, value.value());
|
||||
}
|
||||
template <typename T0, typename T1>
|
||||
void Reflect(Writer& visitor, std::variant<T0, T1>& value) {
|
||||
if (value.index() == 0)
|
||||
Reflect(visitor, std::get<0>(value));
|
||||
else
|
||||
Reflect(visitor, std::get<1>(value));
|
||||
}
|
||||
inline void DefaultReflectMemberStart(Writer& visitor) {
|
||||
visitor.StartObject();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user