Work around SIGSEGV and simplify SymbolIdx

This commit is contained in:
Fangrui Song 2018-02-09 16:42:33 -08:00
parent fd803ffb84
commit aa125e34f3
4 changed files with 10 additions and 10 deletions

View File

@ -171,7 +171,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
optional<lsRange> loc = GetLsRange(working_file, sym.range);
if (loc) {
auto key = SymbolIdx(sym.kind, RawId(sym.id));
auto key = SymbolIdx{RawId(sym.id), sym.kind};
auto it = grouped_symbols.find(key);
if (it != grouped_symbols.end()) {
it->second.ranges.push_back(*loc);

View File

@ -1003,7 +1003,7 @@ void QueryDatabase::UpdateSymbols(Maybe<Id<void>>* symbol_idx,
RawId idx) {
if (!symbol_idx->has_value()) {
*symbol_idx = Id<void>(symbols.size());
symbols.push_back(SymbolIdx(kind, idx));
symbols.push_back(SymbolIdx{idx, kind});
}
}

View File

@ -47,13 +47,8 @@ MAKE_REFLECT_STRUCT(QueryLocation, range, path, role);
MAKE_HASHABLE(QueryLocation, t.range, t.path, t.role);
struct SymbolIdx {
SymbolKind kind;
RawId idx;
SymbolIdx()
: kind(SymbolKind::Invalid),
idx(RawId(-1)) {} // Default ctor needed by stdlib. Do not use.
SymbolIdx(SymbolKind kind, RawId idx) : kind(kind), idx(idx) {}
SymbolKind kind;
bool operator==(const SymbolIdx& o) const {
return kind == o.kind && idx == o.idx;
@ -78,7 +73,7 @@ struct SymbolRef : Reference {
: Reference{Range(), Id<void>(si.idx), si.kind, SymbolRole::None} {}
RawId Idx() const { return RawId(id); }
operator SymbolIdx() const { return SymbolIdx(kind, Idx()); }
operator SymbolIdx() const { return SymbolIdx{Idx(), kind, }; }
QueryFunc& Func(QueryDatabase* db) const;
QueryType& Type(QueryDatabase* db) const;
QueryVar& Var(QueryDatabase* db) const;

View File

@ -2,6 +2,8 @@
#include "queue_manager.h"
#include <loguru.hpp>
#include <climits>
#include <queue>
@ -367,7 +369,10 @@ optional<lsLocation> GetLsLocation(QueryDatabase* db,
WorkingFiles* working_files,
Reference ref) {
std::string path;
lsDocumentUri uri = GetLsDocumentUri(db, GetFileId(db, ref), &path);
QueryFileId file_id = GetFileId(db, ref);
if (!file_id.HasValue())
return nullopt;
lsDocumentUri uri = GetLsDocumentUri(db, file_id, &path);
optional<lsRange> range =
GetLsRange(working_files->GetFileByFilename(path), ref.range);
if (!range)