Skip to content
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 @@ -295,15 +295,21 @@ private static int[] ConvertSemanticRangesToSemanticTokensData(
var isFirstRange = true;
var index = 0;
SemanticRange previousRange = default;
var i = 0;
foreach (var range in semanticRanges)
{
if (TryWriteToken(range, previousRange, isFirstRange, sourceText, tokens.AsSpan(index, TokenSize)))
var nextRange = semanticRanges.Count > i + 1
? semanticRanges[i + 1]
: default;

if (TryWriteToken(range, previousRange, nextRange, isFirstRange, sourceText, tokens.AsSpan(index, TokenSize)))
{
index += TokenSize;
previousRange = range;
}

isFirstRange = false;
i++;
}

// The common case is that the ConvertIntoDataArray calls didn't find any overlap, and we can just directly use the
Expand All @@ -319,12 +325,33 @@ private static int[] ConvertSemanticRangesToSemanticTokensData(
static bool TryWriteToken(
SemanticRange currentRange,
SemanticRange previousRange,
SemanticRange nextRange,
bool isFirstRange,
SourceText sourceText,
Span<int> destination)
{
Debug.Assert(destination.Length == TokenSize);

// Due to the fact that Razor ranges can supersede C# ranges, we can end up with C# whitespace ranges we've
// added, that we not don't want after further processing, so check for that, and skip emitting those ranges.
if (currentRange.IsCSharpWhitespace)
{
// If the previous range is on the same line, and from Razor, then we don't want to emit this.
// This happens when we have leftover whitespace from between two C# ranges, that were superseded by Razor ranges.
if (previousRange.FromRazor &&
currentRange.StartLine == previousRange.EndLine)
{
return false;
}

// If the next range is Razor, then it's leftover whitespace before C#, that was superseded by Razor, so don't emit.
if (nextRange.FromRazor &&
currentRange.StartCharacter == 0)
{
return false;
}
}

/*
* In short, each token takes 5 integers to represent, so a specific token `i` in the file consists of the following array indices:
* - at index `5*i` - `deltaLine`: token line number, relative to the previous token
Expand Down Expand Up @@ -366,16 +393,6 @@ static bool TryWriteToken(
deltaStart = currentRange.StartCharacter;
}

// If this is a C# whitespace range, and the previous range is on the same line, and from Razor
// then we don't want to emit this. This happens when we have leftover whitespace from between
// two C# ranges, that were superseded by Razor ranges.
if (currentRange.IsCSharpWhitespace &&
previousRange.FromRazor &&
currentRange.StartLine == previousRange.EndLine)
{
return false;
}

destination[0] = deltaLine;
destination[1] = deltaStart;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 razorComponentElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 razorComponentElement [] [InputText]
1 4 5 razorComponentAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 razorComponentAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [] [@]
0 1 6 keyword [] [typeof]
0 6 1 punctuation [] [(]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 markupElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 markupElement [] [InputText]
1 4 5 markupAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 markupAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [] [@]
0 1 6 keyword [] [typeof]
0 6 1 punctuation [] [(]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 razorComponentElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 razorComponentElement [] [InputText]
1 4 5 razorComponentAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 razorComponentAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [razorCode] [@]
0 1 6 keyword [razorCode] [typeof]
0 6 1 punctuation [razorCode] [(]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 markupElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 markupElement [] [InputText]
1 4 5 markupAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 markupAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [razorCode] [@]
0 1 6 keyword [razorCode] [typeof]
0 6 1 punctuation [razorCode] [(]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public async Task RazorComponents(bool colorBackground, bool miscellaneousFile)
<Microsoft.AspNetCore.Components.Forms.InputText Value="someValue" />
<Microsoft.AspNetCore.Components.Forms.InputText Value="someValue"></Microsoft.AspNetCore.Components.Forms.InputText>

<InputText
Value="someValue"
CssClass="my-class"
DisplayName="My Input" />

@typeof(InputText).ToString()
@typeof(Microsoft.AspNetCore.Components.Forms.InputText).ToString()
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 razorComponentElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 razorComponentElement [] [InputText]
1 4 5 razorComponentAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 razorComponentAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [] [@]
0 1 6 keyword [] [typeof]
0 6 1 punctuation [] [(]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 markupElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 markupElement [] [InputText]
1 4 5 markupAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 markupAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [] [@]
0 1 6 keyword [] [typeof]
0 6 1 punctuation [] [(]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 razorComponentElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 razorComponentElement [] [InputText]
1 4 5 razorComponentAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 razorComponentAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [razorCode] [@]
0 1 6 keyword [razorCode] [typeof]
0 6 1 punctuation [razorCode] [(]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ Line Δ, Char Δ, Length, Type, Modifier(s), Text
0 1 1 markupTagDelimiter [] [/]
0 1 47 markupElement [] [Microsoft.AspNetCore.Components.Forms.InputText]
0 47 1 markupTagDelimiter [] [>]
2 0 1 markupTagDelimiter [] [<]
0 1 9 markupElement [] [InputText]
1 4 5 markupAttribute [] [Value]
0 5 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 9 markupAttributeValue [] [someValue]
0 9 1 markupAttributeQuote [] ["]
1 4 8 markupAttribute [] [CssClass]
0 8 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 8 markupAttributeValue [] [my-class]
0 8 1 markupAttributeQuote [] ["]
1 4 11 markupAttribute [] [DisplayName]
0 11 1 markupOperator [] [=]
0 1 1 markupAttributeQuote [] ["]
0 1 2 markupAttributeValue [] [My]
0 2 6 markupAttributeValue [] [ Input]
0 6 1 markupAttributeQuote [] ["]
0 2 1 markupTagDelimiter [] [/]
0 1 1 markupTagDelimiter [] [>]
2 0 1 razorTransition [razorCode] [@]
0 1 6 keyword [razorCode] [typeof]
0 6 1 punctuation [razorCode] [(]
Expand Down