From fc6e2af66f675a4bab9809c8e5837b3e7870c069 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 30 Jul 2018 18:00:43 -0700 Subject: [PATCH] Uniquify textDocument/references There can be duplicates with template instantiation. --- src/indexer.cc | 2 -- src/indexer.h | 5 +++-- src/messages/textDocument_references.cc | 4 +++- src/query.cc | 3 --- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/indexer.cc b/src/indexer.cc index 4853adb5..3217bb18 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1110,8 +1110,6 @@ std::string IndexFile::ToString() { return ccls::Serialize(SerializeFormat::Json, *this); } -MAKE_HASHABLE(Use, t.range, t.file_id) - template void Uniquify(std::vector& a) { std::unordered_set seen; diff --git a/src/indexer.h b/src/indexer.h index 146ff5b4..e43cfc5f 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -61,10 +61,11 @@ struct Use : Reference { // |file| is used in Query* but not in Index* int file_id = -1; bool operator==(const Use& o) const { - return range == o.range && usr == o.usr && kind == o.kind && - role == o.role && file_id == o.file_id; + // lexical container info is ignored. + return range == o.range && file_id == o.file_id; } }; +MAKE_HASHABLE(Use, t.range, t.file_id) void Reflect(Reader& visitor, Reference& value); void Reflect(Writer& visitor, Reference& value); diff --git a/src/messages/textDocument_references.cc b/src/messages/textDocument_references.cc index 479a72ef..b11c5073 100644 --- a/src/messages/textDocument_references.cc +++ b/src/messages/textDocument_references.cc @@ -63,6 +63,7 @@ struct Handler_TextDocumentReferences Out_TextDocumentReferences out; out.id = request->id; bool container = g_config->xref.container; + std::unordered_set seen_uses; for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, params.position)) { // Found symbol. Return references. @@ -76,7 +77,8 @@ struct Handler_TextDocumentReferences stack.pop_back(); auto fn = [&](Use use, lsSymbolKind parent_kind) { if (Role(use.role & params.context.role) == params.context.role && - !(use.role & params.context.excludeRole)) + !(use.role & params.context.excludeRole) && + seen_uses.insert(use).second) if (std::optional ls_loc = GetLsLocationEx(db, working_files, use, container)) { if (container) diff --git a/src/query.cc b/src/query.cc index ed11b8b4..d0d272d2 100644 --- a/src/query.cc +++ b/src/query.cc @@ -12,9 +12,6 @@ #include #include -// Used by |REMOVE_ADD| so only |range| is needed. -MAKE_HASHABLE(Use, t.range, t.file_id); - namespace { void AssignFileId(const Lid2file_id &, int file_id, SymbolRef &ref) {