Skip to content

Commit

Permalink
Make Script Editor's parser execute sooner if errors are known to exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickeon committed Dec 16, 2024
1 parent 893bbdf commit 02cc187
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,9 @@
<member name="text_editor/completion/idle_parse_delay" type="float" setter="" getter="">
The delay in seconds after which the script editor should check for errors when the user stops typing.
</member>
<member name="text_editor/completion/idle_parse_delay_with_errors_found" type="float" setter="" getter="">
The delay used instead of [member text_editor/completion/idle_parse_delay], when the parser has found errors. A lower value should feel more responsive while fixing code, but may cause notable stuttering and increase CPU usage.
</member>
<member name="text_editor/completion/put_callhint_tooltip_below_current_line" type="bool" setter="" getter="">
If [code]true[/code], the code completion tooltip will appear below the current line unless there is no space on screen below the current line. If [code]false[/code], the code completion tooltip will appear above the current line.
</member>
Expand Down
13 changes: 10 additions & 3 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,12 @@ void CodeTextEditor::update_editor_settings() {
text_editor->set_code_hint_draw_below(EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line"));
code_complete_enabled = EDITOR_GET("text_editor/completion/code_complete_enabled");
code_complete_timer->set_wait_time(EDITOR_GET("text_editor/completion/code_complete_delay"));
idle->set_wait_time(EDITOR_GET("text_editor/completion/idle_parse_delay"));
bool first_time = idle_time == 0.0;
idle_time = EDITOR_GET("text_editor/completion/idle_parse_delay");
idle_time_with_errors = EDITOR_GET("text_editor/completion/idle_parse_delay_with_errors_found");
if (first_time) {
idle->set_wait_time(idle_time);
}

// Appearance: Guidelines
if (EDITOR_GET("text_editor/appearance/guidelines/show_line_length_guidelines")) {
Expand Down Expand Up @@ -1624,8 +1629,11 @@ void CodeTextEditor::_notification(int p_what) {
void CodeTextEditor::set_error_count(int p_error_count) {
error_button->set_text(itos(p_error_count));
error_button->set_visible(p_error_count > 0);
if (!p_error_count) {
if (p_error_count > 0) {
_set_show_errors_panel(false);
idle->set_wait_time(idle_time_with_errors); // Parsing should happen sooner.
} else {
idle->set_wait_time(idle_time);
}
}

Expand Down Expand Up @@ -1797,7 +1805,6 @@ CodeTextEditor::CodeTextEditor() {
add_child(status_bar);
status_bar->set_h_size_flags(SIZE_EXPAND_FILL);
status_bar->set_custom_minimum_size(Size2(0, 24 * EDSCALE)); // Adjust for the height of the warning icon.

idle = memnew(Timer);
add_child(idle);
idle->set_one_shot(true);
Expand Down
2 changes: 2 additions & 0 deletions editor/code_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ class CodeTextEditor : public VBoxContainer {

Label *info = nullptr;
Timer *idle = nullptr;
float idle_time = 0.0f;
float idle_time_with_errors = 0.0f;
bool code_complete_enabled = true;
Timer *code_complete_timer = nullptr;
int code_complete_timer_line = 0;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {

// Completion
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay", 1.5, "0.1,10,0.01")
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/idle_parse_delay_with_errors_found", 0.5, "0.1,5,0.01")
_initial_set("text_editor/completion/auto_brace_complete", true, true);
_initial_set("text_editor/completion/code_complete_enabled", true, true);
EDITOR_SETTING(Variant::FLOAT, PROPERTY_HINT_RANGE, "text_editor/completion/code_complete_delay", 0.3, "0.01,5,0.01,or_greater")
Expand Down

0 comments on commit 02cc187

Please sign in to comment.