Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Re-add marker IR tokens to represent CSharp in an expression. #1160

Merged
merged 2 commits into from
Apr 3, 2017
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 @@ -21,6 +21,11 @@ public override void WriteCSharpExpression(CSharpRenderingContext context, CShar
throw new ArgumentNullException(nameof(node));
}

if (node.Children.Count == 0)
{
return;
}

if (node.Source != null)
{
using (context.Writer.BuildLinePragma(node.Source.Value))
Expand All @@ -29,28 +34,18 @@ public override void WriteCSharpExpression(CSharpRenderingContext context, CShar
context.Writer.WritePadding(offset, node.Source, context);
context.Writer.WriteStartAssignment(RazorDesignTimeIRPass.DesignTimeVariable);

if (node.Children.Count > 0)
for (var i = 0; i < node.Children.Count; i++)
{
for (var i = 0; i < node.Children.Count; i++)
if (node.Children[i] is RazorIRToken token && token.IsCSharp)
{
if (node.Children[i] is RazorIRToken token && token.IsCSharp)
{
context.AddLineMappingFor(token);
context.Writer.Write(token.Content);
}
else
{
// There may be something else inside the expression like a Template or another extension node.
context.RenderNode(node.Children[i]);
}
context.AddLineMappingFor(token);
context.Writer.Write(token.Content);
}
else
{
// There may be something else inside the expression like a Template or another extension node.
context.RenderNode(node.Children[i]);
}
}
else
{
// When typing "@" / "@(" we still need to provide IntelliSense. This is taken care of by creating a 0 length
// line mapping. It's also important that this 0 length line mapping exists in a line pragma so when a user
// starts typing additional characters following their "@" they get appropriately located errors.
context.AddLineMappingFor(node);
}

context.Writer.WriteLine(";");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public DesignTimeCSharpRenderer(RuntimeTarget target, CSharpRenderingContext con
public override void VisitCSharpExpression(CSharpExpressionIRNode node)
{
// We can't remove this yet, because it's still used recursively in a few places.
if (node.Children.Count == 0)
{
return;
}

if (node.Source != null)
{
Expand All @@ -31,29 +35,19 @@ public override void VisitCSharpExpression(CSharpExpressionIRNode node)
.Write(padding)
.WriteStartAssignment(RazorDesignTimeIRPass.DesignTimeVariable);

if (node.Children.Count > 0)
for (var i = 0; i < node.Children.Count; i++)
{
for (var i = 0; i < node.Children.Count; i++)
{
var token = node.Children[i] as RazorIRToken;
if (token != null && token.IsCSharp)
{
Context.AddLineMappingFor(token);
Context.Writer.Write(token.Content);
}
else
{
// There may be something else inside the expression like a Template or another extension node.
Visit(node.Children[i]);
}
{
Context.AddLineMappingFor(token);
Context.Writer.Write(token.Content);
}
else
{
// There may be something else inside the expression like a Template or another extension node.
Visit(node.Children[i]);
}
}
else
{
// When typing "@" / "@(" we still need to provide IntelliSense. This is taken care of by creating a 0 length
// line mapping. It's also important that this 0 length line mapping exists in a line pragma so when a user
// starts typing additional characters following their "@" they get appropriately located errors.
Context.AddLineMappingFor(node);
}

Context.Writer.WriteLine(";");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ public override void VisitExpressionBlock(ExpressionChunkGenerator chunkGenerato

_builder.Pop();

var emptyExpression = true;
if (expressionNode.Children.Count > 0)
{
var sourceRangeStart = expressionNode
Expand All @@ -362,34 +361,12 @@ public override void VisitExpressionBlock(ExpressionChunkGenerator chunkGenerato
sourceRangeStart.Value.LineIndex,
sourceRangeStart.Value.CharacterIndex,
contentLength);
emptyExpression = false;
}
}

if (emptyExpression)
{
expressionNode.Source = new SourceSpan(
block.Start.FilePath ?? FileName,
block.Start.AbsoluteIndex,
block.Start.LineIndex,
block.Start.CharacterIndex,
length: 0);
}
}

public override void VisitExpressionSpan(ExpressionChunkGenerator chunkGenerator, Span span)
{
if (span.Symbols.Count == 1)
{
if (span.Symbols[0] is CSharpSymbol symbol &&
symbol.Type == CSharpSymbolType.Unknown &&
symbol.Content.Length == 0)
{
// We don't want to create IR nodes for marker symbols.
return;
}
}

_builder.Add(new RazorIRToken()
{
Content = span.Content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Document -
RazorIRToken - - CSharp - private static System.Object __o = null;
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] EmptyExplicitExpression.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] EmptyExplicitExpression.cshtml)
CSharpExpression - (20:2,2 [0] EmptyExplicitExpression.cshtml)
RazorIRToken - (20:2,2 [0] EmptyExplicitExpression.cshtml) - CSharp -
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source Location: (18:2,0 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/EmptyExplicitExpression.cshtml)
Source Location: (20:2,2 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/EmptyExplicitExpression.cshtml)
||
Generated Location: (678:16,6 [0] )
||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Document -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_EmptyExplicitExpression_Runtime - -
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] EmptyExplicitExpression.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] EmptyExplicitExpression.cshtml)
CSharpExpression - (20:2,2 [0] EmptyExplicitExpression.cshtml)
RazorIRToken - (20:2,2 [0] EmptyExplicitExpression.cshtml) - CSharp -
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Document -
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
CSharpStatement - (2:0,2 [6] EmptyImplicitExpressionInCode.cshtml)
RazorIRToken - (2:0,2 [6] EmptyImplicitExpressionInCode.cshtml) - CSharp - \n
CSharpExpression - (8:1,4 [0] EmptyImplicitExpressionInCode.cshtml)
CSharpExpression - (9:1,5 [0] EmptyImplicitExpressionInCode.cshtml)
RazorIRToken - (9:1,5 [0] EmptyImplicitExpressionInCode.cshtml) - CSharp -
CSharpStatement - (9:1,5 [2] EmptyImplicitExpressionInCode.cshtml)
RazorIRToken - (9:1,5 [2] EmptyImplicitExpressionInCode.cshtml) - CSharp - \n
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Generated Location: (593:15,14 [6] )
|
|

Source Location: (8:1,4 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/EmptyImplicitExpressionInCode.cshtml)
Source Location: (9:1,5 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/EmptyImplicitExpressionInCode.cshtml)
||
Generated Location: (712:18,6 [0] )
||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Document -
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
CSharpStatement - (2:0,2 [6] EmptyImplicitExpressionInCode.cshtml)
RazorIRToken - (2:0,2 [6] EmptyImplicitExpressionInCode.cshtml) - CSharp - \n
CSharpExpression - (8:1,4 [0] EmptyImplicitExpressionInCode.cshtml)
CSharpExpression - (9:1,5 [0] EmptyImplicitExpressionInCode.cshtml)
RazorIRToken - (9:1,5 [0] EmptyImplicitExpressionInCode.cshtml) - CSharp -
CSharpStatement - (9:1,5 [2] EmptyImplicitExpressionInCode.cshtml)
RazorIRToken - (9:1,5 [2] EmptyImplicitExpressionInCode.cshtml) - CSharp - \n
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ Document -
RazorIRToken - - CSharp - private static System.Object __o = null;
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] EmptyImplicitExpression.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] EmptyImplicitExpression.cshtml)
CSharpExpression - (19:2,1 [0] EmptyImplicitExpression.cshtml)
RazorIRToken - (19:2,1 [0] EmptyImplicitExpression.cshtml) - CSharp -
HtmlContent - (19:2,1 [1] EmptyImplicitExpression.cshtml) - !
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source Location: (18:2,0 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/EmptyImplicitExpression.cshtml)
Source Location: (19:2,1 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/EmptyImplicitExpression.cshtml)
||
Generated Location: (678:16,6 [0] )
||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Document -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_EmptyImplicitExpression_Runtime - -
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] EmptyImplicitExpression.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] EmptyImplicitExpression.cshtml)
CSharpExpression - (19:2,1 [0] EmptyImplicitExpression.cshtml)
RazorIRToken - (19:2,1 [0] EmptyImplicitExpression.cshtml) - CSharp -
HtmlContent - (19:2,1 [1] EmptyImplicitExpression.cshtml) - !
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Document -
RazorIRToken - - CSharp - private static System.Object __o = null;
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] ExplicitExpressionAtEOF.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] ExplicitExpressionAtEOF.cshtml)
CSharpExpression - (20:2,2 [0] ExplicitExpressionAtEOF.cshtml)
RazorIRToken - (20:2,2 [0] ExplicitExpressionAtEOF.cshtml) - CSharp -
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source Location: (18:2,0 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ExplicitExpressionAtEOF.cshtml)
Source Location: (20:2,2 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ExplicitExpressionAtEOF.cshtml)
||
Generated Location: (678:16,6 [0] )
||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Document -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ExplicitExpressionAtEOF_Runtime - -
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] ExplicitExpressionAtEOF.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] ExplicitExpressionAtEOF.cshtml)
CSharpExpression - (20:2,2 [0] ExplicitExpressionAtEOF.cshtml)
RazorIRToken - (20:2,2 [0] ExplicitExpressionAtEOF.cshtml) - CSharp -
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Document -
CSharpExpression - (8:0,8 [6] ExplicitExpressionWithMarkup.cshtml)
Template - (8:0,8 [6] ExplicitExpressionWithMarkup.cshtml)
HtmlContent - (8:0,8 [6] ExplicitExpressionWithMarkup.cshtml) - </div>
RazorIRToken - (14:0,14 [0] ExplicitExpressionWithMarkup.cshtml) - CSharp -
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (14:0,14 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ExplicitExpressionWithMarkup.cshtml)
||
Generated Location: (787:18,1 [0] )
||

Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Document -
CSharpExpression - (8:0,8 [6] ExplicitExpressionWithMarkup.cshtml)
Template - (8:0,8 [6] ExplicitExpressionWithMarkup.cshtml)
HtmlContent - (8:0,8 [6] ExplicitExpressionWithMarkup.cshtml) - </div>
RazorIRToken - (14:0,14 [0] ExplicitExpressionWithMarkup.cshtml) - CSharp -
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Document -
RazorIRToken - - CSharp - private static System.Object __o = null;
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] ImplicitExpressionAtEOF.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] ImplicitExpressionAtEOF.cshtml)
CSharpExpression - (19:2,1 [0] ImplicitExpressionAtEOF.cshtml)
RazorIRToken - (19:2,1 [0] ImplicitExpressionAtEOF.cshtml) - CSharp -
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source Location: (18:2,0 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ImplicitExpressionAtEOF.cshtml)
Source Location: (19:2,1 [0] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ImplicitExpressionAtEOF.cshtml)
||
Generated Location: (678:16,6 [0] )
||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Document -
ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ImplicitExpressionAtEOF_Runtime - -
RazorMethodDeclaration - - public - async - System.Threading.Tasks.Task - ExecuteAsync
HtmlContent - (0:0,0 [18] ImplicitExpressionAtEOF.cshtml) - This is markup\n\n
CSharpExpression - (18:2,0 [0] ImplicitExpressionAtEOF.cshtml)
CSharpExpression - (19:2,1 [0] ImplicitExpressionAtEOF.cshtml)
RazorIRToken - (19:2,1 [0] ImplicitExpressionAtEOF.cshtml) - CSharp -