Skip to content

Commit

Permalink
Support regions without names in Update-Snippets (Azure#15746)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym authored and suhas92 committed Oct 12, 2020
1 parent 08050bd commit bb99786
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions eng/SnippetGenerator/DirectoryProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,19 @@ private List<Snippet> GetSnippetsInDirectory(string baseDirectory)
var list = new List<Snippet>();
foreach (var file in Directory.GetFiles(baseDirectory, "*.cs", SearchOption.AllDirectories))
{
var syntaxTree = CSharpSyntaxTree.ParseText(
File.ReadAllText(file),
new CSharpParseOptions(LanguageVersion.Preview),
path: file);
list.AddRange(GetAllSnippets(syntaxTree));
try
{
var syntaxTree = CSharpSyntaxTree.ParseText(
File.ReadAllText(file),
new CSharpParseOptions(LanguageVersion.Preview),
path: file);

list.AddRange(GetAllSnippets(syntaxTree));
}
catch (Exception e)
{
throw new InvalidOperationException($"Failed to discover snippets from file {file}", e);
}
}

return list;
Expand All @@ -222,7 +230,13 @@ private Snippet[] GetAllSnippets(SyntaxTree syntaxTree)

foreach (var region in directiveWalker.Regions)
{
var syntaxTrivia = region.Item1.EndOfDirectiveToken.LeadingTrivia.First(t => t.IsKind(SyntaxKind.PreprocessingMessageTrivia));
var leadingTrivia = region.Item1.EndOfDirectiveToken.LeadingTrivia;
if (!leadingTrivia.Any())
{
// Skip unnamed regions
continue;
}
var syntaxTrivia = leadingTrivia.First(t => t.IsKind(SyntaxKind.PreprocessingMessageTrivia));
var fromBounds = TextSpan.FromBounds(
region.Item1.GetLocation().SourceSpan.End,
region.Item2.GetLocation().SourceSpan.Start);
Expand Down

0 comments on commit bb99786

Please sign in to comment.