mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:18:12 +00:00
Playground: Autocomplete after empty {}
Enable the oportunity to show name autocompletion after an empty class, which does not have the redundant empty {}.
This commit is contained in:
parent
5c1cd50c9a
commit
76d4b2c5a4
1 changed files with 29 additions and 10 deletions
|
@ -49,6 +49,17 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
|
|||
GUI::GMLToken* last_seen_token { nullptr };
|
||||
|
||||
for (auto& token : all_tokens) {
|
||||
auto handle_class_child = [&] {
|
||||
if (token.m_type == GUI::GMLToken::Type::Identifier) {
|
||||
state = InIdentifier;
|
||||
identifier_string = token.m_view;
|
||||
} else if (token.m_type == GUI::GMLToken::Type::ClassMarker) {
|
||||
previous_states.append(AfterClassName);
|
||||
state = Free;
|
||||
should_push_state = false;
|
||||
}
|
||||
};
|
||||
|
||||
if (token.m_start.line > cursor.line() || (token.m_start.line == cursor.line() && token.m_start.column > cursor.column()))
|
||||
break;
|
||||
|
||||
|
@ -66,24 +77,26 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
|
|||
}
|
||||
break;
|
||||
case InClassName:
|
||||
if (token.m_type != GUI::GMLToken::Type::LeftCurly) {
|
||||
// Close empty class and imediately handle our parent's next child
|
||||
class_names.take_last();
|
||||
state = previous_states.take_last();
|
||||
|
||||
if (state == AfterClassName)
|
||||
handle_class_child();
|
||||
|
||||
break;
|
||||
}
|
||||
state = AfterClassName;
|
||||
break;
|
||||
case AfterClassName:
|
||||
if (token.m_type == GUI::GMLToken::Type::Identifier) {
|
||||
state = InIdentifier;
|
||||
identifier_string = token.m_view;
|
||||
break;
|
||||
}
|
||||
handle_class_child();
|
||||
|
||||
if (token.m_type == GUI::GMLToken::Type::RightCurly) {
|
||||
class_names.take_last();
|
||||
state = previous_states.take_last();
|
||||
break;
|
||||
}
|
||||
if (token.m_type == GUI::GMLToken::Type::ClassMarker) {
|
||||
previous_states.append(AfterClassName);
|
||||
state = Free;
|
||||
should_push_state = false;
|
||||
}
|
||||
break;
|
||||
case InIdentifier:
|
||||
if (token.m_type == GUI::GMLToken::Type::Colon)
|
||||
|
@ -103,6 +116,12 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)>
|
|||
}
|
||||
}
|
||||
|
||||
if (state == InClassName && last_seen_token && last_seen_token->m_end.line < cursor.line()) {
|
||||
// Close empty class
|
||||
class_names.take_last();
|
||||
state = previous_states.take_last();
|
||||
}
|
||||
|
||||
Vector<GUI::AutocompleteProvider::Entry> class_entries, identifier_entries;
|
||||
switch (state) {
|
||||
case Free:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue