LanguageServers/Cpp: Make find declaration for a declaration node work

The CppComprehensionEngine can now find the declaration of a
declaration node of type class/namespace/function.
This commit is contained in:
Itamar 2022-02-27 19:34:07 +02:00 committed by Andreas Kling
parent abc420b15a
commit 4335bd453d

View file

@ -474,11 +474,21 @@ static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node)
static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node, String name)
{
if (node.parent() && node.parent()->is_name()) {
if (&node != verify_cast<Name>(node.parent())->name()) {
auto& name_node = *verify_cast<Name>(node.parent());
if (&node != name_node.name()) {
// Node is part of scope reference chain
return TargetDeclaration { TargetDeclaration::Type::Scope, name };
}
if (name_node.parent() && name_node.parent()->is_declaration()) {
auto declaration = verify_cast<Declaration>(name_node.parent());
if (declaration->is_struct_or_class()) {
return TargetDeclaration { TargetDeclaration::Type::Type, name };
}
if (declaration->is_function()) {
return TargetDeclaration { TargetDeclaration::Type::Function, name };
}
}
}
if ((node.parent() && node.parent()->is_function_call()) || (node.parent()->is_name() && node.parent()->parent() && node.parent()->parent()->is_function_call())) {