mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-23 16:15:07 +00:00
Improve hover and documentSymbol
This commit is contained in:
parent
d2344265f5
commit
e28cd1733f
@ -24,6 +24,11 @@ GetHover(DB *db, LanguageId lang, SymbolRef sym, int file_id) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!def && entity.def.size()) {
|
||||||
|
def = &entity.def[0];
|
||||||
|
if (def->comments[0])
|
||||||
|
comments = def->comments;
|
||||||
|
}
|
||||||
if (def) {
|
if (def) {
|
||||||
lsMarkedString m;
|
lsMarkedString m;
|
||||||
m.language = LanguageIdentifier(lang);
|
m.language = LanguageIdentifier(lang);
|
||||||
|
28
src/query.cc
28
src/query.cc
@ -217,19 +217,17 @@ void DB::ApplyIndexUpdate(IndexUpdate *u) {
|
|||||||
|
|
||||||
// References (Use &use) in this function are important to update file_id.
|
// References (Use &use) in this function are important to update file_id.
|
||||||
auto Ref = [&](std::unordered_map<int, int> &lid2fid, Usr usr,
|
auto Ref = [&](std::unordered_map<int, int> &lid2fid, Usr usr,
|
||||||
SymbolKind kind, Use &use, int delta) {
|
SymbolKind kind, Use &use, int delta, int k = 1) {
|
||||||
use.file_id =
|
use.file_id =
|
||||||
use.file_id == -1 ? u->file_id : lid2fid.find(use.file_id)->second;
|
use.file_id == -1 ? u->file_id : lid2fid.find(use.file_id)->second;
|
||||||
|
if (k & 1) {
|
||||||
int &v =
|
int &v =
|
||||||
files[use.file_id]
|
files[use.file_id]
|
||||||
.symbol2refcnt[SymbolRef{{use.range, usr, kind, use.role}}];
|
.symbol2refcnt[SymbolRef{{use.range, usr, kind, use.role}}];
|
||||||
v += delta;
|
v += delta;
|
||||||
assert(v >= 0);
|
assert(v >= 0);
|
||||||
};
|
}
|
||||||
auto RefO = [&](std::unordered_map<int, int> &lid2fid, Usr usr,
|
if (k & 2)
|
||||||
SymbolKind kind, Use &use, int delta) {
|
|
||||||
use.file_id =
|
|
||||||
use.file_id == -1 ? u->file_id : lid2fid.find(use.file_id)->second;
|
|
||||||
files[use.file_id]
|
files[use.file_id]
|
||||||
.outline2refcnt[SymbolRef{{use.range, usr, kind, use.role}}] += delta;
|
.outline2refcnt[SymbolRef{{use.range, usr, kind, use.role}}] += delta;
|
||||||
};
|
};
|
||||||
@ -283,15 +281,15 @@ void DB::ApplyIndexUpdate(IndexUpdate *u) {
|
|||||||
if (def.spell)
|
if (def.spell)
|
||||||
Ref(prev_lid2file_id, usr, SymbolKind::Func, *def.spell, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Func, *def.spell, -1);
|
||||||
if (def.extent)
|
if (def.extent)
|
||||||
RefO(prev_lid2file_id, usr, SymbolKind::Func, *def.extent, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Func, *def.extent, -1, 2);
|
||||||
}
|
}
|
||||||
RemoveUsrs(SymbolKind::Func, u->file_id, u->funcs_removed);
|
RemoveUsrs(SymbolKind::Func, u->file_id, u->funcs_removed);
|
||||||
Update(lid2file_id, u->file_id, std::move(u->funcs_def_update));
|
Update(lid2file_id, u->file_id, std::move(u->funcs_def_update));
|
||||||
for (auto &[usr, del_add]: u->funcs_declarations) {
|
for (auto &[usr, del_add]: u->funcs_declarations) {
|
||||||
for (Use &use : del_add.first)
|
for (Use &use : del_add.first)
|
||||||
Ref(prev_lid2file_id, usr, SymbolKind::Func, use, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Func, use, -1, 3);
|
||||||
for (Use &use : del_add.second)
|
for (Use &use : del_add.second)
|
||||||
Ref(lid2file_id, usr, SymbolKind::Func, use, 1);
|
Ref(lid2file_id, usr, SymbolKind::Func, use, 1, 3);
|
||||||
}
|
}
|
||||||
REMOVE_ADD(func, declarations);
|
REMOVE_ADD(func, declarations);
|
||||||
REMOVE_ADD(func, derived);
|
REMOVE_ADD(func, derived);
|
||||||
@ -307,15 +305,15 @@ void DB::ApplyIndexUpdate(IndexUpdate *u) {
|
|||||||
if (def.spell)
|
if (def.spell)
|
||||||
Ref(prev_lid2file_id, usr, SymbolKind::Type, *def.spell, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Type, *def.spell, -1);
|
||||||
if (def.extent)
|
if (def.extent)
|
||||||
RefO(prev_lid2file_id, usr, SymbolKind::Type, *def.extent, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Type, *def.extent, -1, 2);
|
||||||
}
|
}
|
||||||
RemoveUsrs(SymbolKind::Type, u->file_id, u->types_removed);
|
RemoveUsrs(SymbolKind::Type, u->file_id, u->types_removed);
|
||||||
Update(lid2file_id, u->file_id, std::move(u->types_def_update));
|
Update(lid2file_id, u->file_id, std::move(u->types_def_update));
|
||||||
for (auto &[usr, del_add]: u->types_declarations) {
|
for (auto &[usr, del_add]: u->types_declarations) {
|
||||||
for (Use &use : del_add.first)
|
for (Use &use : del_add.first)
|
||||||
Ref(prev_lid2file_id, usr, SymbolKind::Type, use, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Type, use, -1, 3);
|
||||||
for (Use &use : del_add.second)
|
for (Use &use : del_add.second)
|
||||||
Ref(lid2file_id, usr, SymbolKind::Type, use, 1);
|
Ref(lid2file_id, usr, SymbolKind::Type, use, 1, 3);
|
||||||
}
|
}
|
||||||
REMOVE_ADD(type, declarations);
|
REMOVE_ADD(type, declarations);
|
||||||
REMOVE_ADD(type, derived);
|
REMOVE_ADD(type, derived);
|
||||||
@ -332,15 +330,15 @@ void DB::ApplyIndexUpdate(IndexUpdate *u) {
|
|||||||
if (def.spell)
|
if (def.spell)
|
||||||
Ref(prev_lid2file_id, usr, SymbolKind::Var, *def.spell, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Var, *def.spell, -1);
|
||||||
if (def.extent)
|
if (def.extent)
|
||||||
RefO(prev_lid2file_id, usr, SymbolKind::Var, *def.extent, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Var, *def.extent, -1, 2);
|
||||||
}
|
}
|
||||||
RemoveUsrs(SymbolKind::Var, u->file_id, u->vars_removed);
|
RemoveUsrs(SymbolKind::Var, u->file_id, u->vars_removed);
|
||||||
Update(lid2file_id, u->file_id, std::move(u->vars_def_update));
|
Update(lid2file_id, u->file_id, std::move(u->vars_def_update));
|
||||||
for (auto &[usr, del_add]: u->vars_declarations) {
|
for (auto &[usr, del_add]: u->vars_declarations) {
|
||||||
for (Use &use : del_add.first)
|
for (Use &use : del_add.first)
|
||||||
Ref(prev_lid2file_id, usr, SymbolKind::Var, use, -1);
|
Ref(prev_lid2file_id, usr, SymbolKind::Var, use, -1, 3);
|
||||||
for (Use &use : del_add.second)
|
for (Use &use : del_add.second)
|
||||||
Ref(lid2file_id, usr, SymbolKind::Var, use, 1);
|
Ref(lid2file_id, usr, SymbolKind::Var, use, 1, 3);
|
||||||
}
|
}
|
||||||
REMOVE_ADD(var, declarations);
|
REMOVE_ADD(var, declarations);
|
||||||
for (auto &[usr, p] : u->vars_uses)
|
for (auto &[usr, p] : u->vars_uses)
|
||||||
|
Loading…
Reference in New Issue
Block a user