From f699dbdc3f720b3c69083ba91e4214ea76fce6f8 Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Tue, 26 Oct 2021 21:30:48 -0500 Subject: [PATCH] HackStudio+LibGUI: Handle #include quotes and brackets in the engine Previously we had a special case in order to auto-append quotes or angle brackets to #include statements. After the previous commit this is no longer necessary. --- .../LanguageServers/Cpp/CppComprehensionEngine.cpp | 3 ++- Userland/Libraries/LibGUI/AutocompleteProvider.cpp | 14 ++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp index 90cebf4719..0571ce9064 100644 --- a/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp +++ b/Userland/DevTools/HackStudio/LanguageServers/Cpp/CppComprehensionEngine.cpp @@ -670,7 +670,8 @@ Optional> CppComprehensionEngine::try_a if (!(path.ends_with(".h") || Core::File::is_directory(LexicalPath::join(full_dir, path).string()))) continue; if (path.starts_with(partial_basename)) { - options.append({ path, partial_basename.length(), include_type, GUI::AutocompleteProvider::Language::Cpp }); + auto completion = include_type == GUI::AutocompleteProvider::CompletionKind::ProjectInclude ? String::formatted("<{}>", path) : String::formatted("\"{}\"", path); + options.append({ completion, partial_basename.length() + 1, include_type, GUI::AutocompleteProvider::Language::Cpp, path }); } } diff --git a/Userland/Libraries/LibGUI/AutocompleteProvider.cpp b/Userland/Libraries/LibGUI/AutocompleteProvider.cpp index 136108f3c6..08b7538716 100644 --- a/Userland/Libraries/LibGUI/AutocompleteProvider.cpp +++ b/Userland/Libraries/LibGUI/AutocompleteProvider.cpp @@ -181,10 +181,10 @@ void AutocompleteBox::apply_suggestion() return; auto suggestion_index = m_suggestion_view->model()->index(selected_index.row()); - auto suggestion = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Completion).to_string(); + auto completion = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Completion).to_string(); size_t partial_length = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::PartialInputLength).to_i64(); - VERIFY(suggestion.length() >= partial_length); + VERIFY(completion.length() >= partial_length); if (!m_editor->has_selection()) { auto cursor = m_editor->cursor(); VERIFY(m_editor->cursor().column() >= partial_length); @@ -194,16 +194,6 @@ void AutocompleteBox::apply_suggestion() m_editor->delete_text_range(TextRange(start, end)); } - auto completion_kind = (GUI::AutocompleteProvider::CompletionKind)suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Kind).as_u32(); - - String completion; - if (suggestion.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::SystemInclude) - completion = String::formatted("{}{}", suggestion, ">"); - else if (suggestion.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::ProjectInclude) - completion = String::formatted("{}{}", suggestion, "\""); - else - completion = suggestion; - m_editor->insert_at_cursor_or_replace_selection(completion); }