New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Snippet Generator as a tool to be published, update dotnet.yml to… #1834
Merged
chidozieononiwu
merged 7 commits into
Azure:main
from
chidozieononiwu:AddSnippetGenerator
Jul 24, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
09f8821
Add Snippet Generator as a tool to be published, update dotnet.yml to…
chidozieononiwu 807534a
Update dotnet.yml
chidozieononiwu 0c2d1a5
update dotnet.yml
chidozieononiwu 6a50a5e
update dotnet.yml pipeline
chidozieononiwu eeadc47
Update Azure.ClientSdk.Analyzer to net5.0
chidozieononiwu f5e20a4
Update dotnet.yml ci triggers
chidozieononiwu 90987e5
Remove ItemGroup that removes SnippetGenerator Test
chidozieononiwu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<Project Sdk="Microsoft.Build.Traversal"> | ||
<ItemGroup> | ||
<ProjectReference | ||
Include="src\dotnet\Azure.ClientSdk.Analyzers\**\*.csproj"/> | ||
<ProjectReference Include="src\dotnet\Azure.ClientSdk.Analyzers\**\*.csproj" /> | ||
</ItemGroup> | ||
</Project> |
2 changes: 1 addition & 1 deletion
2
...lientSdk.Analyzers/Azure.ClientSdk.Analyzers.Tests/Azure.ClientSdk.Analyzers.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tnet/Azure.ClientSdk.Analyzers/Azure.ClientSdk.Analyzers/Azure.ClientSdk.Analyzers.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<TargetFramework>net5.0</TargetFramework> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we intend to change this to net5? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Praveen is fixing this up with another PR. |
||
<BuildOutputTargetFolder>analyzers/dotnet/cs/</BuildOutputTargetFolder> | ||
<VersionPrefix>0.1.1</VersionPrefix> | ||
<LangVersion>8</LangVersion> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Security; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace SnippetGenerator | ||
{ | ||
public class CSharpProcessor | ||
{ | ||
private static readonly string _snippetFormat = "{3} <code snippet=\"{0}\" language=\"csharp\">{1}{2} </code>"; | ||
private static readonly string _snippetExampleFormat = "{3} <example snippet=\"{0}\">{1}{3} <code language=\"csharp\">{1}{2} </code>{1}{3} </example>"; | ||
|
||
private static readonly Regex _snippetRegex = new Regex("^(?<indent>\\s*)\\/{3}\\s*<code snippet=\"(?<name>[\\w:]+)\"[^>]*?>.*?\\s*<\\/code>", | ||
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
|
||
private static readonly Regex _snippetExampleRegex = new Regex("^(?<indent>\\s*)\\/{3}\\s*<example snippet=\"(?<name>[\\w:]+)\">.*?\\s*<\\/example>", | ||
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase); | ||
|
||
public static async ValueTask<string> ProcessAsync(string markdown, Func<string, ValueTask<string>> snippetProvider) | ||
{ | ||
async ValueTask<string> CodeTagFormatter(Match match) | ||
{ | ||
return await BuildResult(snippetProvider, match, _snippetFormat); | ||
} | ||
|
||
async ValueTask<string> ExampleTagFormatter(Match match) | ||
{ | ||
return await BuildResult(snippetProvider, match, _snippetExampleFormat); | ||
} | ||
|
||
string result = await _snippetRegex.ReplaceAsync(markdown, CodeTagFormatter); | ||
return result != markdown ? result : await _snippetExampleRegex.ReplaceAsync(markdown, ExampleTagFormatter); | ||
} | ||
|
||
private static async ValueTask<string> BuildResult(Func<string, ValueTask<string>> snippetProvider, Match match, string format) | ||
{ | ||
var name = match.Groups["name"].Value; | ||
var prefix = match.Groups["indent"].Value + "///"; | ||
|
||
var snippetText = await snippetProvider(name); | ||
|
||
var builder = new StringBuilder(); | ||
foreach (var line in snippetText.Split(Environment.NewLine)) | ||
{ | ||
builder.Append(prefix); | ||
if (!string.IsNullOrWhiteSpace(line)) | ||
{ | ||
builder.Append(" "); | ||
} | ||
|
||
builder.AppendLine(SecurityElement.Escape(line)); | ||
} | ||
|
||
if (builder.Length > 0) | ||
{ | ||
builder.Length -= Environment.NewLine.Length; | ||
} | ||
|
||
return string.Format(format, name, Environment.NewLine, builder, prefix); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think /* is doing what you expect as devops doesn't support wildcards in the paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. Will
src/dotnet
work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I believe it should work without the *