clang-format file

This commit is contained in:
Felipe Lema 2021-06-23 12:29:54 -04:00
parent b07d39b949
commit 20ef17c0a7

View File

@ -7,8 +7,8 @@
#include "pipeline.hh" #include "pipeline.hh"
#include "sema_manager.hh" #include "sema_manager.hh"
#include <clang/Sema/Sema.h>
#include <algorithm> #include <algorithm>
#include <clang/Sema/Sema.h>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -52,35 +52,27 @@ struct ScanLineEvent {
} }
}; };
} } // namespace
constexpr Position documentBegin{0, 0}; constexpr Position documentBegin{0, 0};
constexpr Position documentEnd{ constexpr Position documentEnd{
std::numeric_limits<decltype(Position::line)>::max(), std::numeric_limits<decltype(Position::line)>::max(),
std::numeric_limits<decltype(Position::character)>::max()}; std::numeric_limits<decltype(Position::character)>::max()};
inline std::ostream &operator<<(std::ostream &s, const Position pos) { inline std::ostream &operator<<(std::ostream &s, const Position pos) {
s s << "{line: " << pos.line << ", end: " << pos.character;
<< "{line: " << pos.line
<< ", end: " << pos.character;
return s; return s;
} }
inline std::ostream &operator<<(std::ostream &s, const lsRange &range) { inline std::ostream &operator<<(std::ostream &s, const lsRange &range) {
s s << "lsRange(start:" << range.start << ", end:" << range.end << ")";
<< "lsRange(start:" << range.start
<< ", end:" << range.end
<< ")";
return s; return s;
} }
void MessageHandler::textDocument_semanticTokensRange( void MessageHandler::textDocument_semanticTokensRange(
SemanticTokensRangeParams &param, ReplyOnce &reply) { SemanticTokensRangeParams &param, ReplyOnce &reply) {
if (param.range.start == documentBegin && param.range.end == documentEnd) if (param.range.start == documentBegin && param.range.end == documentEnd)
LOG_S(INFO) LOG_S(INFO) << "SemanticToken for all document";
<< "SemanticToken for all document";
else else
LOG_S(INFO) LOG_S(INFO) << "SemanticToken for range " << param.range.start;
<< "SemanticToken for range "
<< param.range.start;
std::string path = param.textDocument.uri.getPath(); std::string path = param.textDocument.uri.getPath();
WorkingFile *wfile = wfiles->getFile(path); WorkingFile *wfile = wfiles->getFile(path);
@ -102,7 +94,8 @@ void MessageHandler::textDocument_semanticTokensRange(
assert(queryFile->def); assert(queryFile->def);
if (wfile->buffer_content.size() > g_config->highlight.largeFileSize || if (wfile->buffer_content.size() > g_config->highlight.largeFileSize ||
!match.matches(queryFile->def->path)) { !match.matches(queryFile->def->path)) {
LOG_S(INFO) << "Not SemTokenizing " << path << "because of allowlist/denylist"; LOG_S(INFO) << "Not SemTokenizing " << path
<< "because of allowlist/denylist";
return; return;
} }
@ -112,11 +105,12 @@ void MessageHandler::textDocument_semanticTokensRange(
if (refcnt <= 0) if (refcnt <= 0)
continue; continue;
// skip symbols that don't intersect range // skip symbols that don't intersect range
if( sym.range.end.line < param.range.start.line if (sym.range.end.line < param.range.start.line ||
|| sym.range.start.line > param.range.end.line sym.range.start.line > param.range.end.line
// range is within lines here below, let's test if within specified characters/columns // range is within lines here below, let's test if within specified
|| sym.range.end.column < param.range.start.character // characters/columns
|| sym.range.start.column > param.range.end.character) || sym.range.end.column < param.range.start.character ||
sym.range.start.column > param.range.end.character)
continue; continue;
std::string_view detailed_name; std::string_view detailed_name;
SymbolKind parent_kind = SymbolKind::Unknown; SymbolKind parent_kind = SymbolKind::Unknown;
@ -215,11 +209,13 @@ void MessageHandler::textDocument_semanticTokensRange(
for (auto &loc : symbol.lsRangeAndRoles) { for (auto &loc : symbol.lsRangeAndRoles) {
// For ranges sharing the same start point, the one with leftmost end // For ranges sharing the same start point, the one with leftmost end
// point comes first. // point comes first.
events.push_back({loc.first.start, loc.first.end, id, &symbol, loc.second}); events.push_back(
{loc.first.start, loc.first.end, id, &symbol, loc.second});
// For ranges sharing the same end point, their relative order does not // For ranges sharing the same end point, their relative order does not
// matter, therefore we arbitrarily assign loc.end to them. We use // matter, therefore we arbitrarily assign loc.end to them. We use
// negative id to indicate a deletion event. // negative id to indicate a deletion event.
events.push_back({loc.first.end, loc.first.end, ~id, &symbol, loc.second}); events.push_back(
{loc.first.end, loc.first.end, ~id, &symbol, loc.second});
id++; id++;
} }
symbol.lsRangeAndRoles.clear(); symbol.lsRangeAndRoles.clear();
@ -247,14 +243,17 @@ void MessageHandler::textDocument_semanticTokensRange(
} }
// Transform lsRange into pair<int, int> (offset pairs) // Transform lsRange into pair<int, int> (offset pairs)
std::vector<std::pair<std::pair<lsRange, Role>, CclsSemanticHighlightSymbol *>> scratch; std::vector<
std::pair<std::pair<lsRange, Role>, CclsSemanticHighlightSymbol *>>
scratch;
for (auto &entry : grouped_symbols) { for (auto &entry : grouped_symbols) {
for (auto &range : entry.second.lsRangeAndRoles) for (auto &range : entry.second.lsRangeAndRoles)
scratch.emplace_back(range, &entry.second); scratch.emplace_back(range, &entry.second);
entry.second.lsRangeAndRoles.clear(); entry.second.lsRangeAndRoles.clear();
} }
std::sort(scratch.begin(), scratch.end(), std::sort(scratch.begin(), scratch.end(), [](auto &l, auto &r) {
[](auto &l, auto &r) { return l.first.first.start < r.first.first.start; }); return l.first.first.start < r.first.first.start;
});
int line = 0; int line = 0;
int column = 0; int column = 0;
for (auto &entry : scratch) { for (auto &entry : scratch) {
@ -265,8 +264,10 @@ void MessageHandler::textDocument_semanticTokensRange(
auto &serialized = result.tokens.data; auto &serialized = result.tokens.data;
serialized.push_back(r.start.line - line); line = r.start.line; serialized.push_back(r.start.line - line);
serialized.push_back(r.start.character - column); column = r.start.character; line = r.start.line;
serialized.push_back(r.start.character - column);
column = r.start.character;
serialized.push_back(r.end.character - r.start.character); serialized.push_back(r.end.character - r.start.character);
uint8_t kindId; uint8_t kindId;
@ -284,7 +285,8 @@ void MessageHandler::textDocument_semanticTokensRange(
kindId = (uint8_t)entry.second->kind; kindId = (uint8_t)entry.second->kind;
if (kindId > (uint8_t)SymbolKind::StaticMethod) if (kindId > (uint8_t)SymbolKind::StaticMethod)
kindId--; kindId--;
if (kindId >= 252) kindId = 27 + kindId - 252; if (kindId >= 252)
kindId = 27 + kindId - 252;
} }
serialized.push_back(kindId); serialized.push_back(kindId);
serialized.push_back(modifiers); serialized.push_back(modifiers);