Skip to content
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

Fix bounds in on header attr #37837 #37838

Merged
merged 4 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,23 @@ public class Class1
await TestMissingAsync<MethodDeclarationSyntax>(testText);
}

[Fact]
[WorkItem(37837, "https://github.com/dotnet/roslyn/issues/37837")]
public async Task TestEmptyParameter()
petrroll marked this conversation as resolved.
Show resolved Hide resolved
{
var testText = @"
using System;
public class TestAttribute : Attribute { }
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 @@ -473,10 +473,7 @@ private static TextSpan GetSpanWithoutAttributes(SyntaxNode node, SyntaxNode roo
var afterAttributesToken = root.FindTokenOnRightOfPosition(endOfAttributeLists);

var endOfNode = node.Span.End;
var startOfTokenAfterAttributes = afterAttributesToken.Span.Start;
var startOfNodeWithoutAttributes = endOfNode >= startOfTokenAfterAttributes
? afterAttributesToken.Span.Start
: endOfNode;
var startOfNodeWithoutAttributes = Math.Min(afterAttributesToken.Span.Start, endOfNode);

return TextSpan.FromBounds(startOfNodeWithoutAttributes, endOfNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,16 @@ 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;
petrroll marked this conversation as resolved.
Show resolved Hide resolved
var afterAttributesToken = node.FindTokenOnRightOfPosition(endOfAttributeLists);

return Math.Min(afterAttributesToken.Span.Start, node.Span.End);
}

return start;
return node.SpanStart;
}

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