remove document symbols from macro expansion

eg:

 #define M                                                                               \
  namespace ns_name                                                                      \
  {                                                                                      \
  namespace ns_name_impl                                                                 \
  {                                                                                      \
  void f() {}                                                                            \
  }                                                                                      \
  }

M;
This commit is contained in:
Ludovic Jozeau 2021-05-09 22:04:17 +02:00
parent c018bce9af
commit 5208eb6be6
No known key found for this signature in database
GPG Key ID: 881AEC6AAD9BEA6C

View File

@ -130,6 +130,20 @@ template <> bool ignore(const QueryVar::Def *def) {
} }
} // namespace } // namespace
bool is_macro_expansion(DB *db, WorkingFile *wf, QueryFile *file,
DocumentSymbol const &ds) noexcept {
if (ds.kind == SymbolKind::Macro) {
return false;
}
auto start = ds.range.start;
auto syms = findSymbolsAtLocation(wf, file, 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;
}
void MessageHandler::textDocument_documentSymbol(JsonReader &reader, void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
ReplyOnce &reply) { ReplyOnce &reply) {
DocumentSymbolParam param; DocumentSymbolParam param;
@ -183,7 +197,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;
@ -191,7 +205,9 @@ 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(def) &&
(ds->kind == SymbolKind::Namespace || allows(sym)) &&
!is_macro_expansion(db, wf, file, *ds)) {
// 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() &&