@@ -68,62 +68,62 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
6868 Me .MoveToNextSyntaxNodeInTrivia()
6969
7070 Else
71- Dim parser As New Parser( Me )
72-
73- Me .IsScanningXmlDoc = True
74- Me ._isStartingFirstXmlDocLine = True
75-
76- ' NOTE: Documentation comment syntax trivia must have at least one child xml node, because
77- ' all the ['''] trivia are created as leading trivia for appropriate tokens.
78- ' This means that we have to create at least one XmlText having trailing
79- ' EOL to represent an empty documentation comment: ['''<eol>]
80- '
81- ' The problem with this approach is that in presence of some errors (like
82- ' not closed XML tags) we create missing tokens needed to represent the nodes
83- ' *after* that last <eol> of the doc comment trivia, that means all the locations
84- ' of created diagnostics will land on the first character of the next line
85- ' after documentation comment
86- '
87- ' To workaround this we parse XML nodes in two phases:
88- ' - in the first phase we detect the last DocCommentLineBreak and create
89- ' end-of-xml token instead; this should force all diagnostics to be
90- ' reported on the next token location;
91- ' - in the second phase we continue parsing XML nodes but don't create
92- ' end-of-xml token which should just result in parsing one single node
93- ' of XmlText type containing EOL;
94- ' Then we merge the results and create resulting DocumentationCommentTrivia
95-
96- ' The first phase
97- Me ._endOfXmlInsteadOfLastDocCommentLineBreak = True
98- Dim nodes = parser.ParseXmlContent(ScannerState.Content)
99-
100- ' The second phase
101- Me ._endOfXmlInsteadOfLastDocCommentLineBreak = False
102- If nodes.Count = 0 AndAlso parser.CurrentToken.Kind = SyntaxKind.EndOfXmlToken Then
103- ' This must be an empty documentation comment, we need to reset scanner so
104- ' that the doc comment exterior trivia ([''']) lands on the final XmlNode
105-
106- ResetLineBufferOffset()
107- restorePoint.RestoreTokens(includeLookAhead:= False )
71+ Using parser = New Parser( Me )
72+ Me .IsScanningXmlDoc = True
10873 Me ._isStartingFirstXmlDocLine = True
109- End If
11074
111- nodes = parser.ParseRestOfDocCommentContent(nodes)
112- Me .IsScanningXmlDoc = False
75+ ' NOTE: Documentation comment syntax trivia must have at least one child xml node, because
76+ ' all the ['''] trivia are created as leading trivia for appropriate tokens.
77+ ' This means that we have to create at least one XmlText having trailing
78+ ' EOL to represent an empty documentation comment: ['''<eol>]
79+ '
80+ ' The problem with this approach is that in presence of some errors (like
81+ ' not closed XML tags) we create missing tokens needed to represent the nodes
82+ ' *after* that last <eol> of the doc comment trivia, that means all the locations
83+ ' of created diagnostics will land on the first character of the next line
84+ ' after documentation comment
85+ '
86+ ' To workaround this we parse XML nodes in two phases:
87+ ' - in the first phase we detect the last DocCommentLineBreak and create
88+ ' end-of-xml token instead; this should force all diagnostics to be
89+ ' reported on the next token location;
90+ ' - in the second phase we continue parsing XML nodes but don't create
91+ ' end-of-xml token which should just result in parsing one single node
92+ ' of XmlText type containing EOL;
93+ ' Then we merge the results and create resulting DocumentationCommentTrivia
94+
95+ ' The first phase
96+ Me ._endOfXmlInsteadOfLastDocCommentLineBreak = True
97+ Dim nodes = parser.ParseXmlContent(ScannerState.Content)
98+
99+ ' The second phase
100+ Me ._endOfXmlInsteadOfLastDocCommentLineBreak = False
101+ If nodes.Count = 0 AndAlso parser.CurrentToken.Kind = SyntaxKind.EndOfXmlToken Then
102+ ' This must be an empty documentation comment, we need to reset scanner so
103+ ' that the doc comment exterior trivia ([''']) lands on the final XmlNode
104+
105+ ResetLineBufferOffset()
106+ restorePoint.RestoreTokens(includeLookAhead:= False )
107+ Me ._isStartingFirstXmlDocLine = True
108+ End If
109+
110+ nodes = parser.ParseRestOfDocCommentContent(nodes)
111+ Me .IsScanningXmlDoc = False
113112
114- Debug.Assert(nodes.Any)
115- Debug.Assert(nodes( 0 ).FullWidth > 0 , "should at least get {'''EoL} " )
113+ Debug.Assert(nodes.Any)
114+ Debug.Assert(nodes( 0 ).FullWidth > 0 , "should at least get {'''EoL} " )
116115
117- ' restore _currentToken and lookahead,
118- ' but keep offset and PP state
119- ResetLineBufferOffset()
116+ ' restore _currentToken and lookahead,
117+ ' but keep offset and PP state
118+ ResetLineBufferOffset()
120119
121- docCommentSyntax = SyntaxFactory.DocumentationCommentTrivia(nodes)
120+ docCommentSyntax = SyntaxFactory.DocumentationCommentTrivia(nodes)
122121
123- If Me .Options.DocumentationMode < DocumentationMode.Diagnose Then
124- ' All diagnostics coming from documentation comment are ignored
125- docCommentSyntax.ClearFlags(GreenNode.NodeFlags.ContainsDiagnostics)
126- End If
122+ If Me .Options.DocumentationMode < DocumentationMode.Diagnose Then
123+ ' All diagnostics coming from documentation comment are ignored
124+ docCommentSyntax.ClearFlags(GreenNode.NodeFlags.ContainsDiagnostics)
125+ End If
126+ End Using
127127 End If
128128
129129 ' RESTORE lookahead state and current token if there were any
0 commit comments