mirror of
https://github.com/MaskRay/ccls.git
synced 2025-04-16 22:02:15 +00:00
Merge 0b57c9503d
into 3640f899f1
This commit is contained in:
commit
9c30da3fed
@ -128,12 +128,38 @@ void reflect(JsonWriter &vis, std::unique_ptr<DocumentSymbol> &v) {
|
|||||||
reflect(vis, *v);
|
reflect(vis, *v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Def> bool ignore(const Def *def) { return false; }
|
template <typename Def>
|
||||||
template <> bool ignore(const QueryType::Def *def) {
|
bool isPartOfMacroExpansion(DB *db, WorkingFile *wf, QueryFile *file,
|
||||||
return !def || def->kind == SymbolKind::TypeParameter;
|
Def const *def) noexcept {
|
||||||
|
if (def->kind == SymbolKind::Macro) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto range = getLsRange(wf, def->spell->range);
|
||||||
|
if (range) {
|
||||||
|
auto syms = findSymbolsAtLocation(wf, file, range->start, true);
|
||||||
|
|
||||||
|
auto end = std::end(syms);
|
||||||
|
return std::find_if(std::begin(syms), end, [db](SymbolRef sym) {
|
||||||
|
return getSymbolKind(db, sym) == SymbolKind::Macro;
|
||||||
|
}) != end;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
template <> bool ignore(const QueryVar::Def *def) {
|
|
||||||
return !def || def->is_local();
|
template <typename Def>
|
||||||
|
bool ignore(DB *db, WorkingFile *wf, QueryFile *file, const Def *def) {
|
||||||
|
return isPartOfMacroExpansion(db, wf, file, def);
|
||||||
|
}
|
||||||
|
template <>
|
||||||
|
bool ignore(DB *db, WorkingFile *wf, QueryFile *file,
|
||||||
|
const QueryType::Def *def) {
|
||||||
|
return !def || def->kind == SymbolKind::TypeParameter ||
|
||||||
|
isPartOfMacroExpansion(db, wf, file, def);
|
||||||
|
}
|
||||||
|
template <>
|
||||||
|
bool ignore(DB *db, WorkingFile *wf, QueryFile *file,
|
||||||
|
const QueryVar::Def *def) {
|
||||||
|
return !def || def->is_local() || isPartOfMacroExpansion(db, wf, file, def);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -190,7 +216,7 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
|
|||||||
range1 && range1->includes(*range))
|
range1 && range1->includes(*range))
|
||||||
ds->range = *range1;
|
ds->range = *range1;
|
||||||
}
|
}
|
||||||
withEntity(db, sym, [&](const auto &entity) {
|
withEntity(db, sym, [&, wf = wf, file = file](const auto &entity) {
|
||||||
const auto *def = entity.anyDef();
|
const auto *def = entity.anyDef();
|
||||||
if (!def)
|
if (!def)
|
||||||
return;
|
return;
|
||||||
@ -198,7 +224,8 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
|
|||||||
ds->detail = def->detailed_name;
|
ds->detail = def->detailed_name;
|
||||||
ds->kind = def->kind;
|
ds->kind = def->kind;
|
||||||
|
|
||||||
if (!ignore(def) && (ds->kind == SymbolKind::Namespace || allows(sym))) {
|
if (!ignore(db, wf, file, def) &&
|
||||||
|
(ds->kind == SymbolKind::Namespace || allows(sym))) {
|
||||||
// Drop scopes which are before selectionRange.start. In
|
// Drop scopes which are before selectionRange.start. In
|
||||||
// `int i, j, k;`, the scope of i will be ended by j.
|
// `int i, j, k;`, the scope of i will be ended by j.
|
||||||
while (!scopes.empty() &&
|
while (!scopes.empty() &&
|
||||||
@ -221,8 +248,10 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
|
|||||||
continue;
|
continue;
|
||||||
if (std::optional<SymbolInformation> info =
|
if (std::optional<SymbolInformation> info =
|
||||||
getSymbolInfo(db, sym, false)) {
|
getSymbolInfo(db, sym, false)) {
|
||||||
if ((sym.kind == Kind::Type && ignore(db->getType(sym).anyDef())) ||
|
if ((sym.kind == Kind::Type &&
|
||||||
(sym.kind == Kind::Var && ignore(db->getVar(sym).anyDef())))
|
ignore(db, wf, file, db->getType(sym).anyDef())) ||
|
||||||
|
(sym.kind == Kind::Var &&
|
||||||
|
ignore(db, wf, file, db->getVar(sym).anyDef())))
|
||||||
continue;
|
continue;
|
||||||
if (auto loc = getLsLocation(db, wfiles, sym, file_id)) {
|
if (auto loc = getLsLocation(db, wfiles, sym, file_id)) {
|
||||||
info->location = *loc;
|
info->location = *loc;
|
||||||
|
Loading…
Reference in New Issue
Block a user