mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-28 14:02:51 +00:00
HackStudio+LanguageServers/Cpp: Show scope of symbols in Locator
This commit is contained in:
parent
6054a418e5
commit
84e34d76d8
Notes:
sideshowbarker
2024-07-18 21:07:23 +09:00
Author: https://github.com/itamar8910
Commit: 84e34d76d8
Pull-request: https://github.com/SerenityOS/serenity/pull/5924
10 changed files with 52 additions and 13 deletions
|
@ -294,8 +294,7 @@ NonnullRefPtrVector<Declaration> ParserAutoComplete::get_global_declarations(con
|
|||
|
||||
for (auto& decl : node.declarations()) {
|
||||
declarations.append(decl);
|
||||
if(decl.is_namespace())
|
||||
{
|
||||
if (decl.is_namespace()) {
|
||||
declarations.append(get_global_declarations(decl));
|
||||
}
|
||||
}
|
||||
|
@ -410,13 +409,12 @@ void ParserAutoComplete::update_declared_symbols(const DocumentData& document)
|
|||
{
|
||||
Vector<GUI::AutocompleteProvider::Declaration> declarations;
|
||||
|
||||
for(auto& decl : get_global_declarations(*document.parser().root_node()))
|
||||
{
|
||||
declarations.append({ decl.name(), { document.filename(), decl.start().line, decl.start().column }, type_of_declaration(decl) });
|
||||
for (auto& decl : get_global_declarations(*document.parser().root_node())) {
|
||||
declarations.append({ decl.name(), { document.filename(), decl.start().line, decl.start().column }, type_of_declaration(decl), scope_of_declaration(decl) });
|
||||
}
|
||||
|
||||
for (auto& definition : document.preprocessor().definitions()) {
|
||||
declarations.append({ definition.key, { document.filename(), definition.value.line, definition.value.column }, GUI::AutocompleteProvider::DeclarationType::PreprocessorDefinition });
|
||||
declarations.append({ definition.key, { document.filename(), definition.value.line, definition.value.column }, GUI::AutocompleteProvider::DeclarationType::PreprocessorDefinition, {} });
|
||||
}
|
||||
|
||||
set_declarations_of_document(document.filename(), move(declarations));
|
||||
|
@ -460,4 +458,27 @@ OwnPtr<ParserAutoComplete::DocumentData> ParserAutoComplete::create_document_dat
|
|||
return document_data;
|
||||
}
|
||||
|
||||
String ParserAutoComplete::scope_of_declaration(const Declaration& decl)
|
||||
{
|
||||
|
||||
auto parent = decl.parent();
|
||||
if (!parent)
|
||||
return {};
|
||||
|
||||
if (!parent->is_declaration())
|
||||
return {};
|
||||
|
||||
auto& parent_decl = static_cast<Declaration&>(*parent);
|
||||
|
||||
if (parent_decl.is_namespace()) {
|
||||
auto& containing_namespace = static_cast<NamespaceDeclaration&>(parent_decl);
|
||||
auto scope_of_parent = scope_of_declaration(parent_decl);
|
||||
if (scope_of_parent.is_null())
|
||||
return containing_namespace.m_name;
|
||||
return String::formatted("{}::{}", scope_of_parent, containing_namespace.m_name);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue