Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove document symbols from macro expansion #794

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/messages/textDocument_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ template <> bool ignore(const QueryVar::Def *def) {
}
} // namespace

bool is_macro_expansion(DB *db, WorkingFile *wf, QueryFile *file,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be folded into ignore for QueryVar::Def

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little bit cumbersome, I'll make a commit, so you can see what it looks like, but we would have to edit all ignore functions not just for QueryVar::Def because we want to ignore all symbols generated by macro expansion not just variables.

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,
ReplyOnce &reply) {
DocumentSymbolParam param;
Expand Down Expand Up @@ -183,15 +197,17 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
range1 && range1->includes(*range))
ds->range = *range1;
}
withEntity(db, sym, [&](const auto &entity) {
withEntity(db, sym, [&, wf = wf, file = file](const auto &entity) {
const auto *def = entity.anyDef();
if (!def)
return;
ds->name = def->name(false);
ds->detail = def->detailed_name;
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
// `int i, j, k;`, the scope of i will be ended by j.
while (!scopes.empty() &&
Expand Down