mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
Uniquify textDocument/references
There can be duplicates with template instantiation.
This commit is contained in:
parent
af881dff18
commit
fc6e2af66f
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user