1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

HackStudio: Allow toggling between simple and semantic highlighting

Until it becomes enough stable and performant, semantic highlighting is
disabled by default.

It can be toggled on via the "Project" menu in HackStudio.
This commit is contained in:
Itamar 2022-02-07 08:49:07 +02:00 committed by Andreas Kling
parent 81dcf6c58b
commit 8ec4328fcb
4 changed files with 33 additions and 8 deletions

View file

@ -480,8 +480,8 @@ void Editor::set_document(GUI::TextDocument& doc)
auto& code_document = static_cast<CodeDocument&>(doc);
set_syntax_highlighter_for(code_document);
set_language_client_for(code_document);
set_syntax_highlighter_for(code_document);
if (m_language_client) {
set_autocomplete_provider(make<LanguageServerAidedAutocompleteProvider>(*m_language_client));
@ -500,9 +500,6 @@ void Editor::set_document(GUI::TextDocument& doc)
} else {
set_autocomplete_provider_for(code_document);
}
on_token_info_timer_tick();
m_tokens_info_timer->restart();
}
Optional<Editor::AutoCompleteRequestData> Editor::get_autocomplete_request_data()
@ -609,7 +606,13 @@ void Editor::set_syntax_highlighter_for(const CodeDocument& document)
{
switch (document.language()) {
case Language::Cpp:
if (m_use_semantic_syntax_highlighting) {
set_syntax_highlighter(make<Cpp::SemanticSyntaxHighlighter>());
on_token_info_timer_tick();
m_tokens_info_timer->restart();
} else
set_syntax_highlighter(make<Cpp::SyntaxHighlighter>());
break;
case Language::CSS:
set_syntax_highlighter(make<Web::CSS::SyntaxHighlighter>());
@ -638,6 +641,8 @@ void Editor::set_syntax_highlighter_for(const CodeDocument& document)
default:
set_syntax_highlighter({});
}
force_rehighlight();
}
void Editor::set_autocomplete_provider_for(CodeDocument const& document)
@ -754,4 +759,10 @@ void Editor::create_tokens_info_timer()
m_tokens_info_timer->start();
}
void Editor::set_semantic_syntax_highlighting(bool value)
{
m_use_semantic_syntax_highlighting = value;
set_syntax_highlighter_for(code_document());
}
}

View file

@ -57,6 +57,7 @@ public:
return *m_language_client;
}
virtual void set_cursor(const GUI::TextPosition& a_position) override;
void set_semantic_syntax_highlighting(bool value);
private:
virtual void focusin_event(GUI::FocusEvent&) override;
@ -105,6 +106,8 @@ private:
void on_token_info_timer_tick();
void on_tokens_info_result(Vector<GUI::AutocompleteProvider::TokenInfo> const& tokens_info);
void create_tokens_info_timer();
ErrorOr<void> initialize_documentation_tooltip();
ErrorOr<void> initialize_parameters_hint_tooltip();
explicit Editor();
@ -120,10 +123,8 @@ private:
RefPtr<GUI::Action> m_evaluate_expression_action;
RefPtr<GUI::Action> m_move_execution_to_line_action;
RefPtr<Core::Timer> m_tokens_info_timer; // Used for querying language server for syntax highlighting info
OwnPtr<LanguageClient> m_language_client;
ErrorOr<void> initialize_documentation_tooltip();
ErrorOr<void> initialize_parameters_hint_tooltip();
bool m_use_semantic_syntax_highlighting { false };
};
}

View file

@ -1158,9 +1158,11 @@ void HackStudioWidget::create_project_menu(GUI::Window& window)
for (auto& new_file_action : m_new_file_actions) {
new_submenu.add_action(new_file_action);
}
new_submenu.add_action(*m_new_plain_file_action);
new_submenu.add_separator();
new_submenu.add_action(*m_new_directory_action);
project_menu.add_action(create_toggle_syntax_highlighting_mode_action());
}
void HackStudioWidget::create_edit_menu(GUI::Window& window)
@ -1520,4 +1522,14 @@ void HackStudioWidget::for_each_open_file(Function<void(ProjectFile const&)> fun
}
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_toggle_syntax_highlighting_mode_action()
{
auto action = GUI::Action::create_checkable("&Semantic Highlighting", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-cplusplus.png").release_value_but_fixme_should_propagate_errors(), [this](auto& action) {
for (auto& editor_wrapper : m_all_editor_wrappers)
editor_wrapper.editor().set_semantic_syntax_highlighting(action.is_checked());
});
return action;
}
}

View file

@ -107,6 +107,7 @@ private:
NonnullRefPtr<GUI::Action> create_build_action();
NonnullRefPtr<GUI::Action> create_run_action();
NonnullRefPtr<GUI::Action> create_stop_action();
NonnullRefPtr<GUI::Action> create_toggle_syntax_highlighting_mode_action();
void create_location_history_actions();
void add_new_editor(GUI::Widget& parent);