Skip to content

Commit

Permalink
Add Query*::file_id to allow textDocument/hover on declarations
Browse files Browse the repository at this point in the history
Also change StorageClass storage to uint8_t
  • Loading branch information
MaskRay committed Jul 21, 2018
1 parent 19fa911 commit 27d641b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions index_tests/macros/complex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FOO(make1(), make2);
"bases": [],
"derived": [],
"vars": [],
"uses": ["12:5-12:10|0|1|16420"],
"uses": ["12:5-12:10|0|1|16420", "12:5-12:10|0|1|64|0"],
"callees": []
}],
"usr2type": [{
Expand Down Expand Up @@ -73,7 +73,7 @@ FOO(make1(), make2);
"spell": "9:11-9:16|0|1|2",
"extent": "9:1-9:20|0|1|0",
"type": 53,
"uses": ["12:14-12:19|0|1|12"],
"uses": ["12:14-12:19|0|1|12", "12:14-12:19|0|1|64|0"],
"kind": 13,
"storage": 0
}, {
Expand Down
2 changes: 1 addition & 1 deletion index_tests/macros/foo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int x = A;
"funcs": [13788753348312146871],
"vars": [],
"instances": [],
"uses": ["5:12-5:15|0|1|4"]
"uses": ["5:12-5:15|0|1|4", "5:12-5:15|0|1|64|0"]
}],
"usr2var": [{
"usr": 1569772797058982873,
Expand Down
8 changes: 4 additions & 4 deletions index_tests/namespaces/namespace_alias.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void func() {
"declarations": ["1:11-1:14|0|1|1"],
"alias_of": 0,
"bases": [],
"derived": [],
"derived": [17805385787823406700],
"types": [17805385787823406700],
"funcs": [],
"vars": [],
Expand Down Expand Up @@ -87,7 +87,7 @@ void func() {
"kind": 3,
"declarations": ["3:20-3:23|17805385787823406700|2|1025"],
"alias_of": 0,
"bases": [],
"bases": [17805385787823406700, 17805385787823406700, 17805385787823406700, 17805385787823406700],
"derived": [],
"types": [],
"funcs": [],
Expand All @@ -105,8 +105,8 @@ void func() {
"kind": 3,
"declarations": ["2:15-2:18|926793467007732869|2|1025"],
"alias_of": 0,
"bases": [],
"derived": [],
"bases": [926793467007732869, 926793467007732869, 926793467007732869, 926793467007732869],
"derived": [14450849931009540802],
"types": [14450849931009540802],
"funcs": [],
"vars": [],
Expand Down
2 changes: 1 addition & 1 deletion index_tests/usage/func_called_from_macro_argument.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void caller() {
"bases": [],
"derived": [],
"vars": [],
"uses": ["6:14-6:20|0|1|16420"],
"uses": ["6:14-6:20|0|1|16420", "6:14-6:20|0|1|64|0"],
"callees": []
}, {
"usr": 11404881820527069090,
Expand Down
9 changes: 5 additions & 4 deletions src/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ void Reflect(Writer& visitor, Reference& value);
void Reflect(Reader& visitor, Use& value);
void Reflect(Writer& visitor, Use& value);

MAKE_REFLECT_TYPE_PROXY2(clang::StorageClass, uint8_t);

template <typename D>
struct NameMixin {
std::string_view Name(bool qualified) const {
Expand Down Expand Up @@ -104,11 +102,12 @@ struct FuncDef : NameMixin<FuncDef> {
// Functions that this function calls.
std::vector<SymbolRef> callees;

int file_id = -1;
int16_t qual_name_offset = 0;
int16_t short_name_offset = 0;
int16_t short_name_size = 0;
lsSymbolKind kind = lsSymbolKind::Unknown;
clang::StorageClass storage = clang::SC_None;
uint8_t storage = clang::SC_None;

std::vector<Usr> GetBases() const { return bases; }
};
Expand Down Expand Up @@ -155,6 +154,7 @@ struct TypeDef : NameMixin<TypeDef> {
// type comes from a using or typedef statement).
Usr alias_of = 0;

int file_id = -1;
int16_t qual_name_offset = 0;
int16_t short_name_offset = 0;
int16_t short_name_size = 0;
Expand Down Expand Up @@ -199,14 +199,15 @@ struct VarDef : NameMixin<VarDef> {
// Type of the variable.
Usr type = 0;

int file_id = -1;
int16_t qual_name_offset = 0;
int16_t short_name_offset = 0;
int16_t short_name_size = 0;

lsSymbolKind kind = lsSymbolKind::Unknown;
// Note a variable may have instances of both |None| and |Extern|
// (declaration).
clang::StorageClass storage = clang::SC_None;
uint8_t storage = clang::SC_None;

bool is_local() const {
return spell && spell->kind != SymbolKind::File &&
Expand Down
2 changes: 1 addition & 1 deletion src/message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void EmitSemanticHighlighting(DB *db,
std::string_view detailed_name;
lsSymbolKind parent_kind = lsSymbolKind::Unknown;
lsSymbolKind kind = lsSymbolKind::Unknown;
StorageClass storage = SC_None;
uint8_t storage = SC_None;
// This switch statement also filters out symbols that are not highlighted.
switch (sym.kind) {
case SymbolKind::Func: {
Expand Down
2 changes: 1 addition & 1 deletion src/message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct Out_CclsPublishSemanticHighlighting
int stableId = 0;
lsSymbolKind parentKind;
lsSymbolKind kind;
clang::StorageClass storage;
uint8_t storage;
std::vector<std::pair<int, int>> ranges;

// `lsRanges` is used to compute `ranges`.
Expand Down
2 changes: 1 addition & 1 deletion src/messages/ccls_callHierarchy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool Expand(MessageHandler* m,
for (SymbolRef ref : def->callees)
if (ref.kind == SymbolKind::Func)
handle(Use{{ref.range, ref.usr, ref.kind, ref.role},
def->spell->file_id},
def->file_id},
call_type);
} else {
for (Use use : func.uses)
Expand Down
23 changes: 13 additions & 10 deletions src/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IndexFile& indexed) {
template <typename Q>
bool TryReplaceDef(llvm::SmallVectorImpl<Q>& def_list, Q&& def) {
for (auto& def1 : def_list)
if (def1.spell->file_id == def.spell->file_id) {
if (def1.file_id == def.file_id) {
def1 = std::move(def);
return true;
}
Expand All @@ -182,15 +182,15 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
r.funcs_hint = current->usr2func.size() - previous->usr2func.size();
for (auto& it : previous->usr2func) {
auto& func = it.second;
if (func.def.spell)
if (func.def.detailed_name[0])
r.funcs_removed.push_back(func.usr);
r.funcs_declarations[func.usr].first = std::move(func.declarations);
r.funcs_uses[func.usr].first = std::move(func.uses);
r.funcs_derived[func.usr].first = std::move(func.derived);
}
for (auto& it : current->usr2func) {
auto& func = it.second;
if (func.def.spell && func.def.detailed_name[0])
if (func.def.detailed_name[0])
r.funcs_def_update.emplace_back(it.first, func.def);
r.funcs_declarations[func.usr].second = std::move(func.declarations);
r.funcs_uses[func.usr].second = std::move(func.uses);
Expand All @@ -200,7 +200,7 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
r.types_hint = current->usr2type.size() - previous->usr2type.size();
for (auto& it : previous->usr2type) {
auto& type = it.second;
if (type.def.spell)
if (type.def.detailed_name[0])
r.types_removed.push_back(type.usr);
r.types_declarations[type.usr].first = std::move(type.declarations);
r.types_uses[type.usr].first = std::move(type.uses);
Expand All @@ -209,7 +209,7 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
};
for (auto& it : current->usr2type) {
auto& type = it.second;
if (type.def.spell && type.def.detailed_name[0])
if (type.def.detailed_name[0])
r.types_def_update.emplace_back(it.first, type.def);
r.types_declarations[type.usr].second = std::move(type.declarations);
r.types_uses[type.usr].second = std::move(type.uses);
Expand All @@ -220,14 +220,14 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
r.vars_hint = current->usr2var.size() - previous->usr2var.size();
for (auto& it : previous->usr2var) {
auto& var = it.second;
if (var.def.spell)
if (var.def.detailed_name[0])
r.vars_removed.push_back(var.usr);
r.vars_declarations[var.usr].first = std::move(var.declarations);
r.vars_uses[var.usr].first = std::move(var.uses);
}
for (auto& it : current->usr2var) {
auto& var = it.second;
if (var.def.spell && var.def.detailed_name[0])
if (var.def.detailed_name[0])
r.vars_def_update.emplace_back(it.first, var.def);
r.vars_declarations[var.usr].second = std::move(var.declarations);
r.vars_uses[var.usr].second = std::move(var.uses);
Expand All @@ -246,7 +246,7 @@ void DB::RemoveUsrs(SymbolKind kind,
if (!HasFunc(usr)) continue;
QueryFunc& func = Func(usr);
auto it = llvm::find_if(func.def, [=](const QueryFunc::Def& def) {
return def.spell->file_id == file_id;
return def.file_id == file_id;
});
if (it != func.def.end())
func.def.erase(it);
Expand All @@ -259,7 +259,7 @@ void DB::RemoveUsrs(SymbolKind kind,
if (!HasType(usr)) continue;
QueryType& type = Type(usr);
auto it = llvm::find_if(type.def, [=](const QueryType::Def& def) {
return def.spell->file_id == file_id;
return def.file_id == file_id;
});
if (it != type.def.end())
type.def.erase(it);
Expand All @@ -272,7 +272,7 @@ void DB::RemoveUsrs(SymbolKind kind,
if (!HasVar(usr)) continue;
QueryVar& var = Var(usr);
auto it = llvm::find_if(var.def, [=](const QueryVar::Def& def) {
return def.spell->file_id == file_id;
return def.file_id == file_id;
});
if (it != var.def.end())
var.def.erase(it);
Expand Down Expand Up @@ -400,6 +400,7 @@ void DB::Update(const Lid2file_id &lid2file_id, int file_id,
for (auto &u : us) {
auto& def = u.second;
assert(def.detailed_name[0]);
u.second.file_id = file_id;
AssignFileId(lid2file_id, file_id, def.spell);
AssignFileId(lid2file_id, file_id, def.extent);
AssignFileId(lid2file_id, file_id, def.callees);
Expand All @@ -418,6 +419,7 @@ void DB::Update(const Lid2file_id &lid2file_id, int file_id,
for (auto &u : us) {
auto& def = u.second;
assert(def.detailed_name[0]);
u.second.file_id = file_id;
AssignFileId(lid2file_id, file_id, def.spell);
AssignFileId(lid2file_id, file_id, def.extent);
auto R = type_usr.try_emplace({u.first}, type_usr.size());
Expand All @@ -435,6 +437,7 @@ void DB::Update(const Lid2file_id &lid2file_id, int file_id,
for (auto &u : us) {
auto& def = u.second;
assert(def.detailed_name[0]);
u.second.file_id = file_id;
AssignFileId(lid2file_id, file_id, def.spell);
AssignFileId(lid2file_id, file_id, def.extent);
auto R = var_usr.try_emplace({u.first}, var_usr.size());
Expand Down

0 comments on commit 27d641b

Please sign in to comment.