sort code completions with rules
Fixups Add levenshtein distance for comparisons, remove kind sort order, try to improve as many different use cases as possible Trying again to improve code completion Sort code autocompletion options by similarity based on input To make it really brief, uses a combination `String.similiary`, the category system introduced in a previous PR, and some filtering to yield more predictable results, instead of scattering every completion option at seemingly random. It also gives much higher priority to strings that contain the base in full, closer to the beginning or are perfect matches. Also moves CodeCompletionOptionCompare to code_edit.cpp Co-Authored-By: Micky <66727710+Mickeon@users.noreply.github.com> Co-Authored-By: Eric M <41730826+EricEzaM@users.noreply.github.com>
This commit is contained in:
@@ -37,8 +37,8 @@ class CodeEdit : public TextEdit {
|
||||
GDCLASS(CodeEdit, TextEdit)
|
||||
|
||||
public:
|
||||
/* Keep enum in sync with: */
|
||||
/* /core/object/script_language.h - ScriptLanguage::CodeCompletionKind */
|
||||
// Keep enums in sync with:
|
||||
// core/object/script_language.h - ScriptLanguage::CodeCompletionKind
|
||||
enum CodeCompletionKind {
|
||||
KIND_CLASS,
|
||||
KIND_FUNCTION,
|
||||
@@ -52,6 +52,14 @@ public:
|
||||
KIND_PLAIN_TEXT,
|
||||
};
|
||||
|
||||
// core/object/script_language.h - ScriptLanguage::CodeCompletionLocation
|
||||
enum CodeCompletionLocation {
|
||||
LOCATION_LOCAL = 0,
|
||||
LOCATION_PARENT_MASK = 1 << 8,
|
||||
LOCATION_OTHER_USER_CODE = 1 << 9,
|
||||
LOCATION_OTHER = 1 << 10,
|
||||
};
|
||||
|
||||
private:
|
||||
/* Indent management */
|
||||
int indent_size = 4;
|
||||
@@ -427,7 +435,7 @@ public:
|
||||
|
||||
void request_code_completion(bool p_force = false);
|
||||
|
||||
void add_code_completion_option(CodeCompletionKind p_type, const String &p_display_text, const String &p_insert_text, const Color &p_text_color = Color(1, 1, 1), const Ref<Resource> &p_icon = Ref<Resource>(), const Variant &p_value = Variant::NIL);
|
||||
void add_code_completion_option(CodeCompletionKind p_type, const String &p_display_text, const String &p_insert_text, const Color &p_text_color = Color(1, 1, 1), const Ref<Resource> &p_icon = Ref<Resource>(), const Variant &p_value = Variant::NIL, int p_location = LOCATION_OTHER);
|
||||
void update_code_completion_options(bool p_forced = false);
|
||||
|
||||
TypedArray<Dictionary> get_code_completion_options() const;
|
||||
@@ -456,5 +464,11 @@ public:
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(CodeEdit::CodeCompletionKind);
|
||||
VARIANT_ENUM_CAST(CodeEdit::CodeCompletionLocation);
|
||||
|
||||
// The custom comparer which will sort completion options.
|
||||
struct CodeCompletionOptionCompare {
|
||||
_FORCE_INLINE_ bool operator()(const ScriptLanguage::CodeCompletionOption &l, const ScriptLanguage::CodeCompletionOption &r) const;
|
||||
};
|
||||
|
||||
#endif // CODE_EDIT_H
|
||||
|
||||
Reference in New Issue
Block a user