mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-16 13:48:04 +00:00
Make $ccls/inheritanceHierarchy and textDocument/typeDefinition find declarations if definitions do not exist; spelling ranges of operator=
This commit is contained in:
parent
c633ce437b
commit
d758b78635
@ -45,7 +45,7 @@ OUTPUT:
|
|||||||
"kind": 6,
|
"kind": 6,
|
||||||
"storage": 0,
|
"storage": 0,
|
||||||
"declarations": [],
|
"declarations": [],
|
||||||
"spell": "2:8-2:16|15041163540773201510|2|1026|-1",
|
"spell": "2:8-2:18|15041163540773201510|2|1026|-1",
|
||||||
"extent": "2:3-2:27|15041163540773201510|2|0|-1",
|
"extent": "2:3-2:27|15041163540773201510|2|0|-1",
|
||||||
"bases": [],
|
"bases": [],
|
||||||
"derived": [],
|
"derived": [],
|
||||||
|
@ -664,6 +664,7 @@ public:
|
|||||||
switch (OrigD->getKind()) {
|
switch (OrigD->getKind()) {
|
||||||
case Decl::CXXConversion: // *operator* int => *operator int*
|
case Decl::CXXConversion: // *operator* int => *operator int*
|
||||||
case Decl::CXXDestructor: // *~*A => *~A*
|
case Decl::CXXDestructor: // *~*A => *~A*
|
||||||
|
case Decl::CXXMethod: // *operator*= => *operator=*
|
||||||
if (Loc.isFileID()) {
|
if (Loc.isFileID()) {
|
||||||
SourceRange R =
|
SourceRange R =
|
||||||
cast<FunctionDecl>(OrigD)->getNameInfo().getSourceRange();
|
cast<FunctionDecl>(OrigD)->getNameInfo().getSourceRange();
|
||||||
|
@ -71,6 +71,9 @@ bool ExpandHelper(MessageHandler *m, Out_CclsInheritanceHierarchy::Entry *entry,
|
|||||||
if (def->spell) {
|
if (def->spell) {
|
||||||
if (auto loc = GetLsLocation(m->db, m->working_files, *def->spell))
|
if (auto loc = GetLsLocation(m->db, m->working_files, *def->spell))
|
||||||
entry->location = *loc;
|
entry->location = *loc;
|
||||||
|
} else if (entity.declarations.size()) {
|
||||||
|
if (auto loc = GetLsLocation(m->db, m->working_files, entity.declarations[0]))
|
||||||
|
entry->location = *loc;
|
||||||
}
|
}
|
||||||
} else if (!derived) {
|
} else if (!derived) {
|
||||||
entry->numChildren = 0;
|
entry->numChildren = 0;
|
||||||
|
@ -30,32 +30,40 @@ struct Handler_TextDocumentTypeDefinition
|
|||||||
QueryFile *file;
|
QueryFile *file;
|
||||||
if (!FindFileOrFail(db, project, request->id,
|
if (!FindFileOrFail(db, project, request->id,
|
||||||
request->params.textDocument.uri.GetPath(), &file,
|
request->params.textDocument.uri.GetPath(), &file,
|
||||||
nullptr)) {
|
nullptr))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
WorkingFile *working_file =
|
WorkingFile *working_file =
|
||||||
working_files->GetFileByFilename(file->def->path);
|
working_files->GetFileByFilename(file->def->path);
|
||||||
|
|
||||||
Out_TextDocumentTypeDefinition out;
|
Out_TextDocumentTypeDefinition out;
|
||||||
out.id = request->id;
|
out.id = request->id;
|
||||||
|
auto Add = [&](const QueryType &type) {
|
||||||
|
for (const auto &def : type.def)
|
||||||
|
if (def.spell) {
|
||||||
|
if (auto ls_loc = GetLsLocationEx(db, working_files, *def.spell,
|
||||||
|
g_config->xref.container))
|
||||||
|
out.result.push_back(*ls_loc);
|
||||||
|
}
|
||||||
|
if (out.result.empty())
|
||||||
|
for (const DeclRef &dr : type.declarations)
|
||||||
|
if (auto ls_loc = GetLsLocationEx(db, working_files, dr,
|
||||||
|
g_config->xref.container))
|
||||||
|
out.result.push_back(*ls_loc);
|
||||||
|
};
|
||||||
for (SymbolRef sym :
|
for (SymbolRef sym :
|
||||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||||
Usr usr = sym.usr;
|
|
||||||
switch (sym.kind) {
|
switch (sym.kind) {
|
||||||
case SymbolKind::Var: {
|
case SymbolKind::Var: {
|
||||||
const QueryVar::Def *def = db->GetVar(sym).AnyDef();
|
const QueryVar::Def *def = db->GetVar(sym).AnyDef();
|
||||||
if (!def || !def->type)
|
if (def && def->type)
|
||||||
continue;
|
Add(db->Type(def->type));
|
||||||
usr = def->type;
|
break;
|
||||||
[[fallthrough]];
|
|
||||||
}
|
}
|
||||||
case SymbolKind::Type: {
|
case SymbolKind::Type: {
|
||||||
QueryType &type = db->Type(usr);
|
for (auto &def : db->GetType(sym).def)
|
||||||
for (const auto &def : type.def)
|
if (def.alias_of) {
|
||||||
if (def.spell) {
|
Add(db->Type(def.alias_of));
|
||||||
if (auto ls_loc = GetLsLocationEx(db, working_files, *def.spell,
|
break;
|
||||||
g_config->xref.container))
|
|
||||||
out.result.push_back(*ls_loc);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user