Getting rid of Advance (part 1)

This commit is contained in:
Ryan Nowak 2016-12-20 10:37:54 -08:00
parent 0d569da92c
commit c088a8871d
1 changed files with 23 additions and 4 deletions

View File

@ -130,13 +130,32 @@ namespace Microsoft.AspNetCore.Razor.Evolution.Legacy
} }
directiveText = directiveText.Trim(); directiveText = directiveText.Trim();
var startOffset = span.Content.IndexOf(directiveText, StringComparison.Ordinal);
var offsetContent = span.Content.Substring(0, startOffset); // If this is the "string literal" form of a directive, we'll need to postprocess the location
var offsetTextLocation = SourceLocation.Advance(span.Start, offsetContent); // and content.
//
// Ex: @addTagHelper "*, Microsoft.AspNetCore.CoolLibrary"
// ^ ^
// Start End
var directiveStart = span.Start;
if (span.Symbols.Count == 1 && (span.Symbols[0] as CSharpSymbol)?.Type == CSharpSymbolType.StringLiteral)
{
var offset = span.Content.IndexOf(directiveText, StringComparison.Ordinal);
// This is safe because inside one of these directives all of the text needs to be on the
// same line.
var original = span.Start;
directiveStart = new SourceLocation(
original.FilePath,
original.AbsoluteIndex + offset,
original.LineIndex,
original.CharacterIndex + offset);
}
var directiveDescriptor = new TagHelperDirectiveDescriptor var directiveDescriptor = new TagHelperDirectiveDescriptor
{ {
DirectiveText = directiveText, DirectiveText = directiveText,
Location = offsetTextLocation, Location = directiveStart,
DirectiveType = directiveType DirectiveType = directiveType
}; };