This commit is contained in:
Бондарев Иван 2019-12-25 13:17:32 +01:00
parent b4ec2405a4
commit fa420a349b
7 changed files with 88 additions and 5 deletions

View file

@ -5315,7 +5315,7 @@ namespace CodeCompletion
if (awaitedProcType != null)
{
if (awaitedProcType is TypeSynonim)
awaitedProcType = (awaitedProcType as TypeSynonim).actType;
awaitedProcType = (awaitedProcType as TypeSynonim).GetLeafActType();
if (awaitedProcType is ProcType)
{
if ((awaitedProcType as ProcType).target.parameters.Count > 0)

View file

@ -167,7 +167,7 @@ namespace CodeCompletion
{
if (!((returned_scopes[i] as ProcScope).is_constructor && returned_scopes[i].is_static))
proces.Add(returned_scopes[i] as ProcScope);
}
}
else if (returned_scopes[i] is ElementScope && (returned_scopes[i] as ElementScope).sc is CompiledScope)
{
//ProcType pt = new ProcType();
@ -176,6 +176,28 @@ namespace CodeCompletion
if (ps != null)
proces.Add(ps);
}
else if (returned_scopes[i] is ElementScope && (returned_scopes[i] as ElementScope).sc is TypeSynonim)
{
TypeSynonim ts = (returned_scopes[i] as ElementScope).sc as TypeSynonim;
TypeScope act_ts = ts.GetLeafActType();
ProcType procType =act_ts as ProcType;
if (procType != null)
{
ProcScope tmp = procType.target;
if (tmp != null)
proces.Add(tmp);
}
else
{
CompiledScope cs = act_ts as CompiledScope;
if (cs != null)
{
ProcScope ps = cs.FindNameOnlyInThisType("Invoke") as ProcScope;
if (ps != null)
proces.Add(ps);
}
}
}
else if (i == 0)
return proces;
}
@ -1099,7 +1121,7 @@ namespace CodeCompletion
_method_call.dereferencing_value.visit(this);
search_all = false;
SymScope[] names = returned_scopes.ToArray();
if (names.Length > 0 && names[0] is ElementScope && ((names[0] as ElementScope).sc is ProcType || (names[0] as ElementScope).sc is CompiledScope))
if (names.Length > 0 && names[0] is ElementScope && (names[0] as ElementScope).sc is TypeScope && ((names[0] as ElementScope).sc as TypeScope).IsDelegate)
{
returned_scope = names[0];
return;

View file

@ -3012,6 +3012,13 @@ namespace CodeCompletion
}
}
public TypeScope GetLeafActType(int level=0)
{
if (actType is TypeSynonim && level < 10)
return (actType as TypeSynonim).GetLeafActType(level+1);
return actType;
}
public override SymInfo[] GetNames()
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
@ -3082,6 +3089,14 @@ namespace CodeCompletion
}
}
public override bool IsDelegate
{
get
{
return actType.IsDelegate;
}
}
public override void AddIndexer(TypeScope ts, bool is_static)
{
actType.AddIndexer(ts, is_static);

View file

@ -75,6 +75,23 @@ namespace CodeCompletion
tmp = tmp.Remove(ind, tmp.IndexOf("]}") + 2 - ind);
ind = tmp.IndexOf("{[");
}
ind = tmp.IndexOf("{(");
while (ind != -1)
{
var lines = tmp.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None);
var pos = ind - 1;
var line = GetLineByPos(lines, pos);
var col = GetColByPos(lines, pos);
var desc = CodeCompletion.CodeCompletionTester.GetMethodDescription(pos, tmp, line, col, FileName, dc, comp.ParsersController, 1, 1);
var should_desc = tmp.Substring(ind + 2, tmp.IndexOf(")}") - ind - 2);
if (desc == null)
desc = "";
desc = desc.Split(new string[] { "\n" }, StringSplitOptions.None)[0].Trim();
assert(desc.Replace(", ", ",") == should_desc.Replace(", ", ","), FileName + ", should: " + should_desc + ", is: " + desc);
tmp = tmp.Remove(ind, tmp.IndexOf(")}") + 2 - ind);
ind = tmp.IndexOf("{(");
}
}
}
@ -144,6 +161,25 @@ namespace CodeCompletion
return "";
}
public static string GetMethodDescription(int pos, string content, int line, int col, string FileName, DomConverter dc, PascalABCCompiler.Parsers.Controller controller,
int num_param, int cur_param_num)
{
string expr_without_brackets = null;
PascalABCCompiler.Parsers.KeywordKind keyw;
var expr = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindExpressionFromAnyPosition(pos, content, line, col, out keyw, out expr_without_brackets);
if (expr == null)
expr = expr_without_brackets;
var errors = new List<PascalABCCompiler.Errors.Error>();
var warnings = new List<CompilerWarning>();
var tree = controller.GetExpression("test" + Path.GetExtension(FileName), expr, errors, warnings);
int defaultIndex = 0;
int param_count = 0;
var desc = dc.GetNameOfMethod(tree, expr, line, col, num_param, ref defaultIndex, cur_param_num, out param_count);
if (desc != null && desc.Length > 0)
return desc[0];
return "";
}
private static void assert(bool cond, string message=null)
{
if (message != null)

View file

@ -0,0 +1,9 @@
type
T = byte -> ();
var p: T;
begin
if p <> nil then p{@var p: T;@}(2);
p{(procedure Action<>.Invoke(obj: byte); virtual;)}(2);
end.

View file

@ -1,4 +1,4 @@
function Test(a: integer): integer;
function Test(a: integer): integer;
begin
end;
@ -29,6 +29,7 @@ begin
Test{@function Test(a: string): integer;@}('333');
Test{@function Test(a: boolean): integer;@}(true);
Test{@function Test(a: List<integer>): integer;@}(Lst(2,3,4));
Test{(function Test(a: integer): integer;)};
var delim: array of char;
'aa'.Split{@function string.Split(separator: array of char; options: StringSplitOptions): array of string;@}(delim, System.StringSplitOptions.RemoveEmptyEntries);
end.

View file

@ -1,4 +1,4 @@
function f1<T1, T2, T3>{(a: byte)}: (T1, T2, T3);begin end;
function f1<T1, T2, T3>: (T1, T2, T3);begin end;
function f2<T1, T2, T3>(a: byte): (T1, T2, T3);begin end;
begin
var a{@var a: (byte,word,single);@} := f1&<byte, word, single>;