From c742d0bf3ece792d173acf8075ce68eb0784bd90 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, 26 Jan 2020 18:24:07 +0100 Subject: [PATCH] fix pascalabcnet/pascalabcnetide#173 --- CodeCompletion/DomSyntaxTreeVisitor.cs | 22 ++++++++++++++++------ CodeCompletion/ExpressionVisitor.cs | 13 ++++++++----- CodeCompletion/SymTable.cs | 19 +++++++++++++++++++ TestSuite/intellisense_tests/property5.pas | 9 +++++++++ 4 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 TestSuite/intellisense_tests/property5.pas diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index 640db83f2..183cfb433 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -436,8 +436,11 @@ namespace CodeCompletion } if (returned_scope is ElementScope) { - cnst_val.prim_val = (returned_scope as ElementScope).cnst_val; - returned_scope = (returned_scope as ElementScope).sc; + ElementScope es = returned_scope as ElementScope; + cnst_val.prim_val = es.cnst_val; + returned_scope = es.sc; + if (es.IsIndexedProperty) + returned_scope = new IndexedPropertyType(es.sc as TypeScope); return; } else @@ -699,7 +702,9 @@ namespace CodeCompletion if (returned_scope != null && returned_scope is TypeScope) { TypeScope ts = returned_scope as TypeScope; - if (ts.GetFullName() != null && (ts.GetFullName().IndexOf("System.Tuple") == 0 || ts.original_type != null && ts.original_type.GetFullName() != null && ts.original_type.GetFullName().IndexOf("(T1,") == 0)) + if (ts is IndexedPropertyType) + returned_scope = (ts as IndexedPropertyType).propertyType; + else if (ts.GetFullName() != null && (ts.GetFullName().IndexOf("System.Tuple") == 0 || ts.original_type != null && ts.original_type.GetFullName() != null && ts.original_type.GetFullName().IndexOf("(T1,") == 0)) { if (_indexer.indexes.expressions[0] is int32_const) { @@ -1220,6 +1225,8 @@ namespace CodeCompletion pr.already_defined = true; pr.loc = cur_loc; pr.head_loc = loc; + if (topScope.ElemKind == SymbolKind.Interface) + pr.si.not_include = true; is_realization = true; entry_scope.AddName("$method", pr); } @@ -2867,7 +2874,7 @@ namespace CodeCompletion if (_method_name.meth_name is operator_name_ident) _method_name.meth_name.visit(this); else - meth_name = _method_name.meth_name.name; + meth_name = _method_name.meth_name.name; } public override void visit(dot_node _dot_node) @@ -2921,8 +2928,11 @@ namespace CodeCompletion } else if (returned_scope is ElementScope) { - this.cnst_val.prim_val = (returned_scope as ElementScope).cnst_val; - returned_scope = (returned_scope as ElementScope).sc; + ElementScope es = returned_scope as ElementScope; + this.cnst_val.prim_val = es.cnst_val; + returned_scope = es.sc; + if (es.IsIndexedProperty) + returned_scope = new IndexedPropertyType(es.sc as TypeScope); return; } else if (returned_scope is TypeScope) diff --git a/CodeCompletion/ExpressionVisitor.cs b/CodeCompletion/ExpressionVisitor.cs index a0d8404ac..28f0e5b16 100644 --- a/CodeCompletion/ExpressionVisitor.cs +++ b/CodeCompletion/ExpressionVisitor.cs @@ -507,15 +507,18 @@ namespace CodeCompletion _indexer.dereferencing_value.visit(this); if (returned_scope != null) { + ElementScope es = returned_scope as ElementScope; if (returned_scope != null) - if (returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcScope && ((returned_scope as ElementScope).sc as ProcScope).return_type != null) - returned_scope = new ElementScope(((returned_scope as ElementScope).sc as ProcScope).return_type.GetElementType()); + if (es != null && es.sc is ProcScope && (es.sc as ProcScope).return_type != null) + returned_scope = new ElementScope((es.sc as ProcScope).return_type.GetElementType()); else if (returned_scope is ProcScope && (returned_scope as ProcScope).is_constructor) returned_scope = new ElementScope((returned_scope as ProcScope).declaringType.GetElementType()); - else if (returned_scope is ElementScope && (returned_scope as ElementScope).sc is TypeScope) + else if (es != null && es.sc is TypeScope) { - TypeScope ts = (returned_scope as ElementScope).sc as TypeScope; - if (ts.GetFullName() != null && (ts.GetFullName().IndexOf("System.Tuple") == 0 || ts.original_type != null && ts.original_type.GetFullName() != null && ts.original_type.GetFullName().IndexOf("(T1,") == 0)) + TypeScope ts = es.sc as TypeScope; + if (es.IsIndexedProperty) + returned_scope = new ElementScope(ts); + else if (ts.GetFullName() != null && (ts.GetFullName().IndexOf("System.Tuple") == 0 || ts.original_type != null && ts.original_type.GetFullName() != null && ts.original_type.GetFullName().IndexOf("(T1,") == 0)) { if (_indexer.indexes.expressions[0] is int32_const) { diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index c9c92a405..89312466a 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -1446,6 +1446,15 @@ namespace CodeCompletion } } + public bool IsIndexedProperty + { + get + { + return this.ElemKind == SymbolKind.Property && indexers != null && indexers.Count > 0; + } + + } + public PascalABCCompiler.SyntaxTree.parametr_kind ParamKind { get @@ -1854,6 +1863,16 @@ namespace CodeCompletion } } + public class IndexedPropertyType : TypeScope + { + public TypeScope propertyType; + + public IndexedPropertyType(TypeScope propertyType) + { + this.propertyType = propertyType; + } + } + public class ProcType : TypeScope, IProcType { public ProcScope target; diff --git a/TestSuite/intellisense_tests/property5.pas b/TestSuite/intellisense_tests/property5.pas new file mode 100644 index 000000000..b7b13e77a --- /dev/null +++ b/TestSuite/intellisense_tests/property5.pas @@ -0,0 +1,9 @@ +type + t1 = class + static property p1[i: integer]: sequence of integer read Arr(0); + end; + +begin + var x{@var x: sequence of integer;@} := t1.p1[0]; + t1.p1[0].Average{@(расширение sequence of T) function Average(): real;@}(); +end. \ No newline at end of file