Skip to content

Commit

Permalink
$ccls/publishSemanticHighlighting: support both line/character-style …
Browse files Browse the repository at this point in the history
…and position-style ranges
  • Loading branch information
MaskRay committed Jul 14, 2018
1 parent d604fc3 commit 4612aa0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> blacklist;
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions src/message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,14 @@ void EmitSemanticHighlighting(DB *db,
Out_CclsPublishSemanticHighlighting out;
out.params.uri = lsDocumentUri::FromPath(wfile->filename);
// Transform lsRange into pair<int, int> (offset pairs)
{
if (!g_config->highlight.lsRanges) {
std::vector<std::pair<lsRange, Out_CclsPublishSemanticHighlighting::Symbol *>>
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;
Expand Down Expand Up @@ -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);
}
12 changes: 3 additions & 9 deletions src/message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4612aa0

Please sign in to comment.