From 4335bd453d67b21275f598b43e506148b90c7ddf Mon Sep 17 00:00:00 2001 From: Itamar Date: Sun, 27 Feb 2022 19:34:07 +0200 Subject: [PATCH] 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. --- .../LanguageServers/Cpp/CppComprehensionEngine.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp index 32ac408db1..7cf0360d9f 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp @@ -474,11 +474,21 @@ static Optional get_target_declaration(const ASTNode& node) static Optional get_target_declaration(const ASTNode& node, String name) { - if (node.parent() && node.parent()->is_name()) { - if (&node != verify_cast(node.parent())->name()) { + auto& name_node = *verify_cast(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(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())) {