From 0b30c64fd61fa2c082686dfb0fe697e37e90bcc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 13 May 2018 14:02:48 +0200 Subject: [PATCH] fix #820 --- CodeCompletion/CodeFormatter.cs | 8 +++- CodeCompletion/DomSyntaxTreeVisitor.cs | 2 +- CodeCompletion/SymTable.cs | 46 +++++++++++----------- TestSuite/intellisense_tests/generics8.pas | 9 +++++ 4 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 TestSuite/intellisense_tests/generics8.pas diff --git a/CodeCompletion/CodeFormatter.cs b/CodeCompletion/CodeFormatter.cs index 0ad41e42e..70f0bb0ec 100644 --- a/CodeCompletion/CodeFormatter.cs +++ b/CodeCompletion/CodeFormatter.cs @@ -1416,12 +1416,16 @@ namespace CodeFormatters sb.Append("unit"); SetKeywordOffset("unit"); } - else + else if (_unit_name.HeaderKeyword == UnitHeaderKeyword.Library) { sb.Append("library"); SetKeywordOffset("library"); } - + else if (_unit_name.HeaderKeyword == UnitHeaderKeyword.Namespace) + { + sb.Append("namespace"); + SetKeywordOffset("namespace"); + } visit_node(_unit_name.idunit_name); //sb.AppendLine(";"); } diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index c3f7fa169..18dadbe70 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -4292,7 +4292,7 @@ namespace CodeCompletion } if (gen_args.Count > 0) - ts = ts.GetInstance(gen_args); + ts = ts.GetInstance(gen_args, true); //ts.MakeInstance(); //ret_tn = ts.GetGenericInstance(gen_args); //ts.si.describe = ts.ToString(); diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index 603fce371..193d7a4d7 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -1728,7 +1728,7 @@ namespace CodeCompletion } } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { return this; } @@ -2308,7 +2308,7 @@ namespace CodeCompletion } } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { return this; } @@ -2396,7 +2396,7 @@ namespace CodeCompletion return this.ToString(); } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { return this; } @@ -2593,7 +2593,7 @@ namespace CodeCompletion return null; } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { return new FileScope(gen_args[0], this.topScope); } @@ -2665,7 +2665,7 @@ namespace CodeCompletion si.description = name + " in " + declScope.si.name; } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { if (gen_args.Count > 0) return gen_args[0]; @@ -2766,12 +2766,12 @@ namespace CodeCompletion return actType.GetIndexers(); } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { TypeScope original_type = actType; if (actType.original_type != null) original_type = actType.original_type; - TypeScope ts = original_type.GetInstance(gen_args); + TypeScope ts = original_type.GetInstance(gen_args, exact); ts.aliased = true; return ts; } @@ -2895,7 +2895,7 @@ namespace CodeCompletion get { return actType.ElementType; } } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { return this; } @@ -3114,7 +3114,7 @@ namespace CodeCompletion return this.ToString(); } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { if ((elementType is UnknownScope || elementType is TemplateParameterScope) && gen_args.Count > 0) return new ArrayScope(gen_args[gen_args.Count-1], Rank > 1?indexes:null); @@ -3329,7 +3329,7 @@ namespace CodeCompletion } } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { return this; } @@ -3511,7 +3511,7 @@ namespace CodeCompletion } } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { return this; } @@ -3910,7 +3910,7 @@ namespace CodeCompletion return ts; } - public virtual TypeScope GetInstance(List gen_args) + public virtual TypeScope GetInstance(List gen_args, bool exact = false) { TypeScope ts = new TypeScope(this.kind, this.topScope, this.baseScope); ts.original_type = this; @@ -3919,18 +3919,18 @@ namespace CodeCompletion for (int i = 0; i < gen_args.Count; i++) { TypeScope gen_arg = gen_args[i]; - if (gen_arg.instances != null && gen_arg.original_type != null) + if (gen_arg.instances != null && gen_arg.original_type != null && !exact) { if (gen_arg.original_type.generic_params != null && this.generic_params != null) - for (int j=0; j < gen_arg.original_type.generic_params.Count; j++) - { - if (string.Compare(gen_arg.original_type.generic_params[j], this.generic_params[j], true) == 0) + for (int j = 0; j < gen_arg.original_type.generic_params.Count; j++) { - new_gen_args.Add(gen_arg.instances[j]); - ts.AddGenericParameter(gen_arg.instances[j].si.name); - ts.AddGenericInstanciation(gen_arg.instances[j]); + if (string.Compare(gen_arg.original_type.generic_params[j], this.generic_params[j], true) == 0) + { + new_gen_args.Add(gen_arg.instances[j]); + ts.AddGenericParameter(gen_arg.instances[j].si.name); + ts.AddGenericInstanciation(gen_arg.instances[j]); + } } - } } else { @@ -5059,7 +5059,7 @@ namespace CodeCompletion } } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { Type t = this.ctn; if (!ctn.IsGenericType) @@ -5085,7 +5085,7 @@ namespace CodeCompletion sc.generic_params = new List(); sc.instances = new List(); sc.original_type = this; - if (this.instances != null && this.instances.Count > 0) + if (this.instances != null && this.instances.Count > 0 && !exact) for (int i = 0; i < this.instances.Count; i++) { if (this.instances[i] is UnknownScope || this.instances[i] is TemplateParameterScope) @@ -7318,7 +7318,7 @@ namespace CodeCompletion return new List(0); } - public override TypeScope GetInstance(List gen_args) + public override TypeScope GetInstance(List gen_args, bool exact = false) { if (gen_args.Count > 0) return gen_args[0]; diff --git a/TestSuite/intellisense_tests/generics8.pas b/TestSuite/intellisense_tests/generics8.pas new file mode 100644 index 000000000..a67f244b5 --- /dev/null +++ b/TestSuite/intellisense_tests/generics8.pas @@ -0,0 +1,9 @@ +type + MyType = class + Variable: T; + end; + +begin + var V{@var V: MyType>;@} := new MyType&(); + var l{@var l: List>;@} := new List(); +end. \ No newline at end of file