From d1c90ec85a2b6f6bfa716f41887f4f9153139ffd Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 14 Jul 2018 13:56:00 -0700 Subject: [PATCH] $ccls/publishSemanticHighlighting: support both line/character-style and position-style ranges --- src/config.h | 5 ++++- src/message_handler.cc | 8 +++++--- src/message_handler.h | 12 +++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/config.h b/src/config.h index 1ba2f1c6..13379fbf 100644 --- a/src/config.h +++ b/src/config.h @@ -144,6 +144,9 @@ struct Config { // Semantic highlighting struct Highlight { + // true: LSP line/character; false: position + bool lsRanges = false; + // Like index.{whitelist,blacklist}, don't publish semantic highlighting to // blacklisted files. std::vector blacklist; @@ -230,7 +233,7 @@ MAKE_REFLECT_STRUCT(Config::Diagnostics, onParse, onType, whitelist) -MAKE_REFLECT_STRUCT(Config::Highlight, blacklist, whitelist) +MAKE_REFLECT_STRUCT(Config::Highlight, lsRanges, blacklist, whitelist) MAKE_REFLECT_STRUCT(Config::Index, attributeMakeCallsToCtor, blacklist, diff --git a/src/message_handler.cc b/src/message_handler.cc index 711f1d2f..f6ef4695 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -336,12 +336,14 @@ void EmitSemanticHighlighting(DB *db, Out_CclsPublishSemanticHighlighting out; out.params.uri = lsDocumentUri::FromPath(wfile->filename); // Transform lsRange into pair (offset pairs) - { + if (!g_config->highlight.lsRanges) { std::vector> scratch; - for (auto &entry : grouped_symbols) + for (auto &entry : grouped_symbols) { for (auto &range : entry.second.lsRanges) scratch.emplace_back(range, &entry.second); + entry.second.lsRanges.clear(); + } std::sort(scratch.begin(), scratch.end(), [](auto &l, auto &r) { return l.first.start < r.first.start; }); const auto &buf = wfile->buffer_content; @@ -375,7 +377,7 @@ void EmitSemanticHighlighting(DB *db, } for (auto &entry : grouped_symbols) - if (entry.second.ranges.size()) + if (entry.second.ranges.size() || entry.second.lsRanges.size()) out.params.symbols.push_back(std::move(entry.second)); pipeline::WriteStdout(kMethodType_CclsPublishSemanticHighlighting, out); } diff --git a/src/message_handler.h b/src/message_handler.h index 425a134d..f771ec0b 100644 --- a/src/message_handler.h +++ b/src/message_handler.h @@ -76,15 +76,9 @@ struct Out_CclsPublishSemanticHighlighting std::string method = "$ccls/publishSemanticHighlighting"; Params params; }; -MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Symbol, - stableId, - parentKind, - kind, - storage, - ranges); -MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Params, - uri, - symbols); +MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Symbol, stableId, + parentKind, kind, storage, ranges, lsRanges); +MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting::Params, uri, symbols); MAKE_REFLECT_STRUCT(Out_CclsPublishSemanticHighlighting, jsonrpc, method,