1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

CppLanguageServer+LibGUI: Autocomplete #include paths

The C++ language-server can now autocomplete include paths.

Paths that start with '<' will be searched in /usr/include, and paths
that start with '"' will be searched in the project's root directory.
This commit is contained in:
Itamar 2021-05-22 11:27:54 +03:00 committed by Andreas Kling
parent ccd491594f
commit c003c3c76d
4 changed files with 64 additions and 1 deletions

View file

@ -176,7 +176,17 @@ void AutocompleteBox::apply_suggestion()
size_t partial_length = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::PartialInputLength).to_i64();
VERIFY(suggestion.length() >= partial_length);
auto completion = suggestion.substring_view(partial_length, suggestion.length() - partial_length);
auto completion_view = suggestion.substring_view(partial_length, suggestion.length() - partial_length);
auto completion_kind = (GUI::AutocompleteProvider::CompletionKind)suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Kind).as_uint();
String completion;
if (completion_view.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::SystemInclude)
completion = String::formatted("{}{}", completion_view, ">");
else if (completion_view.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::ProjectInclude)
completion = String::formatted("{}{}", completion_view, "\"");
else
completion = completion_view;
m_editor->insert_at_cursor_or_replace_selection(completion);
}