Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -195,15 +195,15 @@ private void ConvertToUnresolvedDirectiveAttribute(
var directiveNameSpan = nameSpan;
if (directiveNameSpan is SourceSpan ns && attributeName.StartsWith('@'))
{
directiveNameSpan = new SourceSpan(ns.FilePath, ns.AbsoluteIndex + 1, ns.LineIndex, ns.CharacterIndex + 1, ns.Length - 1, ns.LineCount, ns.EndCharacterIndex);
directiveNameSpan = ns.WithAbsoluteIndex(ns.AbsoluteIndex + 1).WithCharacterIndex(ns.CharacterIndex + 1).WithLength(ns.Length - 1);
Comment thread
chsienki marked this conversation as resolved.
Outdated
}

// Strip parameter suffix from OriginalAttributeSpan for parameter matches
var parameterOriginalSpan = directiveNameSpan;
if (match.IsParameterMatch && directiveAttributeName.HasParameter && parameterOriginalSpan is SourceSpan ps)
{
var nameWithoutParamLen = directiveAttributeName.TextWithoutParameter.Length;
parameterOriginalSpan = new SourceSpan(ps.FilePath, ps.AbsoluteIndex, ps.LineIndex, ps.CharacterIndex, nameWithoutParamLen, ps.LineCount, ps.CharacterIndex + nameWithoutParamLen);
parameterOriginalSpan = ps.WithLength(nameWithoutParamLen).WithEndCharacterIndex(ps.CharacterIndex + nameWithoutParamLen);
}

IntermediateNode directiveNode = match.IsParameterMatch && directiveAttributeName.HasParameter
Expand Down Expand Up @@ -581,14 +581,7 @@ private static void MergeAdjacentCSharpTokens(IntermediateNode node)
if (firstSpan is { } first && lastSpan is { } last)
{
var endAbsolute = last.AbsoluteIndex + last.Length;
mergedSpan = new SourceSpan(
first.FilePath,
first.AbsoluteIndex,
first.LineIndex,
first.CharacterIndex,
endAbsolute - first.AbsoluteIndex,
last.LineIndex - first.LineIndex + 1,
last.EndCharacterIndex);
mergedSpan = first.WithLength(endAbsolute - first.AbsoluteIndex).WithLineCount(last.LineIndex - first.LineIndex + 1).WithEndCharacterIndex(last.EndCharacterIndex);
}

var content = sb.ToString();
Expand Down Expand Up @@ -877,14 +870,7 @@ private static void ConvertComponentAttributeToTagHelper(
var directiveNameSpan = attributeNameSpan;
if (directiveNameSpan is SourceSpan nameSpan && attributeName.StartsWith('@'))
{
directiveNameSpan = new SourceSpan(
nameSpan.FilePath,
nameSpan.AbsoluteIndex + 1,
nameSpan.LineIndex,
nameSpan.CharacterIndex + 1,
nameSpan.Length - 1,
nameSpan.LineCount,
nameSpan.EndCharacterIndex);
directiveNameSpan = nameSpan.WithAbsoluteIndex(nameSpan.AbsoluteIndex + 1).WithCharacterIndex(nameSpan.CharacterIndex + 1).WithLength(nameSpan.Length - 1);
}

IntermediateNode directiveNode = match.IsParameterMatch && directiveAttributeName.HasParameter
Expand Down Expand Up @@ -991,7 +977,7 @@ private static void CopyAsTagHelperAttributeValues(HtmlAttributeIntermediateNode
var totalLength = source.Children[^1] is HtmlAttributeValueIntermediateNode lastValue && lastValue.Source is { } ls
? (ls.AbsoluteIndex + ls.Length) - fs.AbsoluteIndex
: mergedText.Length;
spanSource = new SourceSpan(fs.FilePath, fs.AbsoluteIndex, fs.LineIndex, fs.CharacterIndex, totalLength, fs.LineCount, fs.EndCharacterIndex);
spanSource = fs.WithLength(totalLength);
}

mergedContent.Source = spanSource;
Expand Down Expand Up @@ -1052,14 +1038,7 @@ private static void CopyAsTagHelperAttributeValues(HtmlAttributeIntermediateNode

var nameCharIndex = attrSource.CharacterIndex + nameIndex;

return new SourceSpan(
attrSource.FilePath,
attrSource.AbsoluteIndex + nameIndex,
attrSource.LineIndex,
nameCharIndex,
nameLength,
0,
nameCharIndex + nameLength);
return attrSource.WithAbsoluteIndex(attrSource.AbsoluteIndex + nameIndex).WithCharacterIndex(nameCharIndex).WithLength(nameLength).WithLineCount(0).WithEndCharacterIndex(nameCharIndex + nameLength);
}

private static SourceSpan? ComputeAttributeValueSpan(HtmlAttributeIntermediateNode htmlAttr)
Expand All @@ -1080,16 +1059,11 @@ private static void CopyAsTagHelperAttributeValues(HtmlAttributeIntermediateNode
var endIndex = lastSource.AbsoluteIndex + lastSource.Length;
var length = endIndex - childSource.AbsoluteIndex;
var endCharIndex = lastSource.CharacterIndex + lastSource.Length;
return new SourceSpan(
childSource.FilePath,
childSource.AbsoluteIndex,
childSource.LineIndex,
childSource.CharacterIndex,
length,
return childSource.WithLength(length)
// Note: does not incorporate lastSource.LineCount; attribute values
// spanning multiple lines are uncommon and the old pipeline had the same limitation.
lastSource.LineIndex - childSource.LineIndex,
endCharIndex);
.WithLineCount(lastSource.LineIndex - childSource.LineIndex)
.WithEndCharacterIndex(endCharIndex);
}

return childSource;
Expand All @@ -1113,14 +1087,7 @@ private static void CopyAsTagHelperAttributeValues(HtmlAttributeIntermediateNode

var valueCharIndex = attrSource.CharacterIndex + valueStart;

return new SourceSpan(
attrSource.FilePath,
attrSource.AbsoluteIndex + valueStart,
attrSource.LineIndex,
valueCharIndex,
valueLength,
0,
valueCharIndex + valueLength);
return attrSource.WithAbsoluteIndex(attrSource.AbsoluteIndex + valueStart).WithCharacterIndex(valueCharIndex).WithLength(valueLength).WithLineCount(0).WithEndCharacterIndex(valueCharIndex + valueLength);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,7 @@ private static void ConvertMixedLiteralAndExpressionValue(IntermediateNode targe
// Compute value source span with correct line/char positions.
var valueCharIndex = attrSource.CharacterIndex + prefix.Length + (attrSource.AbsoluteIndex + prefix.Length < valueStart ? 1 : 0);
var valueEndCharIndex = attrSource.EndCharacterIndex - suffix.Length;
var valueSource = new SourceSpan(
attrSource.FilePath, valueStart, attrSource.LineIndex, valueCharIndex,
valueLength, attrSource.LineCount, valueEndCharIndex);
var valueSource = attrSource.WithAbsoluteIndex(valueStart).WithCharacterIndex(valueCharIndex).WithLength(valueLength).WithEndCharacterIndex(valueEndCharIndex);
targetNode.Children.Add(new CSharpIntermediateToken(sourceText, valueSource));
}
}
Expand Down Expand Up @@ -678,10 +676,10 @@ private static void ConvertEscapedAtExpressionValue(IntermediateNode targetNode,
var transAbsIdx = atSrc.AbsoluteIndex + 2;
var transCharIdx = atSrc.CharacterIndex + 2;
// Empty token (MarkupEphemeralTextLiteral equivalent)
var emptySource = new SourceSpan(atSrc.FilePath, transAbsIdx, atSrc.LineIndex, transCharIdx, 0, 0, transCharIdx);
var emptySource = atSrc.WithAbsoluteIndex(transAbsIdx).WithCharacterIndex(transCharIdx).WithLength(0).WithLineCount(0).WithEndCharacterIndex(transCharIdx);
Comment thread
chsienki marked this conversation as resolved.
Outdated
targetNode.Children.Add(new CSharpIntermediateToken(string.Empty, emptySource));
// @ transition token
var transSource = new SourceSpan(atSrc.FilePath, transAbsIdx, atSrc.LineIndex, transCharIdx, 1, 0, transCharIdx + 1);
var transSource = atSrc.WithAbsoluteIndex(transAbsIdx).WithCharacterIndex(transCharIdx).WithLength(1).WithLineCount(0).WithEndCharacterIndex(transCharIdx + 1);
targetNode.Children.Add(new CSharpIntermediateToken("@", transSource));
}

Expand All @@ -693,7 +691,7 @@ private static void ConvertEscapedAtExpressionValue(IntermediateNode targetNode,
{
var openAbsIndex = innerSource.AbsoluteIndex - 1;
var openCharIndex = innerSource.CharacterIndex - 1;
var openSource = new SourceSpan(innerSource.FilePath, openAbsIndex, innerSource.LineIndex, openCharIndex, 1, 0, openCharIndex + 1);
var openSource = innerSource.WithAbsoluteIndex(openAbsIndex).WithCharacterIndex(openCharIndex).WithLength(1).WithLineCount(0).WithEndCharacterIndex(openCharIndex + 1);
targetNode.Children.Add(new CSharpIntermediateToken("(", openSource));

foreach (var innerChild in csharpExprValue.Children)
Expand All @@ -706,7 +704,7 @@ private static void ConvertEscapedAtExpressionValue(IntermediateNode targetNode,
{
var closeAbsIndex = lastSource.AbsoluteIndex + lastSource.Length;
var closeCharIndex = lastSource.EndCharacterIndex;
var closeSource = new SourceSpan(lastSource.FilePath, closeAbsIndex, lastSource.LineIndex, closeCharIndex, 1, 0, closeCharIndex + 1);
var closeSource = lastSource.WithAbsoluteIndex(closeAbsIndex).WithCharacterIndex(closeCharIndex).WithLength(1).WithLineCount(0).WithEndCharacterIndex(closeCharIndex + 1);
targetNode.Children.Add(new CSharpIntermediateToken(")", closeSource));
}
}
Expand Down Expand Up @@ -742,9 +740,7 @@ private static void ConvertPureCSharpExpressionValue(IntermediateNode targetNode
// to match baseline's separate token structure.
var openParenAbsIndex = valueStart + 1; // after @
var openParenCharIndex = attrSource.CharacterIndex + prefix.Length + 1;
var openParenSource = new SourceSpan(
attrSource.FilePath, openParenAbsIndex, attrSource.LineIndex, openParenCharIndex,
1, 0, openParenCharIndex + 1);
var openParenSource = attrSource.WithAbsoluteIndex(openParenAbsIndex).WithCharacterIndex(openParenCharIndex).WithLength(1).WithLineCount(0).WithEndCharacterIndex(openParenCharIndex + 1);
targetNode.Children.Add(new CSharpIntermediateToken("(", openParenSource));

// Inner expression content from the CSharpExpressionAttributeValueIntermediateNode
Expand All @@ -768,9 +764,7 @@ private static void ConvertPureCSharpExpressionValue(IntermediateNode targetNode

var closeParenAbsIndex = valueStart + valueLength - 1; // last char
var closeParenCharIndex = attrSource.CharacterIndex + prefix.Length + valueLength - 1;
var closeParenSource = new SourceSpan(
attrSource.FilePath, closeParenAbsIndex, attrSource.LineIndex, closeParenCharIndex,
1, 0, closeParenCharIndex + 1);
var closeParenSource = attrSource.WithAbsoluteIndex(closeParenAbsIndex).WithCharacterIndex(closeParenCharIndex).WithLength(1).WithLineCount(0).WithEndCharacterIndex(closeParenCharIndex + 1);
targetNode.Children.Add(new CSharpIntermediateToken(")", closeParenSource));
}
else
Expand Down Expand Up @@ -875,14 +869,7 @@ private static void UnwrapCSharpAttributeValue(
var valueAbsIndex = attrSource.AbsoluteIndex + prefix.Length;
var valueCharIndex = attrSource.CharacterIndex + prefix.Length;

return new SourceSpan(
attrSource.FilePath,
valueAbsIndex,
attrSource.LineIndex,
valueCharIndex,
length: 0,
lineCount: 0,
endCharacterIndex: valueCharIndex);
return attrSource.WithAbsoluteIndex(valueAbsIndex).WithCharacterIndex(valueCharIndex).WithLength(0).WithLineCount(0).WithEndCharacterIndex(valueCharIndex);
}

/// <summary>
Expand Down Expand Up @@ -1148,14 +1135,7 @@ private static void MergeAdjacentHtmlContent(IntermediateNode parent, int index,
current.Children.AddRange(next.Children);
if (current.Source is SourceSpan currentSource && next.Source is SourceSpan nextSource)
{
current.Source = new SourceSpan(
currentSource.FilePath,
currentSource.AbsoluteIndex,
currentSource.LineIndex,
currentSource.CharacterIndex,
(nextSource.AbsoluteIndex + nextSource.Length) - currentSource.AbsoluteIndex,
nextSource.LineCount,
nextSource.EndCharacterIndex);
current.Source = currentSource.WithLength((nextSource.AbsoluteIndex + nextSource.Length) - currentSource.AbsoluteIndex).WithLineCount(nextSource.LineCount).WithEndCharacterIndex(nextSource.EndCharacterIndex);
}
else if (current.Source == null)
{
Expand Down Expand Up @@ -1340,20 +1320,13 @@ private static void LowerImplicitExpressionAttribute_Legacy(

var openLoc = sourceDocument.Text.Lines.GetLinePosition(contentStart);
var closeLoc = sourceDocument.Text.Lines.GetLinePosition(contentStart + contentLength - 1);
expr.Source = new SourceSpan(exprSource.FilePath, contentStart, openLoc.Line, openLoc.Character, contentLength, 0, closeLoc.Character + 1);
expr.Source = exprSource.WithAbsoluteIndex(contentStart).WithLineIndex(openLoc.Line).WithCharacterIndex(openLoc.Character).WithLength(contentLength).WithLineCount(0).WithEndCharacterIndex(closeLoc.Character + 1);
}
else
{
// Implicit expression: single token.
var contentLocation = sourceDocument.Text.Lines.GetLinePosition(contentStart);
var contentSpan = new SourceSpan(
exprSource.FilePath,
contentStart,
contentLocation.Line,
contentLocation.Character,
contentLength,
0,
contentLocation.Character + contentLength);
var contentSpan = exprSource.WithAbsoluteIndex(contentStart).WithLineIndex(contentLocation.Line).WithCharacterIndex(contentLocation.Character).WithLength(contentLength).WithLineCount(0).WithEndCharacterIndex(contentLocation.Character + contentLength);
expr.Children.Add(new CSharpIntermediateToken(
LazyContent.Create(text, static s => s), contentSpan));
expr.Source = contentSpan;
Expand Down Expand Up @@ -1383,8 +1356,7 @@ private static void LowerImplicitExpressionAttribute_Legacy(

var mergedContent = sb.ToString();
var tokenSpan = firstSpan is { } f && lastSpan is { } l
? new SourceSpan(f.FilePath, f.AbsoluteIndex, f.LineIndex, f.CharacterIndex,
(l.AbsoluteIndex + l.Length) - f.AbsoluteIndex, l.LineIndex - f.LineIndex, l.EndCharacterIndex)
? f.WithLength((l.AbsoluteIndex + l.Length) - f.AbsoluteIndex).WithLineCount(l.LineIndex - f.LineIndex).WithEndCharacterIndex(l.EndCharacterIndex)
: firstSpan;
expr.Children.Add(new CSharpIntermediateToken(
LazyContent.Create(mergedContent, static s => s), tokenSpan));
Expand Down Expand Up @@ -1458,7 +1430,7 @@ private static void LowerMixedContentFromChildren_Legacy(
if (i + 1 < htmlAttr.Children.Count && htmlAttr.Children[i + 1].Source is { } nextSrc)
{
var loc = sourceDocument.Text.Lines.GetLinePosition(nextSrc.AbsoluteIndex);
emptySpan = new SourceSpan(nextSrc.FilePath, nextSrc.AbsoluteIndex, loc.Line, loc.Character, 0, 0, loc.Character);
emptySpan = nextSrc.WithLineIndex(loc.Line).WithCharacterIndex(loc.Character).WithLength(0).WithLineCount(0).WithEndCharacterIndex(loc.Character);
}

target.Children.Add(CreateEmptyCSharpToken(emptySpan));
Expand Down Expand Up @@ -1606,8 +1578,7 @@ private static void FlushPendingLiterals(

if (pendingFirstSpan is { } f && pendingLastSpan is { } l)
{
htmlContent.Source = new SourceSpan(f.FilePath, f.AbsoluteIndex, f.LineIndex, f.CharacterIndex,
(l.AbsoluteIndex + l.Length) - f.AbsoluteIndex, l.LineIndex - f.LineIndex + 1, l.EndCharacterIndex);
htmlContent.Source = f.WithLength((l.AbsoluteIndex + l.Length) - f.AbsoluteIndex).WithLineCount(l.LineIndex - f.LineIndex + 1).WithEndCharacterIndex(l.EndCharacterIndex);
}

target.Children.Add(htmlContent);
Expand Down Expand Up @@ -1638,14 +1609,7 @@ private static void TryAddCSharpInDeclarationDiagnostic(
var diagSource = exprChild.Source ?? elementNode.Source ?? SourceSpan.Undefined;
if (diagSource.AbsoluteIndex > 0)
{
diagSource = new SourceSpan(
diagSource.FilePath,
diagSource.AbsoluteIndex - 1,
diagSource.LineIndex,
diagSource.CharacterIndex - 1,
diagSource.Length + 1,
diagSource.LineCount,
diagSource.EndCharacterIndex);
diagSource = diagSource.WithAbsoluteIndex(diagSource.AbsoluteIndex - 1).WithCharacterIndex(diagSource.CharacterIndex - 1).WithLength(diagSource.Length + 1);
}

tagHelperNode.AddDiagnostic(
Expand Down
Loading
Loading