From 459d5c6185245f78010526daea90afc47fc235f6 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Sun, 28 Nov 2021 12:36:51 +0100 Subject: [PATCH] fix pascalabcnet/pascalabcnetide#231 --- CodeCompletion/DomSyntaxTreeVisitor.cs | 49 +++++++++++++++++-- .../ParserTools/DefaultLanguageInformation.cs | 4 +- TestSuite/intellisense_tests/autoclass4.pas | 3 ++ TestSuite/intellisense_tests/tuple2.pas | 3 +- .../TreeConversion/syntax_tree_visitor.cs | 2 +- 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 TestSuite/intellisense_tests/autoclass4.pas diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index b4a9bcc4b..19bc3e575 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -101,7 +101,31 @@ namespace CodeCompletion var id = new ident_with_templateparams(); ntr.Add(new ident(s)); foreach (var gen_td in tn.instance_params) - ttr.params_list.Add(BuildSyntaxNodeForTypeReference(gen_td)); + { + if (gen_td.PrintableName.StartsWith("AnonymousType#")) + { + SymScope tmp = cur_scope; + TypeScope ts = null; + cur_scope = ts = new TypeScope(SymbolKind.Class, cur_scope, null); + tmp.AddName(gen_td.PrintableName, cur_scope); + ts.loc = get_location(gen_td.location); + ts.si = new SymInfo("class", SymbolKind.Class, ""); + foreach (var field in (gen_td as common_type_node).fields) + { + ElementScope es = new ElementScope(); + es.si = new SymInfo(field.name, SymbolKind.Property, ""); + BuildSyntaxNodeForTypeReference(field.type).visit(this); + es.sc = returned_scope; + ts.AddName(field.name, es); + } + returned_scope = cur_scope; + cur_scope = tmp; + ttr.params_list.Add(new named_type_reference(gen_td.PrintableName)); + } + else + ttr.params_list.Add(BuildSyntaxNodeForTypeReference(gen_td)); + } + } } return ttr; @@ -177,7 +201,8 @@ namespace CodeCompletion } else { - if (tn.full_name.IndexOf("$") != -1 || tn.full_name.IndexOf("#") != -1) + + if (tn.full_name.IndexOf("$") != -1 || tn.full_name.IndexOf("#") != -1 && tn.full_name.IndexOf("AnonymousType#") == -1) return ts; if (ts is FileScope && tn.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.typed_file) return ts; @@ -193,6 +218,22 @@ namespace CodeCompletion } } + /*private TypeScope CreateTypeScopeBySemanticType(type_node tn) + { + if (tn is common_generic_instance_type_node) + { + var ts = new TypeScope(); + var gitn = tn as common_generic_instance_type_node; + ts.gener + foreach (var field in gitn.fields) + { + ts.AddName(field.name, CreateTypeScopeBySemanticType(field.type)); + } + } + return null; + }*/ + + private void CorrectVariableType(var_definition_node vdn) { location loc = null; @@ -761,7 +802,7 @@ namespace CodeCompletion } // if (si == null) dn = compiled_type_node.get_type_node(PascalABCCompiler.NetHelper.NetHelper.FindType((_var_def_statement.vars_type as named_type_reference).names[0].name,unl)); - if (returned_scope == null) return; + //if (returned_scope == null) return; if (returned_scope is ProcScope) { returned_scope = new ProcType(returned_scope as ProcScope); @@ -773,6 +814,8 @@ namespace CodeCompletion SymInfo si = new SymInfo(s.name, SymbolKind.Variable, s.name); if (cur_scope is TypeScope) si.kind = SymbolKind.Field; if (_var_def_statement.is_event) si.kind = SymbolKind.Event; + if (returned_scope == null && false) + returned_scope = new UnknownScope(new SymInfo("",SymbolKind.Class, "")); ElementScope es = new ElementScope(si, returned_scope, cur_scope); if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_var_def_statement)) es.AddDocumentation(this.converter.controller.docs[_var_def_statement]); diff --git a/ParserTools/ParserTools/DefaultLanguageInformation.cs b/ParserTools/ParserTools/DefaultLanguageInformation.cs index 98aea72e0..2a86b3516 100644 --- a/ParserTools/ParserTools/DefaultLanguageInformation.cs +++ b/ParserTools/ParserTools/DefaultLanguageInformation.cs @@ -994,7 +994,7 @@ namespace PascalABCCompiler.Parsers if (sc is IProcScope) return ""; if (sc is ITypeScope) { - return sc.Name+(((sc as ITypeScope).TemplateArguments != null && !sc.Name.EndsWith("<>"))?"<>":"")+"."; + return sc.Name+(((sc as ITypeScope).TemplateArguments != null && !sc.Name.EndsWith("<>") && sc.Name != "class")?"<>":"")+"."; } return sc.Name + "."; } @@ -1478,7 +1478,7 @@ namespace PascalABCCompiler.Parsers type_name = type_name.Substring(1, type_name.Length - 1); switch (scope.ElemKind) { - case SymbolKind.Variable: sb.Append("var " + GetTopScopeName(scope.TopScope) + scope.Name + ": " + type_name); break; + case SymbolKind.Variable: sb.Append("var " + GetTopScopeName(scope.TopScope) + scope.Name + ((type_name != "")?": " + type_name:"")); break; case SymbolKind.Parameter: sb.Append(kind_of_param(scope) + "parameter " + scope.Name + ": " + type_name + (scope.ConstantValue != null ? (":=" + scope.ConstantValue.ToString()) : "")); break; case SymbolKind.Constant: { diff --git a/TestSuite/intellisense_tests/autoclass4.pas b/TestSuite/intellisense_tests/autoclass4.pas new file mode 100644 index 000000000..47528dfbe --- /dev/null +++ b/TestSuite/intellisense_tests/autoclass4.pas @@ -0,0 +1,3 @@ +### +var a{@var a: sequence of class;@} := (1..18).Sel(i->new class(f := i, g := i.ToS)); +var x{@var x: string;@} := a.First().g; \ No newline at end of file diff --git a/TestSuite/intellisense_tests/tuple2.pas b/TestSuite/intellisense_tests/tuple2.pas index e71894892..ef20f6b05 100644 --- a/TestSuite/intellisense_tests/tuple2.pas +++ b/TestSuite/intellisense_tests/tuple2.pas @@ -12,5 +12,6 @@ begin var t := f1{@function f1(): (byte,byte);@}; var b{@var b: byte;@} := t.Item1; var t1 := f2; - var i{@@} := t1.Item1; + var i{@var i;@} := t1.Item1; + var j{@var j;@} := i; end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 21fc973f6..aadd56d90 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -17971,7 +17971,7 @@ namespace PascalABCCompiler.TreeConverter || syntax_statement is procedure_call || syntax_statement is raise_statement) { - if (!(new LambdaSearcher(syntax_statement).CheckIfContainsLambdas())) + if (lambdaProcessingState != LambdaProcessingState.TypeInferencePhase && !(new LambdaSearcher(syntax_statement).CheckIfContainsLambdas())) continue; } }