@@ -182,48 +182,14 @@ public void Resolve(CancellationToken token)
182
182
}
183
183
}
184
184
185
- private IEnumerable < CommentNode > ParseComments ( QualifiedModuleName qualifiedName )
185
+ private IEnumerable < CommentNode > ParseComments ( QualifiedModuleName qualifiedName , IEnumerable < VBAParser . CommentContext > comments , IEnumerable < VBAParser . RemCommentContext > remComments )
186
186
{
187
- var result = new List < CommentNode > ( ) ;
188
-
189
- var code = qualifiedName . Component . CodeModule . GetSanitizedCode ( ) ;
190
- var commentBuilder = new StringBuilder ( ) ;
191
- var continuing = false ;
192
-
193
- var startLine = 0 ;
194
- var startColumn = 0 ;
195
-
196
- for ( var i = 0 ; i < code . Length ; i ++ )
197
- {
198
- var line = code [ i ] ;
199
- var index = 0 ;
200
-
201
- if ( continuing || line . HasComment ( out index ) )
202
- {
203
- startLine = continuing ? startLine : i ;
204
- startColumn = continuing ? startColumn : index ;
205
-
206
- var commentLength = line . Length - index ;
207
-
208
- continuing = line . EndsWith ( "_" ) ;
209
- if ( ! continuing )
210
- {
211
- commentBuilder . Append ( line . Substring ( index , commentLength ) . TrimStart ( ) ) ;
212
- var selection = new Selection ( startLine + 1 , startColumn + 1 , i + 1 , line . Length + 1 ) ;
213
-
214
- var comment = new CommentNode ( commentBuilder . ToString ( ) , new QualifiedSelection ( qualifiedName , selection ) ) ;
215
- commentBuilder . Clear ( ) ;
216
- result . Add ( comment ) ;
217
- }
218
- else
219
- {
220
- // ignore line continuations in comment text:
221
- commentBuilder . Append ( line . Substring ( index , commentLength ) . TrimStart ( ) ) ;
222
- }
223
- }
224
- }
225
-
226
- return result ;
187
+ var commentNodes = comments
188
+ . Select ( comment => new CommentNode ( comment . GetComment ( ) , Tokens . CommentMarker , new QualifiedSelection ( qualifiedName , comment . GetSelection ( ) ) ) ) ;
189
+ var remCommentNodes = remComments
190
+ . Select ( comment => new CommentNode ( comment . GetComment ( ) , Tokens . Rem , new QualifiedSelection ( qualifiedName , comment . GetSelection ( ) ) ) ) ;
191
+ var allCommentNodes = commentNodes . Union ( remCommentNodes ) ;
192
+ return allCommentNodes ;
227
193
}
228
194
229
195
private void ParseInternal ( VBComponent vbComponent , string code , CancellationToken token )
@@ -232,8 +198,6 @@ private void ParseInternal(VBComponent vbComponent, string code, CancellationTok
232
198
State . SetModuleState ( vbComponent , ParserState . Parsing ) ;
233
199
234
200
var qualifiedName = new QualifiedModuleName ( vbComponent ) ;
235
- var comments = ParseComments ( qualifiedName ) ;
236
- _state . SetModuleComments ( vbComponent , comments ) ;
237
201
238
202
var obsoleteCallsListener = new ObsoleteCallStatementListener ( ) ;
239
203
var obsoleteLetListener = new ObsoleteLetStatementListener ( ) ;
@@ -273,6 +237,9 @@ private void ParseInternal(VBComponent vbComponent, string code, CancellationTok
273
237
walker . Walk ( declarationsListener , tree ) ;
274
238
declarationsListener . NewDeclaration -= declarationsListener_NewDeclaration ;
275
239
240
+ var comments = ParseComments ( qualifiedName , commentListener . Comments , commentListener . RemComments ) ;
241
+ _state . SetModuleComments ( vbComponent , comments ) ;
242
+
276
243
_state . ObsoleteCallContexts = obsoleteCallsListener . Contexts . Select ( context => new QualifiedContext ( qualifiedName , context ) ) ;
277
244
_state . ObsoleteLetContexts = obsoleteLetListener . Contexts . Select ( context => new QualifiedContext ( qualifiedName , context ) ) ;
278
245
_state . EmptyStringLiterals = emptyStringLiteralListener . Contexts . Select ( context => new QualifiedContext ( qualifiedName , context ) ) ;
0 commit comments