Skip to content

Commit

Permalink
Fix issue in attribute line with attribute class name (#8897)
Browse files Browse the repository at this point in the history
* Fix issue in attribute line with attribute class name
  • Loading branch information
praveenkuttappan authored Aug 28, 2024
1 parent 2afc9d4 commit 5835f21
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CSharpLanguageService : LanguageProcessor
public override string Name { get; } = "C#";
public override string[] Extensions { get; } = { ".dll" };
public override string ProcessName => _csharpParserToolPath;
public override string VersionString { get; } = "29";
public override string VersionString { get; } = "29.1";

public CSharpLanguageService(IConfiguration configuration, TelemetryClient telemetryClient) : base(telemetryClient)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CodeFileBuilder

public ICodeFileBuilderSymbolOrderProvider SymbolOrderProvider { get; set; } = new CodeFileBuilderSymbolOrderProvider();

public const string CurrentVersion = "29";
public const string CurrentVersion = "29.1";

private IEnumerable<INamespaceSymbol> EnumerateNamespaces(IAssemblySymbol assemblySymbol)
{
Expand Down Expand Up @@ -298,9 +298,7 @@ private void BuildType(List<ReviewLine> reviewLines, INamedTypeSymbol namedType,
{
typeToken.NavigationDisplayName = namedType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
typeToken.RenderClasses.Add(namedType.TypeKind.ToString().ToLowerInvariant());
typeToken.HasSuffixSpace = true;
}

if (namedType.TypeKind == TypeKind.Delegate)
{
reviewLine.Tokens.Last().HasSuffixSpace = false;
Expand All @@ -309,6 +307,7 @@ private void BuildType(List<ReviewLine> reviewLines, INamedTypeSymbol namedType,
return;
}

reviewLine.Tokens.Last().HasSuffixSpace = true;
BuildBaseType(reviewLine, namedType);
reviewLine.Tokens.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.OpenBraceToken));
foreach (var namedTypeSymbol in SymbolOrderProvider.OrderTypes(namedType.GetTypeMembers()))
Expand Down Expand Up @@ -517,8 +516,10 @@ private void BuildAttributes(List<ReviewLine> reviewLines, ImmutableArray<Attrib
attributeLine.AddToken(ReviewToken.CreatePunctuationToken(SyntaxKind.EqualsToken));
BuildTypedConstant(attributeLine, argument.Value);
}
attributeLine.Tokens.Last().HasSuffixSpace = false;
attributeLine.AddToken(ReviewToken.CreatePunctuationToken(SyntaxKind.CloseParenToken));
}
attributeLine.Tokens.Last().HasSuffixSpace = false;
attributeLine.AddToken(ReviewToken.CreatePunctuationToken(SyntaxKind.CloseBracketToken));
attributeLine.RelatedToLine = relatedTo;
//Add current attribute line to review lines
Expand Down Expand Up @@ -573,7 +574,7 @@ private void BuildTypedConstant(ReviewLine reviewLine, TypedConstant typedConsta
}
else if (typedConstant.Kind == TypedConstantKind.Array)
{
tokenList.Add(ReviewToken.CreateKeywordToken(SyntaxKind.NewKeyword, false));
tokenList.Add(ReviewToken.CreateKeywordToken(SyntaxKind.NewKeyword));
tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.OpenBracketToken, false));
tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.CloseBracketToken));
tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.OpenBraceToken));
Expand Down Expand Up @@ -826,14 +827,16 @@ protected override void AddSpace()

protected override void AddBitwiseOr()
{
if(_tokenList.Count > 0)
_tokenList.Last().HasSuffixSpace = true;
_tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.BarToken));
}

public override void VisitField(IFieldSymbol symbol)
{
_tokenList.Add(ReviewToken.CreateTypeNameToken(symbol.Type.Name));
_tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.DotToken));
_tokenList.Add(ReviewToken.CreateMemberNameToken(symbol.Name));
_tokenList.Add(ReviewToken.CreateTypeNameToken(symbol.Type.Name, false));
_tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.DotToken, false));
_tokenList.Add(ReviewToken.CreateMemberNameToken(symbol.Name, false));
}

public void Format(ITypeSymbol? type, object? typedConstantValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.42.0" />
<PackageReference Include="Azure.Core.Expressions.DataFactory" Version="1.0.0" />
<PackageReference Include="Azure.Security.Attestation" Version="1.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageReference Include="Azure.Template" Version="1.0.3-beta.4055065" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,25 @@ public void VerifyObsoleteMemberIsHidden()
Assert.True(relatedLine?.IsHidden);
}
}

[Fact]
public void VerifyTemplateClassLine()
{
var coreExprAssembly = Assembly.Load("Azure.Core.Expressions.DataFactory");
var dllStream = coreExprAssembly.GetFile("Azure.Core.Expressions.DataFactory.dll");
var assemblySymbol = CompilationFactory.GetCompilation(dllStream, null);
var codeFile = new CSharpAPIParser.TreeToken.CodeFileBuilder().Build(assemblySymbol, true, null);

var lines = codeFile.ReviewLines;
var namespaceLine = lines.Where(lines => lines.LineId == "Azure.Core.Expressions.DataFactory").FirstOrDefault();
Assert.NotNull(namespaceLine);
var classLine = namespaceLine.Children.Where(lines => lines.LineId.StartsWith("Azure.Core.Expressions.DataFactory.DataFactoryElement")).FirstOrDefault();
Assert.NotNull(classLine);
Assert.Equal("public sealed class DataFactoryElement<T> {", classLine.ToString().Trim());

var methodLine = classLine.Children.Where(lines => lines.LineId == "Azure.Core.Expressions.DataFactory.DataFactoryElement<T>.FromKeyVaultSecret(Azure.Core.Expressions.DataFactory.DataFactoryKeyVaultSecret)").FirstOrDefault();
Assert.NotNull(methodLine);
Assert.Equal("public static DataFactoryElement<string?> FromKeyVaultSecret(DataFactoryKeyVaultSecret secret);", methodLine.ToString().Trim());
}
}
}

0 comments on commit 5835f21

Please sign in to comment.