diff --git a/CodeCompletion/ExpressionVisitor.cs b/CodeCompletion/ExpressionVisitor.cs index da8059d4b..bfcc9e91c 100644 --- a/CodeCompletion/ExpressionVisitor.cs +++ b/CodeCompletion/ExpressionVisitor.cs @@ -79,7 +79,7 @@ namespace CodeCompletion { returned_scope = null; } - if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcType) + if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcType && expr is method_call) { if (by_dot) if (((returned_scope as ElementScope).sc as ProcType).target.return_type != null) @@ -99,7 +99,7 @@ namespace CodeCompletion else returned_scope = null; } - else if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is CompiledScope && ((returned_scope as ElementScope).sc as CompiledScope).CompiledType.BaseType == typeof(MulticastDelegate)) + else if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is CompiledScope && ((returned_scope as ElementScope).sc as CompiledScope).CompiledType.BaseType == typeof(MulticastDelegate) && expr is method_call) { ProcScope invoke_meth = ((returned_scope as ElementScope).sc as CompiledScope).FindNameOnlyInThisType("Invoke") as ProcScope; if (invoke_meth != null) @@ -351,9 +351,9 @@ namespace CodeCompletion } else if (returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcType && by_dot) { - TypeScope ts = ((returned_scope as ElementScope).sc as ProcType).target.return_type; - if (ts != null) - returned_scope = new ElementScope(ts); + //TypeScope ts = ((returned_scope as ElementScope).sc as ProcType).target.return_type; + //if (ts != null) + // returned_scope = new ElementScope(ts); } if (returned_scope is ElementScope) returned_scope = CheckForAccess(entry_scope, returned_scope as ElementScope); @@ -785,13 +785,14 @@ namespace CodeCompletion else returned_scope = new ElementScope((returned_scope as ProcScope).return_type); } - else if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcType) + else if (returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is ProcType && _dot_node.left is method_call) { TypeScope ts = ((returned_scope as ElementScope).sc as ProcType).target.return_type; if (ts != null) returned_scope = new ElementScope(ts); + } - else if ((returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is CompiledScope)) + else if ((returned_scope != null && returned_scope is ElementScope && (returned_scope as ElementScope).sc is CompiledScope) && _dot_node.left is method_call) { ProcScope invoke_meth = ((returned_scope as ElementScope).sc as CompiledScope).FindNameOnlyInThisType("Invoke") as ProcScope; if (invoke_meth != null) diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index 6ccccc92b..22f1cec04 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -1695,12 +1695,14 @@ namespace CodeCompletion { public ProcScope target; private CompiledScope parent; + private ProcScope invokeMeth; public ProcType(ProcScope target) { this.target = target; this.si = new SymInfo(this.ToString(), SymbolKind.Delegate, this.ToString()); this.parent = TypeTable.get_compiled_type(PascalABCCompiler.NetHelper.NetHelper.MulticastDelegateType); + } public ProcType(ProcScope target, List generic_params):this(target) @@ -1737,20 +1739,59 @@ namespace CodeCompletion } } + public ProcScope InvokeMethod + { + get + { + if (invokeMeth == null) + { + invokeMeth = new ProcScope("Invoke", target); + invokeMeth.declaringType = parent; + invokeMeth.parameters = target.parameters; + invokeMeth.return_type = target.return_type; + invokeMeth.is_virtual = true; + invokeMeth.Complete(); + } + return invokeMeth; + } + } + public override TypeScope GetInstance(List gen_args, bool exact = false) { return this; } + public override List FindOverloadNames(string name) + { + List lst = new List(); + if (string.Compare(name, InvokeMethod.name, true) == 0) + lst.Add(InvokeMethod); + else + lst.AddRange(parent.FindOverloadNames(name)); + return lst; + } + + public override List FindOverloadNamesOnlyInType(string name) + { + List lst = new List(); + if (string.Compare(name, InvokeMethod.name, true) == 0) + lst.Add(InvokeMethod); + else + lst.AddRange(parent.FindOverloadNamesOnlyInType(name)); + return lst; + } + public override SymInfo[] GetNames() { - //SortedDictionary dict = new SortedDictionary(); - return parent.GetNames(); + List lst = new List(); + lst.Add(InvokeMethod.si); + lst.AddRange(parent.GetNames()); + return lst.ToArray(); } public override SymInfo[] GetNames(ExpressionVisitor ev, PascalABCCompiler.Parsers.KeywordKind keyword, bool called_in_base) { - return null; + return parent.GetNames(ev, keyword, called_in_base); } public override string GetDescription() @@ -1770,36 +1811,38 @@ namespace CodeCompletion public override SymInfo[] GetNamesAsInObject() { - //SortedDictionary dict = new SortedDictionary(); - return parent.GetNamesAsInObject(); + List lst = new List(); + lst.Add(InvokeMethod.si); + lst.AddRange(parent.GetNamesAsInObject()); + return lst.ToArray(); } public override SymInfo[] GetNamesAsInObject(ExpressionVisitor ev) { - //SortedDictionary dict = new SortedDictionary(); - return parent.GetNamesAsInObject(ev); + List lst = new List(); + lst.Add(InvokeMethod.si); + lst.AddRange(parent.GetNamesAsInObject(ev)); + return lst.ToArray(); } public override SymScope FindName(string name) { - if (topScope != null) return topScope.FindName(name); - return null; + return topScope.FindName(name); } public override SymScope FindNameInAnyOrder(string name) { - if (topScope != null) return topScope.FindNameInAnyOrder(name); - return null; + return parent.FindNameInAnyOrder(name); } public override SymScope FindNameOnlyInType(string name) { - return null; + return parent.FindNameOnlyInType(name); } public override SymScope FindNameOnlyInThisType(string name) { - return null; + return parent.FindNameOnlyInThisType(name); } public override bool IsConvertable(TypeScope ts) diff --git a/TestSuite/intellisense_tests/delegates2.pas b/TestSuite/intellisense_tests/delegates2.pas new file mode 100644 index 000000000..2bccad719 --- /dev/null +++ b/TestSuite/intellisense_tests/delegates2.pas @@ -0,0 +1,12 @@ +procedure A1(x: procedure) := x.DynamicInvoke{@function Delegate.DynamicInvoke(params args: array of Object): System.Object;@}(); +procedure A2(x: procedure) := x.Invoke{@procedure Invoke(); virtual;@}(); + +function B1(x: function: byte) := x.DynamicInvoke{@function Delegate.DynamicInvoke(params args: array of Object): System.Object;@}(); +function B2(x: function: byte) := x.Invoke{@function Invoke(): byte; virtual;@}(); + +function D1(x: Func0) := x.DynamicInvoke{@function Delegate.DynamicInvoke(params args: array of System.Object): System.Object;@}(); +function D2(x: Func0) := x.Invoke{@function Func<>.Invoke(): byte; virtual;@}(); + +begin + +end. \ No newline at end of file