Skip to content

Commit

Permalink
Uniquify textDocument/references
Browse files Browse the repository at this point in the history
There can be duplicates with template instantiation.
  • Loading branch information
MaskRay committed Oct 24, 2019
1 parent 3c851a2 commit 8449051
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,6 @@ std::string IndexFile::ToString() {
return ccls::Serialize(SerializeFormat::Json, *this);
}

MAKE_HASHABLE(Use, t.range, t.file_id)

template <typename T>
void Uniquify(std::vector<T>& a) {
std::unordered_set<T> seen;
Expand Down
5 changes: 3 additions & 2 deletions src/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/messages/textDocument_references.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct Handler_TextDocumentReferences
Out_TextDocumentReferences out;
out.id = request->id;
bool container = g_config->xref.container;
std::unordered_set<Use> seen_uses;

for (SymbolRef sym : FindSymbolsAtLocation(wfile, file, params.position)) {
// Found symbol. Return references.
Expand All @@ -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<lsLocationEx> ls_loc =
GetLsLocationEx(db, working_files, use, container)) {
if (container)
Expand Down
3 changes: 0 additions & 3 deletions src/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#include <unordered_map>
#include <unordered_set>

// 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) {
Expand Down

0 comments on commit 8449051

Please sign in to comment.