mirror of
https://github.com/MaskRay/ccls.git
synced 2025-03-21 08:16:18 +00:00
clang-format file
This commit is contained in:
parent
b07d39b949
commit
20ef17c0a7
@ -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 ¶m, ReplyOnce &reply) {
|
SemanticTokensRangeParams ¶m, 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);
|
||||||
@ -89,7 +81,7 @@ void MessageHandler::textDocument_semanticTokensRange(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto [queryFile,wFile] = findOrFail(path, reply);
|
auto [queryFile, wFile] = findOrFail(path, reply);
|
||||||
if (!queryFile) {
|
if (!queryFile) {
|
||||||
// `findOrFail` already set the reply message
|
// `findOrFail` already set the reply message
|
||||||
return;
|
return;
|
||||||
@ -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;
|
||||||
@ -146,7 +140,7 @@ void MessageHandler::textDocument_semanticTokensRange(
|
|||||||
// E.g. copy-initialization of constructors should not be highlighted
|
// E.g. copy-initialization of constructors should not be highlighted
|
||||||
// but we still want to keep the range for jumping to definition.
|
// but we still want to keep the range for jumping to definition.
|
||||||
const auto concise_name =
|
const auto concise_name =
|
||||||
detailed_name.substr(0, detailed_name.find('<'));
|
detailed_name.substr(0, detailed_name.find('<'));
|
||||||
const auto start_line_idx = sym.range.start.line;
|
const auto start_line_idx = sym.range.start.line;
|
||||||
const auto start_col = sym.range.start.column;
|
const auto start_col = sym.range.start.column;
|
||||||
if (start_line_idx >= wfile->index_lines.size()) // out-of-range ?
|
if (start_line_idx >= wfile->index_lines.size()) // out-of-range ?
|
||||||
@ -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();
|
||||||
@ -239,7 +235,7 @@ void MessageHandler::textDocument_semanticTokensRange(
|
|||||||
// .
|
// .
|
||||||
if (top && !(events[i - 1].pos == events[i].pos))
|
if (top && !(events[i - 1].pos == events[i].pos))
|
||||||
events[top - 1].symbol->lsRangeAndRoles.push_back(
|
events[top - 1].symbol->lsRangeAndRoles.push_back(
|
||||||
{{events[i - 1].pos, events[i].pos}, events[i].role});
|
{{events[i - 1].pos, events[i].pos}, events[i].role});
|
||||||
if (events[i].id >= 0)
|
if (events[i].id >= 0)
|
||||||
events[top++] = events[i];
|
events[top++] = events[i];
|
||||||
else
|
else
|
||||||
@ -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;
|
||||||
@ -278,19 +279,20 @@ void MessageHandler::textDocument_semanticTokensRange(
|
|||||||
modifiers |= 2;
|
modifiers |= 2;
|
||||||
}
|
}
|
||||||
if (entry.second->kind == SymbolKind::StaticMethod) {
|
if (entry.second->kind == SymbolKind::StaticMethod) {
|
||||||
kindId = (uint8_t) SymbolKind::Method;
|
kindId = (uint8_t)SymbolKind::Method;
|
||||||
modifiers = 4;
|
modifiers = 4;
|
||||||
} else {
|
} else {
|
||||||
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);
|
||||||
}
|
}
|
||||||
// tokens ready, let's tag them with "the next id"
|
// tokens ready, let's tag them with "the next id"
|
||||||
result.id = queryFile->latestSemanticTokens.id +1;
|
result.id = queryFile->latestSemanticTokens.id + 1;
|
||||||
// before sending data, we'll cache the token we're sending
|
// before sending data, we'll cache the token we're sending
|
||||||
queryFile->latestSemanticTokens = result;
|
queryFile->latestSemanticTokens = result;
|
||||||
|
|
||||||
@ -298,8 +300,8 @@ void MessageHandler::textDocument_semanticTokensRange(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MessageHandler::textDocument_semanticTokensFull(
|
void MessageHandler::textDocument_semanticTokensFull(
|
||||||
SemanticTokensParams ¶m, ReplyOnce &reply){
|
SemanticTokensParams ¶m, ReplyOnce &reply) {
|
||||||
lsRange fullRange{documentBegin, documentEnd};
|
lsRange fullRange{documentBegin, documentEnd};
|
||||||
SemanticTokensRangeParams fullRangeParameters{param.textDocument, fullRange};
|
SemanticTokensRangeParams fullRangeParameters{param.textDocument, fullRange};
|
||||||
textDocument_semanticTokensRange(fullRangeParameters, reply);
|
textDocument_semanticTokensRange(fullRangeParameters, reply);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user