Исправления некоторых падений тестов в Intellisense (#3363)

* Fix delegate hints

* Fix extensionmethods8.pas test

* Change InstanceCreationContext GetDescription strategy

* Add keywords treated as functions logic in TestForKeyword function
This commit is contained in:
Александр Земляк 2025-11-29 14:27:33 +03:00 committed by GitHub
parent 4e871c1f3a
commit 770cb4fddb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 40 additions and 28 deletions

View file

@ -2246,8 +2246,9 @@ namespace CodeCompletion
//(ret_tn as TypeScope).name = _type_declaration.type_name.name;
returned_scope.si.name = _type_declaration.type_name.name;
returned_scope.si.description = returned_scope.GetDescription();
if (!(_type_declaration.type_def is class_definition))
returned_scope.MakeSynonimDescription();
// Это мертвый код EVA
//if (!(_type_declaration.type_def is class_definition))
// returned_scope.MakeSynonimDescription();
returned_scope.loc = get_location(_type_declaration);//new location(loc.begin_line_num,loc.begin_column_num,ret_tn.loc.end_line_num,ret_tn.loc.end_column_num,ret_tn.loc.doc);
if (_type_declaration.type_def is class_definition)
{
@ -2317,7 +2318,8 @@ namespace CodeCompletion
cur_scope.AddName(_type_declaration.type_name.name, returned_scope);
if (returned_scope is ProcType)
{
returned_scope.MakeSynonimDescription();
((TypeScope)returned_scope).aliased = true;
returned_scope.BuildDescription();
}
location loc = get_location(_type_declaration);
if (returned_scope.loc == null)

View file

@ -587,11 +587,6 @@ namespace CodeCompletion
return "";
}
public virtual void MakeSynonimDescription()
{
}
public virtual string GetDescriptionWithoutDoc()
{
return si.name;
@ -2608,13 +2603,6 @@ namespace CodeCompletion
return is_constructor;
}
// не используется нигде для ProcScope EVA
public override void MakeSynonimDescription()
{
//aliased = true;
si.description = CodeCompletionController.CurrentParser?.LanguageInformation.GetSynonimDescription(this);
}
//zavershenie opisanija, vyzyvaetsja kogda parametry razobrany
public void Complete()
{
@ -4265,11 +4253,20 @@ namespace CodeCompletion
this.exact = exact;
}
private static string GetDescription(TypeScope t)
{
if (t.Description != null)
return t.Description;
t.BuildDescription();
return t.Description;
}
private struct ScopeComparer : IEqualityComparer<TypeScope>
{
public bool Equals(TypeScope t1, TypeScope t2) => t1.IsEqual(t2);
public int GetHashCode(TypeScope t) => t.GetDescription().GetHashCode();
public int GetHashCode(TypeScope t) => GetDescription(t).GetHashCode();
}
public bool Equals(InstanceCreationContext otherInfo)
@ -4282,8 +4279,8 @@ namespace CodeCompletion
public override int GetHashCode()
{
return string.Join("", genericArguments.Select(arg => arg.si != null ? arg.GetDescription() : "")
.Concat(new string[] { originalType.GetDescription(), exact.ToString() })).GetHashCode();
return string.Join("", genericArguments.Select(arg => arg.si != null ? GetDescription(arg) : "")
.Concat(new string[] { GetDescription(originalType), exact.ToString() })).GetHashCode();
}
}
@ -4817,12 +4814,6 @@ namespace CodeCompletion
implemented_interfaces.Add(type);
}
public override void MakeSynonimDescription()
{
aliased = true;
si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetSynonimDescription(this);
}
public virtual bool IsConvertable(TypeScope ts, bool strong = false)
{
if (IsEqual(ts))
@ -4938,6 +4929,10 @@ namespace CodeCompletion
public override void BuildDescription()
{
si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetDescription(this);
// Случай делегата
if (aliased && this is ProcType)
si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetSynonimDescription(this);
}
//opisanie, vysvechivaetsja v zheltkom okoshke

View file

@ -1703,6 +1703,10 @@ namespace PascalABCCompiler.Parsers
{
keyword = KeywordKind.Raise;
}
else if (KeywordsStorage.KeywordsTreatedAsFunctions.Contains(s))
{
keyword = KeywordKind.None;
}
else if (IsKeyword(s))
{
keyword = KeywordKind.CommonKeyword;

View file

@ -34,6 +34,11 @@ namespace PascalABCCompiler.Parsers
/// </summary>
public List<string> TypeKeywords { get; set; } = new List<string>();
/// <summary>
/// Ключевые слова, которые должны восприниматься как функции при парсинге выражений
/// </summary>
public HashSet<string> KeywordsTreatedAsFunctions { get; set; }
/// <summary>
/// Словарь соответствий ключевых слов их эквивалентам (задается пользователем в специальном файле)
/// </summary>
@ -83,6 +88,8 @@ namespace PascalABCCompiler.Parsers
KeywordsForIntellisenseSet = new HashSet<string>(stringComparer);
KeywordsTreatedAsFunctions = new HashSet<string>(stringComparer);
KeywordKinds = new Dictionary<string, KeywordKind>(stringComparer);
}
@ -102,7 +109,8 @@ namespace PascalABCCompiler.Parsers
return GetIdToken();
}
public void CreateNewKeyword(string name, Enum token = null, KeywordKind kind = KeywordKind.None, bool isTypeKeyword = false, bool excludedInIntellisense = false)
public void CreateNewKeyword(string name, Enum token = null, KeywordKind kind = KeywordKind.None,
bool isTypeKeyword = false, bool excludedInIntellisense = false, bool treatAsFunction = false)
{
name = ConvertKeyword(name);
@ -115,6 +123,9 @@ namespace PascalABCCompiler.Parsers
KeywordsForIntellisenseSet.Add(name);
}
if (treatAsFunction)
KeywordsTreatedAsFunctions.Add(name);
// token null может передаваться, если это ключевое слово исключительно для Intellisense (например, break)
if (token != null)
KeywordsToTokens[name] = (int)(object)token;

View file

@ -26,8 +26,8 @@ namespace Languages.Pascal.Frontend.Core
CreateNewKeyword("is", Tokens.tkIs);
CreateNewKeyword("implicit", Tokens.tkImplicit);
CreateNewKeyword("explicit", Tokens.tkExplicit);
CreateNewKeyword("sizeof", Tokens.tkSizeOf);
CreateNewKeyword("typeof", Tokens.tkTypeOf);
CreateNewKeyword("sizeof", Tokens.tkSizeOf, treatAsFunction: true);
CreateNewKeyword("typeof", Tokens.tkTypeOf, treatAsFunction: true);
CreateNewKeyword("where", Tokens.tkWhere);
CreateNewKeyword("array", Tokens.tkArray, isTypeKeyword: true);
CreateNewKeyword("begin", Tokens.tkBegin);

View file

@ -2,5 +2,5 @@
var ch: char;
var n: integer;
(ch*n).Replace{@function string.Replace(oldChar: char; newChar: char): string;@}(#0,#32);
(2+3).Between{@(расширение) function integer.Between(a: integer; b: integer): boolean;@}(2,3);
(2+3).Between{@(расширение) function integer.Between(a: integer; b: integer; inclusive: boolean:=True): boolean;@}(2,3);
end.