Skip to content

Commit a6db8aa

Browse files
committed
Merge pull request godotengine#111597 from HolonProduction/code-edit-dirty-flag
CodeEdit: Use flag to recalculate characteristics
2 parents 2ab796b + f6ff221 commit a6db8aa

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

core/object/script_language.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,13 @@ TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics
617617
// Return characteristics of the match found by order of importance.
618618
// Matches will be ranked by a lexicographical order on the vector returned by this function.
619619
// The lower values indicate better matches and that they should go before in the order of appearance.
620-
if (last_matches == matches) {
620+
if (!matches_dirty) {
621621
return charac;
622622
}
623623
charac.clear();
624624
// Ensure base is not empty and at the same time that matches is not empty too.
625625
if (p_base.length() == 0) {
626-
last_matches = matches;
626+
matches_dirty = false;
627627
charac.push_back(location);
628628
return charac;
629629
}
@@ -642,7 +642,7 @@ TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_characteristics
642642
charac.push_back(bad_case);
643643
charac.push_back(location);
644644
charac.push_back(matches[0].first);
645-
last_matches = matches;
645+
matches_dirty = false;
646646
return charac;
647647
}
648648

@@ -652,7 +652,7 @@ void ScriptLanguage::CodeCompletionOption::clear_characteristics() {
652652

653653
TypedArray<int> ScriptLanguage::CodeCompletionOption::get_option_cached_characteristics() const {
654654
// Only returns the cached value and warns if it was not updated since the last change of matches.
655-
if (last_matches != matches) {
655+
if (matches_dirty) {
656656
WARN_PRINT("Characteristics are not up to date.");
657657
}
658658

core/object/script_language.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class ScriptLanguage : public Object {
315315
Ref<Resource> icon;
316316
Variant default_value;
317317
Vector<Pair<int, int>> matches;
318-
Vector<Pair<int, int>> last_matches = { { -1, -1 } }; // This value correspond to an impossible match
318+
bool matches_dirty = true; // Must be set when mutating `matches`, so that sorting characteristics are recalculated.
319319
int location = LOCATION_OTHER;
320320
String theme_color_name;
321321

core/object/script_language_extension.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class ScriptLanguageExtension : public ScriptLanguage {
427427
option.matches.push_back(Pair<int, int>(matches[j], matches[j + 1]));
428428
}
429429
}
430+
option.matches_dirty = true;
430431
r_options->push_back(option);
431432
}
432433
}

scene/gui/code_edit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() {
36723672

36733673
for (ScriptLanguage::CodeCompletionOption &option : code_completion_option_sources) {
36743674
option.matches.clear();
3675+
option.matches_dirty = true;
36753676
if (single_quote && option.display.is_quoted()) {
36763677
option.display = option.display.unquote().quote("'");
36773678
}
@@ -3757,6 +3758,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() {
37573758
// go through all possible matches to get the best one as defined by CodeCompletionOptionCompare
37583759
if (all_possible_subsequence_matches.size() > 0) {
37593760
option.matches = all_possible_subsequence_matches[0];
3761+
option.matches_dirty = true;
37603762
option.get_option_characteristics(string_to_complete);
37613763
all_possible_subsequence_matches = all_possible_subsequence_matches.slice(1);
37623764
if (all_possible_subsequence_matches.size() > 0) {
@@ -3765,6 +3767,7 @@ void CodeEdit::_filter_code_completion_candidates_impl() {
37653767
compared_option.clear_characteristics();
37663768
for (Vector<Pair<int, int>> &matches : all_possible_subsequence_matches) {
37673769
compared_option.matches = matches;
3770+
compared_option.matches_dirty = true;
37683771
compared_option.get_option_characteristics(string_to_complete);
37693772
if (compare(compared_option, option)) {
37703773
option = compared_option;

0 commit comments

Comments
 (0)