summaryrefslogtreecommitdiff
path: root/modules/gdscript/gd_editor.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-12-21 11:46:28 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-12-21 11:46:28 -0300
commit78e7777cf5ed721b4802066a769b5ecc0c530c3b (patch)
treed2a8f851fd3ec87776b7bddec651d7489533278c /modules/gdscript/gd_editor.cpp
parentf7f197c40941ffaf03fcddeb20536dec8074ca00 (diff)
parente7c1137d927baf6daefa218b48ac1c891cb356ee (diff)
Merge branch 'master' of https://github.com/okamstudio/godot
Conflicts: modules/gdscript/gd_editor.cpp Improved code completion for InputEvent (shows members by type)
Diffstat (limited to 'modules/gdscript/gd_editor.cpp')
-rw-r--r--modules/gdscript/gd_editor.cpp65
1 files changed, 55 insertions, 10 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index f47b147dbf..eb1d0a4db3 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -606,6 +606,16 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser::
if (base.type==Variant::OBJECT) {
+ if (id.operator String()=="new" && base.value.get_type()==Variant::OBJECT) {
+ Object *obj = base.value;
+ if (obj && obj->cast_to<GDNativeClass>()) {
+ GDNativeClass *gdnc = obj->cast_to<GDNativeClass>();
+ r_type.type=Variant::OBJECT;
+ r_type.value=Variant();
+ r_type.obj_type=gdnc->get_name();
+ return true;
+ }
+ }
if (ObjectTypeDB::has_method(base.obj_type,id)) {
@@ -677,7 +687,8 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser::
v.get_method_list(&mi);
for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
- if (E->get().name==id.operator String()) {
+ if (!E->get().name.begins_with("_") && E->get().name==id.operator String()) {
+
MethodInfo mi = E->get();
r_type.type=mi.return_val.type;
@@ -934,7 +945,7 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const
block=block->parent_block;
}
- //TODO guess identifier type of arguments (ONLY if this is a virtual function)
+ //guess from argument if virtual
if (context.function && context.function->name!=StringName()) {
int argindex = -1;
@@ -995,7 +1006,7 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const
}
}
- if (context.function && !context.function->_static) {
+ if (!(context.function && context.function->_static)) {
for(int i=0;i<context._class->variables.size();i++) {
@@ -1136,6 +1147,8 @@ static void _find_identifiers_in_class(GDCompletionContext& context,bool p_stati
List<MethodInfo> methods;
ObjectTypeDB::get_method_list(type,&methods);
for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
+ if (E->get().name.begins_with("_"))
+ continue;
if (E->get().arguments.size())
result.insert(E->get().name+"(");
else
@@ -1196,7 +1209,7 @@ static void _find_identifiers(GDCompletionContext& context,int p_line,bool p_onl
}
-static String _get_visual_datatype(const PropertyInfo& p_info) {
+static String _get_visual_datatype(const PropertyInfo& p_info,bool p_isarg=true) {
String n = p_info.name;
int idx = n.find(":");
@@ -1206,8 +1219,12 @@ static String _get_visual_datatype(const PropertyInfo& p_info) {
if (p_info.type==Variant::OBJECT && p_info.hint==PROPERTY_HINT_RESOURCE_TYPE)
return p_info.hint_string;
- if (p_info.type==Variant::NIL)
- return "void";
+ if (p_info.type==Variant::NIL) {
+ if (p_isarg)
+ return "var";
+ else
+ return "void";
+ }
return Variant::get_type_name(p_info.type);
}
@@ -1297,7 +1314,7 @@ static void _find_type_arguments(const GDParser::Node*p_node,int p_line,const St
}
- arghint = _get_visual_datatype(m->get_argument_info(-1))+" "+p_method.operator String()+String("(");
+ arghint = _get_visual_datatype(m->get_argument_info(-1),false)+" "+p_method.operator String()+String("(");
for(int i=0;i<m->get_argument_count();i++) {
if (i>0)
@@ -1361,7 +1378,7 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No
const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode*>(op->arguments[0]);
MethodInfo mi = GDFunctions::get_info(fn->function);
- arghint = _get_visual_datatype(mi.return_val)+" "+GDFunctions::get_func_name(fn->function)+String("(");
+ arghint = _get_visual_datatype(mi.return_val,false)+" "+GDFunctions::get_func_name(fn->function)+String("(");
for(int i=0;i<mi.arguments.size();i++) {
if (i>0)
arghint+=", ";
@@ -1668,7 +1685,6 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
isfunction=true;
case GDParser::COMPLETION_INDEX: {
- print_line("index");
const GDParser::Node *node = p.get_completion_node();
if (node->type!=GDParser::Node::TYPE_OPERATOR)
break;
@@ -1680,6 +1696,32 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
if (_guess_expression_type(context,static_cast<const GDParser::OperatorNode *>(node)->arguments[0],p.get_completion_line(),t)) {
if (t.type==Variant::OBJECT && t.obj_type!=StringName()) {
+
+
+ if (t.value.get_type()) {
+ Object *obj=t.value;
+ if (obj) {
+ GDScript *scr = obj->cast_to<GDScript>();
+ while (scr) {
+
+ if (!isfunction) {
+ for (const Map<StringName,Variant>::Element *E=scr->get_constants().front();E;E=E->next()) {
+ options.insert(E->key());
+ }
+ }
+ for (const Map<StringName,GDFunction>::Element *E=scr->get_member_functions().front();E;E=E->next()) {
+ options.insert(E->key());
+ }
+
+ if (scr->get_base().is_valid())
+ scr=scr->get_base().ptr();
+ else
+ scr=NULL;
+ }
+ }
+ }
+
+
if (!isfunction) {
ObjectTypeDB::get_integer_constant_list(t.obj_type,r_options);
}
@@ -1687,6 +1729,9 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
ObjectTypeDB::get_method_list(t.obj_type,&mi);
for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
+ if (E->get().name.begins_with("_"))
+ continue;
+
if (E->get().arguments.size())
options.insert(E->get().name+"(");
else
@@ -1695,6 +1740,7 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
}
} else {
+
if (t.type==Variant::INPUT_EVENT) {
//this is hardcoded otherwise it's not obvious
@@ -1775,7 +1821,6 @@ Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base
}
-
} break;
case GDParser::COMPLETION_CALL_ARGUMENTS: {