-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[XSG] Correct lineinfo for expanded markups #31641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,15 @@ | |
|
|
||
| namespace Microsoft.Maui.Controls.SourceGen; | ||
|
|
||
| class ExpandMarkupsVisitor : IXamlNodeVisitor | ||
| class ExpandMarkupsVisitor(SourceGenContext context) : IXamlNodeVisitor | ||
| { | ||
| public ExpandMarkupsVisitor(SourceGenContext context) => Context = context; | ||
| record XmlLineInfoProvider(IXmlLineInfo XmlLineInfo) : IXmlLineInfoProvider | ||
| { | ||
| } | ||
|
|
||
| record SGContextProvider(SourceGenContext Context) | ||
| { | ||
| } | ||
|
|
||
| public static readonly IList<XmlName> Skips = | ||
| [ | ||
|
|
@@ -19,7 +25,7 @@ class ExpandMarkupsVisitor : IXamlNodeVisitor | |
| XmlName.xName, | ||
| ]; | ||
|
|
||
| SourceGenContext Context { get; } | ||
| SourceGenContext Context { get; } = context; | ||
| public TreeVisitingMode VisitingMode => TreeVisitingMode.BottomUp; | ||
| public bool StopOnDataTemplate => false; | ||
| public bool StopOnResourceDictionary => false; | ||
|
|
@@ -63,7 +69,7 @@ public void Visit(ListNode node, INode parentNode) | |
| INode? ParseExpression(ref string expression, IXmlNamespaceResolver nsResolver, IXmlLineInfo xmlLineInfo, INode node, INode parentNode) | ||
| { | ||
| if (expression.StartsWith("{}", StringComparison.Ordinal)) | ||
| return new ValueNode(expression.Substring(2), null); | ||
| return new ValueNode(expression.Substring(2), null, xmlLineInfo?.LineNumber ?? -1, xmlLineInfo?.LinePosition ?? -1); | ||
|
|
||
| if (expression[expression.Length - 1] != '}') | ||
| { | ||
|
|
@@ -92,16 +98,12 @@ public void Visit(ListNode node, INode parentNode) | |
| var serviceProvider = new XamlServiceProvider(node, Context); | ||
| serviceProvider.Add(typeof(IXmlNamespaceResolver), nsResolver); | ||
| serviceProvider.Add(typeof(SGContextProvider), new SGContextProvider(Context)); | ||
| if (xmlLineInfo != null) | ||
| serviceProvider.Add(typeof(IXmlLineInfoProvider), new XmlLineInfoProvider(xmlLineInfo)); | ||
|
|
||
| return new MarkupExpansionParser().Parse(match!, ref expression, serviceProvider); | ||
| } | ||
|
|
||
| class SGContextProvider | ||
| { | ||
| public SGContextProvider(SourceGenContext context) => Context = context; | ||
|
|
||
| public SourceGenContext Context { get; } | ||
| } | ||
|
|
||
| public class MarkupExpansionParser : MarkupExpressionParser, IExpressionParser<INode> | ||
| { | ||
|
|
@@ -110,7 +112,7 @@ public class MarkupExpansionParser : MarkupExpressionParser, IExpressionParser<I | |
|
|
||
| public INode Parse(string match, ref string remaining, IServiceProvider serviceProvider) | ||
| { | ||
| if (!(serviceProvider.GetService(typeof(IXmlNamespaceResolver)) is IXmlNamespaceResolver nsResolver)) | ||
| if (serviceProvider.GetService(typeof(IXmlNamespaceResolver)) is not IXmlNamespaceResolver nsResolver) | ||
| throw new ArgumentException(); | ||
| IXmlLineInfo? xmlLineInfo = null; | ||
| if (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) is IXmlLineInfoProvider xmlLineInfoProvider) | ||
|
|
@@ -149,7 +151,10 @@ public INode Parse(string match, ref string remaining, IServiceProvider serviceP | |
| catch (XamlParseException xpe) | ||
| { | ||
| if (contextProvider != null) | ||
| { | ||
| contextProvider.Context.ReportDiagnostic(Diagnostic.Create(Descriptors.XamlParserError, LocationHelpers.LocationCreate(contextProvider.Context.ProjectItem.RelativePath!, xmlLineInfo!, match), xpe.Message)); | ||
| return null!; | ||
StephaneDelcroix marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't ask what changed for that return null to be needed, I have no idea |
||
| } | ||
| else | ||
| throw; | ||
| } | ||
|
|
@@ -174,11 +179,11 @@ public INode Parse(string match, ref string remaining, IServiceProvider serviceP | |
| if (childname == XmlName.xTypeArguments) | ||
| { | ||
| typeArguments = TypeArgumentsParser.ParseExpression(parsed.strValue, nsResolver, xmlLineInfo); | ||
| childnodes.Add((childname, new ValueNode(typeArguments, nsResolver))); | ||
| childnodes.Add((childname, new ValueNode(typeArguments, nsResolver, xmlLineInfo?.LineNumber ?? -1, xmlLineInfo?.LinePosition ?? -1))); | ||
| } | ||
| else | ||
| { | ||
| var childnode = parsed.value as INode ?? new ValueNode(parsed.strValue, nsResolver); | ||
| var childnode = parsed.value as INode ?? new ValueNode(parsed.strValue, nsResolver, xmlLineInfo?.LineNumber ?? -1, xmlLineInfo?.LinePosition ?? -1); | ||
| childnodes.Add((childname, childnode)); | ||
| } | ||
| } | ||
|
|
@@ -198,9 +203,7 @@ public INode Parse(string match, ref string remaining, IServiceProvider serviceP | |
| throw new NotSupportedException(); | ||
|
|
||
|
|
||
| _node = xmlLineInfo == null | ||
| ? new ElementNode(xmltype, null, nsResolver) | ||
| : new ElementNode(xmltype, null, nsResolver, xmlLineInfo.LineNumber, xmlLineInfo.LinePosition); | ||
| _node = new ElementNode(xmltype, null, nsResolver, xmlLineInfo?.LineNumber ?? -1, xmlLineInfo?.LinePosition ?? -1); | ||
|
|
||
| foreach (var (childname, childnode) in childnodes) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.