diff --git a/Base/res/icons/hackstudio/Preprocessor.png b/Base/res/icons/hackstudio/Preprocessor.png new file mode 100644 index 0000000000..45edf08aa1 Binary files /dev/null and b/Base/res/icons/hackstudio/Preprocessor.png differ diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp index 27d936b028..9f6ac5aa49 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/ParserAutoComplete.cpp @@ -163,6 +163,13 @@ Vector ParserAutoComplete::autocomplete_name(c suggestions.append({ name.to_string(), partial_text.length(), GUI::AutocompleteProvider::CompletionKind::Identifier }); } } + + for (auto& preprocessor_name : document.parser().definitions().keys()) { + if (preprocessor_name.starts_with(partial_text)) { + suggestions.append({ preprocessor_name.to_string(), partial_text.length(), GUI::AutocompleteProvider::CompletionKind::PreprocessorDefinition }); + } + } + return suggestions; } @@ -275,9 +282,11 @@ NonnullRefPtrVector ParserAutoComplete::get_declarations_in_outer_s continue; declarations.append(get_declarations_in_outer_scope_including_headers(*included_document)); } + for (auto& decl : document.parser().root_node()->declarations()) { declarations.append(decl); } + return declarations; } @@ -374,6 +383,11 @@ void ParserAutoComplete::update_declared_symbols(const DocumentData& document) for (auto& decl : document.parser().root_node()->declarations()) { declarations.append({ decl.name(), { document.filename(), decl.start().line, decl.start().column }, type_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 }); + } + set_declarations_of_document(document.filename(), move(declarations)); } @@ -403,7 +417,6 @@ OwnPtr ParserAutoComplete::create_document_dat all_definitions.set(move(item.key), move(item.value)); for (auto include : document_data->preprocessor().included_paths()) { - auto included_document = get_or_create_document_data(document_path_from_include_path(include)); if (!included_document) continue; diff --git a/Userland/DevTools/HackStudio/Locator.cpp b/Userland/DevTools/HackStudio/Locator.cpp index 994600eab2..b796b2ddd4 100644 --- a/Userland/DevTools/HackStudio/Locator.cpp +++ b/Userland/DevTools/HackStudio/Locator.cpp @@ -86,6 +86,7 @@ public: static GUI::Icon class_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Class.png")); static GUI::Icon function_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Function.png")); static GUI::Icon variable_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Variable.png")); + static GUI::Icon preprocessor_icon(Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Preprocessor.png")); switch (suggestion.as_symbol_declaration.value().type) { case GUI::AutocompleteProvider::DeclarationType::Struct: return struct_icon; @@ -95,6 +96,8 @@ public: return function_icon; case GUI::AutocompleteProvider::DeclarationType::Variable: return variable_icon; + case GUI::AutocompleteProvider::DeclarationType::PreprocessorDefinition: + return preprocessor_icon; } return {}; } diff --git a/Userland/Libraries/LibCpp/Preprocessor.cpp b/Userland/Libraries/LibCpp/Preprocessor.cpp index 5f4f2c29ae..4d3fc2f82f 100644 --- a/Userland/Libraries/LibCpp/Preprocessor.cpp +++ b/Userland/Libraries/LibCpp/Preprocessor.cpp @@ -105,10 +105,14 @@ void Preprocessor::handle_preprocessor_line(const StringView& line) if (m_state == State::Normal) { auto key = lexer.consume_until(' '); consume_whitespace(); + DefinedValue value; + value.line = m_line_index; + auto string_value = lexer.consume_all(); if (!string_value.is_empty()) value.value = string_value; + m_definitions.set(key, value); } return; diff --git a/Userland/Libraries/LibCpp/Preprocessor.h b/Userland/Libraries/LibCpp/Preprocessor.h index e5702b396a..3ae0d35083 100644 --- a/Userland/Libraries/LibCpp/Preprocessor.h +++ b/Userland/Libraries/LibCpp/Preprocessor.h @@ -43,6 +43,8 @@ public: struct DefinedValue { Optional value; + size_t line {0}; + size_t column {0}; }; using Definitions = HashMap; diff --git a/Userland/Libraries/LibGUI/AutocompleteProvider.h b/Userland/Libraries/LibGUI/AutocompleteProvider.h index 3c7fa4cc76..98ae75a89e 100644 --- a/Userland/Libraries/LibGUI/AutocompleteProvider.h +++ b/Userland/Libraries/LibGUI/AutocompleteProvider.h @@ -42,6 +42,7 @@ public: enum class CompletionKind { Identifier, + PreprocessorDefinition, }; enum class Language { @@ -66,7 +67,8 @@ public: Function, Struct, Class, - Variable + Variable, + PreprocessorDefinition, }; struct Declaration {