mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-31 13:41:03 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									fb10f45efe
								
							
						
					
					
						commit
						006e899bb3
					
				
					 11 changed files with 291 additions and 202 deletions
				
			
		|  | @ -906,19 +906,20 @@ static void _list_available_types(bool p_inherit_only, GDScriptParser::Completio | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| static void _find_identifiers_in_suite(const GDScriptParser::SuiteNode *p_suite, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_result) { | ||||
| static void _find_identifiers_in_suite(const GDScriptParser::SuiteNode *p_suite, HashMap<String, ScriptLanguage::CodeCompletionOption> &r_result, int p_recursion_depth = 0) { | ||||
| 	for (int i = 0; i < p_suite->locals.size(); i++) { | ||||
| 		ScriptLanguage::CodeCompletionOption option; | ||||
| 		int location = p_recursion_depth == 0 ? ScriptLanguage::LOCATION_LOCAL : (p_recursion_depth | ScriptLanguage::LOCATION_PARENT_MASK); | ||||
| 		if (p_suite->locals[i].type == GDScriptParser::SuiteNode::Local::CONSTANT) { | ||||
| 			option = ScriptLanguage::CodeCompletionOption(p_suite->locals[i].name, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, ScriptLanguage::LOCATION_LOCAL); | ||||
| 			option = ScriptLanguage::CodeCompletionOption(p_suite->locals[i].name, ScriptLanguage::CODE_COMPLETION_KIND_CONSTANT, location); | ||||
| 			option.default_value = p_suite->locals[i].constant->initializer->reduced_value; | ||||
| 		} else { | ||||
| 			option = ScriptLanguage::CodeCompletionOption(p_suite->locals[i].name, ScriptLanguage::CODE_COMPLETION_KIND_VARIABLE, ScriptLanguage::LOCATION_LOCAL); | ||||
| 			option = ScriptLanguage::CodeCompletionOption(p_suite->locals[i].name, ScriptLanguage::CODE_COMPLETION_KIND_VARIABLE, location); | ||||
| 		} | ||||
| 		r_result.insert(option.display, option); | ||||
| 	} | ||||
| 	if (p_suite->parent_block) { | ||||
| 		_find_identifiers_in_suite(p_suite->parent_block, r_result); | ||||
| 		_find_identifiers_in_suite(p_suite->parent_block, r_result, p_recursion_depth + 1); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -933,7 +934,7 @@ static void _find_identifiers_in_class(const GDScriptParser::ClassNode *p_class, | |||
| 		int classes_processed = 0; | ||||
| 		while (clss) { | ||||
| 			for (int i = 0; i < clss->members.size(); i++) { | ||||
| 				const int location = (classes_processed + p_recursion_depth) | ScriptLanguage::LOCATION_PARENT_MASK; | ||||
| 				const int location = p_recursion_depth == 0 ? classes_processed : (p_recursion_depth | ScriptLanguage::LOCATION_PARENT_MASK); | ||||
| 				const GDScriptParser::ClassNode::Member &member = clss->members[i]; | ||||
| 				ScriptLanguage::CodeCompletionOption option; | ||||
| 				switch (member.type) { | ||||
|  | @ -1025,7 +1026,7 @@ static void _find_identifiers_in_base(const GDScriptCompletionIdentifier &p_base | |||
| 	while (!base_type.has_no_type()) { | ||||
| 		switch (base_type.kind) { | ||||
| 			case GDScriptParser::DataType::CLASS: { | ||||
| 				_find_identifiers_in_class(base_type.class_type, p_only_functions, base_type.is_meta_type, false, r_result, p_recursion_depth + 1); | ||||
| 				_find_identifiers_in_class(base_type.class_type, p_only_functions, base_type.is_meta_type, false, r_result, p_recursion_depth); | ||||
| 				// This already finds all parent identifiers, so we are done.
 | ||||
| 				base_type = GDScriptParser::DataType(); | ||||
| 			} break; | ||||
|  | @ -1205,7 +1206,7 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context | |||
| 	} | ||||
| 
 | ||||
| 	if (p_context.current_class) { | ||||
| 		_find_identifiers_in_class(p_context.current_class, p_only_functions, (!p_context.current_function || p_context.current_function->is_static), false, r_result, p_recursion_depth + 1); | ||||
| 		_find_identifiers_in_class(p_context.current_class, p_only_functions, (!p_context.current_function || p_context.current_function->is_static), false, r_result, p_recursion_depth); | ||||
| 	} | ||||
| 
 | ||||
| 	List<StringName> functions; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 ajreckof
						ajreckof