summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Base/home/anon/Source/little/other.cpp4
-rw-r--r--Base/home/anon/Source/little/other.h5
-rw-r--r--Userland/DevTools/HackStudio/AutoCompleteResponse.h5
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp33
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h1
-rw-r--r--Userland/DevTools/HackStudio/LanguageServers/Shell/AutoComplete.cpp4
-rw-r--r--Userland/DevTools/HackStudio/Locator.cpp9
-rw-r--r--Userland/Libraries/LibCpp/AST.h2
-rw-r--r--Userland/Libraries/LibCpp/Parser.h1
-rw-r--r--Userland/Libraries/LibGUI/AutocompleteProvider.h1
10 files changed, 52 insertions, 13 deletions
diff --git a/Base/home/anon/Source/little/other.cpp b/Base/home/anon/Source/little/other.cpp
index a35a49284a..5569d78eeb 100644
--- a/Base/home/anon/Source/little/other.cpp
+++ b/Base/home/anon/Source/little/other.cpp
@@ -1,6 +1,8 @@
#include "other.h"
#include <stdio.h>
+namespace MyNamespace {
+
int func()
{
int x = 1;
@@ -12,3 +14,5 @@ int func()
printf("x+y: %d\n", x + y);
return x + y;
}
+
+}
diff --git a/Base/home/anon/Source/little/other.h b/Base/home/anon/Source/little/other.h
index 54f64fd686..4acda987e7 100644
--- a/Base/home/anon/Source/little/other.h
+++ b/Base/home/anon/Source/little/other.h
@@ -1,3 +1,6 @@
+
+namespace MyNamespace {
+
int func();
#define USE_VAR2
@@ -12,3 +15,5 @@ struct StructInHeader {
int var3;
#endif
};
+
+}
diff --git a/Userland/DevTools/HackStudio/AutoCompleteResponse.h b/Userland/DevTools/HackStudio/AutoCompleteResponse.h
index 26f2ed45eb..457a0d5890 100644
--- a/Userland/DevTools/HackStudio/AutoCompleteResponse.h
+++ b/Userland/DevTools/HackStudio/AutoCompleteResponse.h
@@ -98,6 +98,7 @@ inline bool encode(Encoder& encoder, const GUI::AutocompleteProvider::Declaratio
if (!encode(encoder, declaration.position))
return false;
encoder << (u32)declaration.type;
+ encoder << declaration.scope;
return true;
}
@@ -109,10 +110,14 @@ inline bool decode(Decoder& decoder, GUI::AutocompleteProvider::Declaration& dec
if (!decode(decoder, declaration.position))
return false;
+
u32 type;
if (!decoder.decode(type))
return false;
+ if (!decoder.decode(declaration.scope))
+ return false;
+
declaration.type = static_cast<GUI::AutocompleteProvider::DeclarationType>(type);
return true;
}
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp
index 228c2f07da..53a58577c9 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp
@@ -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 {};
+}
+
}
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h
index c5dcef52c6..42b22856ea 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h
+++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.h
@@ -107,6 +107,7 @@ private:
String document_path_from_include_path(const StringView& include_path) const;
void update_declared_symbols(const DocumentData&);
GUI::AutocompleteProvider::DeclarationType type_of_declaration(const Declaration&);
+ String scope_of_declaration(const Declaration&);
Optional<GUI::AutocompleteProvider::ProjectLocation> find_preprocessor_definition(const DocumentData&, const GUI::TextPosition&);
OwnPtr<DocumentData> create_document_data(String&& text, const String& filename);
diff --git a/Userland/DevTools/HackStudio/LanguageServers/Shell/AutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Shell/AutoComplete.cpp
index 1302646d79..08da4bbe26 100644
--- a/Userland/DevTools/HackStudio/LanguageServers/Shell/AutoComplete.cpp
+++ b/Userland/DevTools/HackStudio/LanguageServers/Shell/AutoComplete.cpp
@@ -233,7 +233,7 @@ void AutoComplete::update_declared_symbols(const DocumentData& document)
if (!name.is_empty()) {
dbgln("Found variable {}", name);
- declarations.append({ move(name), { filename, entry.name->position().start_line.line_number, entry.name->position().start_line.line_column }, GUI::AutocompleteProvider::DeclarationType::Variable });
+ declarations.append({ move(name), { filename, entry.name->position().start_line.line_number, entry.name->position().start_line.line_column }, GUI::AutocompleteProvider::DeclarationType::Variable, {} });
}
}
::Shell::AST::NodeVisitor::visit(node);
@@ -242,7 +242,7 @@ void AutoComplete::update_declared_symbols(const DocumentData& document)
void visit(const ::Shell::AST::FunctionDeclaration* node) override
{
dbgln("Found function {}", node->name().name);
- declarations.append({ node->name().name, { filename, node->position().start_line.line_number, node->position().start_line.line_column }, GUI::AutocompleteProvider::DeclarationType::Function });
+ declarations.append({ node->name().name, { filename, node->position().start_line.line_number, node->position().start_line.line_column }, GUI::AutocompleteProvider::DeclarationType::Function, {} });
}
const String& filename;
diff --git a/Userland/DevTools/HackStudio/Locator.cpp b/Userland/DevTools/HackStudio/Locator.cpp
index b796b2ddd4..24e8bbdf63 100644
--- a/Userland/DevTools/HackStudio/Locator.cpp
+++ b/Userland/DevTools/HackStudio/Locator.cpp
@@ -77,8 +77,11 @@ public:
return GUI::FileIconProvider::icon_for_path(suggestion.as_filename.value());
}
if (suggestion.is_symbol_declaration()) {
- if (index.column() == Column::Name)
- return suggestion.as_symbol_declaration.value().name;
+ if (index.column() == Column::Name) {
+ if (suggestion.as_symbol_declaration.value().scope.is_null())
+ return suggestion.as_symbol_declaration.value().name;
+ return String::formatted("{}::{}", suggestion.as_symbol_declaration.value().scope, suggestion.as_symbol_declaration.value().name);
+ }
if (index.column() == Column::Filename)
return suggestion.as_symbol_declaration.value().position.file;
if (index.column() == Column::Icon) {
@@ -225,7 +228,7 @@ void Locator::update_suggestions()
for (auto& item : m_document_to_declarations) {
for (auto& decl : item.value) {
- if (decl.name.contains(typed_text, CaseSensitivity::CaseInsensitive))
+ if (decl.name.contains(typed_text, CaseSensitivity::CaseInsensitive) || decl.scope.contains(typed_text, CaseSensitivity::CaseInsensitive))
suggestions.append((LocatorSuggestionModel::Suggestion::create_symbol_declaration(decl)));
}
}
diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h
index 498ca566cb..1fab2109ed 100644
--- a/Userland/Libraries/LibCpp/AST.h
+++ b/Userland/Libraries/LibCpp/AST.h
@@ -75,6 +75,7 @@ public:
virtual bool is_variable_or_parameter_declaration() const { return false; }
virtual bool is_function_call() const { return false; }
virtual bool is_type() const { return false; }
+ virtual bool is_declaration() const { return false; }
protected:
ASTNode(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
@@ -113,7 +114,6 @@ public:
virtual ~Statement() override = default;
virtual const char* class_name() const override { return "Statement"; }
- virtual bool is_declaration() const { return false; }
virtual NonnullRefPtrVector<Declaration> declarations() const override;
protected:
diff --git a/Userland/Libraries/LibCpp/Parser.h b/Userland/Libraries/LibCpp/Parser.h
index 4511e09bda..98f9424f63 100644
--- a/Userland/Libraries/LibCpp/Parser.h
+++ b/Userland/Libraries/LibCpp/Parser.h
@@ -121,7 +121,6 @@ private:
NonnullRefPtrVector<Declaration> parse_declarations_in_translation_unit(ASTNode& parent);
RefPtr<Declaration> parse_single_declaration_in_translation_unit(ASTNode& parent);
-
bool match(Token::Type);
Token consume(Token::Type);
Token consume();
diff --git a/Userland/Libraries/LibGUI/AutocompleteProvider.h b/Userland/Libraries/LibGUI/AutocompleteProvider.h
index 98ae75a89e..8613be538b 100644
--- a/Userland/Libraries/LibGUI/AutocompleteProvider.h
+++ b/Userland/Libraries/LibGUI/AutocompleteProvider.h
@@ -75,6 +75,7 @@ public:
String name;
ProjectLocation position;
DeclarationType type;
+ String scope;
};
virtual void provide_completions(Function<void(Vector<Entry>)>) = 0;