private static MarkupMinimizedTagHelperDirectiveAttributeSyntax RewriteToMinimizedDirectiveAttribute( MarkupMinimizedAttributeBlockSyntax attributeBlock, TryParseResult result) { // // Consider, <Foo @bind:param /> // We're now going to rewrite @bind:param from a regular MarkupAttributeBlock to a MarkupTagHelperDirectiveAttribute. // We need to split the name "@bind:param" into four parts, // @ - Transition (MetaCode) // bind - Name (Text) // : - Colon (MetaCode) // param - ParameterName (Text) // var attributeName = result.AttributeName; var attributeNameSyntax = attributeBlock.Name; var transition = SyntaxFactory.RazorMetaCode( new SyntaxList <SyntaxToken>(SyntaxFactory.MissingToken(SyntaxKind.Transition))); RazorMetaCodeSyntax colon = null; MarkupTextLiteralSyntax parameterName = null; if (attributeName.StartsWith("@", StringComparison.Ordinal)) { attributeName = attributeName.Substring(1); var attributeNameToken = SyntaxFactory.Token(SyntaxKind.Text, attributeName); attributeNameSyntax = SyntaxFactory.MarkupTextLiteral().AddLiteralTokens(attributeNameToken); var transitionToken = SyntaxFactory.Token(SyntaxKind.Transition, "@"); transition = SyntaxFactory.RazorMetaCode(new SyntaxList <SyntaxToken>(transitionToken)); } if (attributeName.IndexOf(':') != -1) { var segments = attributeName.Split(new[] { ':' }, 2); var attributeNameToken = SyntaxFactory.Token(SyntaxKind.Text, segments[0]); attributeNameSyntax = SyntaxFactory.MarkupTextLiteral().AddLiteralTokens(attributeNameToken); var colonToken = SyntaxFactory.Token(SyntaxKind.Colon, ":"); colon = SyntaxFactory.RazorMetaCode(new SyntaxList <SyntaxToken>(colonToken)); var parameterNameToken = SyntaxFactory.Token(SyntaxKind.Text, segments[1]); parameterName = SyntaxFactory.MarkupTextLiteral().AddLiteralTokens(parameterNameToken); } var rewritten = SyntaxFactory.MarkupMinimizedTagHelperDirectiveAttribute( attributeBlock.NamePrefix, transition, attributeNameSyntax, colon, parameterName); rewritten = rewritten.WithTagHelperAttributeInfo( new TagHelperAttributeInfo(result.AttributeName, parameterName?.GetContent(), result.AttributeStructure, result.IsBoundAttribute, isDirectiveAttribute: true)); return(rewritten); }
public override void VisitRazorMetaCode(RazorMetaCodeSyntax node) { if (node.Kind == SyntaxKind.RazorMetaCode) { AddSemanticRange(node, RazorSemanticTokensLegend.RazorTransition); } else { throw new NotSupportedException("Attempted to visit a RazorMetaCode other than '{' or '}'."); } }
public override void VisitRazorMetaCode(RazorMetaCodeSyntax node) { if (node.Kind == SyntaxKind.RazorMetaCode) { AddSemanticRange(node, RazorSemanticTokensLegend.RazorTransition); } else { throw new NotSupportedException(RazorLS.Resources.Unknown_RazorMetaCode); } }
public override SyntaxNode VisitRazorMetaCode(RazorMetaCodeSyntax node) { if (!_tryParseResult.IsBoundNonStringAttribute) { return(base.VisitRazorMetaCode(node)); } if (_rewriteAsMarkup) { // Change to a MarkupChunkGenerator so that the '@' \ parenthesis is generated as part of the output. var context = node.GetSpanContext(); var newContext = new SpanContext(new MarkupChunkGenerator(), context.EditHandler); var expression = SyntaxFactory.CSharpExpressionLiteral(new SyntaxList <SyntaxToken>(node.MetaCode)).WithSpanContext(newContext); return(VisitCSharpExpressionLiteral(expression)); } _rewriteAsMarkup = true; return(base.VisitRazorMetaCode(node)); }
public override void VisitRazorMetaCode(RazorMetaCodeSyntax node) { WriteNode(node, isHtml: false, base.VisitRazorMetaCode); }
public override void VisitRazorMetaCode(RazorMetaCodeSyntax node) { WriteSpan(node, FormattingSpanKind.MetaCode); base.VisitRazorMetaCode(node); }
public override void VisitRazorMetaCode(RazorMetaCodeSyntax node) { WriteSpan(node, SpanKindInternal.MetaCode); base.VisitRazorMetaCode(node); }