Skip to content

Commit

Permalink
Fix only attributes can cause refactorings crash (dotnet#37837).
Browse files Browse the repository at this point in the history
  • Loading branch information
petrroll committed Aug 8, 2019
1 parent f42de27 commit a97815e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,22 @@ public class Class1
await TestMissingAsync<MethodDeclarationSyntax>(testText);
}

[Fact]
[WorkItem(37837, "https://github.com/dotnet/roslyn/issues/37837")]
public async Task TestEmptyParameter()
{
var testText = @"
using System;
public class Class1
{
static void foo({|result:[Test][||]
|} {
}
}";
await TestAsync<ParameterSyntax>(testText);
}

[Fact]
[WorkItem(37584, "https://github.com/dotnet/roslyn/issues/37584")]
public async Task TestMissingEmptyMember2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,22 @@ protected TNode TryGetAncestorForLocation<TNode>(int position, SyntaxNode root)

protected int GetStartOfNodeExcludingAttributes(SyntaxNode node)
{
var attributeLists = GetAttributeLists(node);
var start = attributeLists.LastOrDefault()?.GetLastToken().GetNextToken().SpanStart ??
node.SpanStart;
var attributeList = GetAttributeLists(node);
if (attributeList.Any())
{
var endOfAttributeLists = attributeList.Last().Span.End;
var afterAttributesToken = node.FindTokenOnRightOfPosition(endOfAttributeLists);

var endOfNode = node.Span.End;
var startOfTokenAfterAttributes = afterAttributesToken.Span.Start;
var startOfNodeWithoutAttributes = endOfNode >= startOfTokenAfterAttributes
? afterAttributesToken.Span.Start
: endOfNode;

return startOfNodeWithoutAttributes;
}

return start;
return node.SpanStart;
}

public abstract SyntaxList<SyntaxNode> GetAttributeLists(SyntaxNode node);
Expand Down

0 comments on commit a97815e

Please sign in to comment.