@@ -95,8 +95,11 @@ private void AddReference(SymbolType type, string name, IScriptExtent nameExtent
95
95
} ) ;
96
96
}
97
97
98
- // TODO: Should we move this to AstOperations.cs? It is highly coupled to `ReferenceTable`,
99
- // perhaps it doesn't have to be.
98
+ // TODO: Reconstruct this to take an action lambda that returns a visit action and accepts a
99
+ // symbol. Then ReferenceTable can add a reference and find symbol can just stop.
100
+ //
101
+ // TODO: Have a symbol name and a separate display name, the first minimally the text so the
102
+ // buckets work, the second usually a more complete signature for e.g. outline view.
100
103
private sealed class ReferenceVisitor : AstVisitor2
101
104
{
102
105
private readonly ReferenceTable _references ;
@@ -115,8 +118,7 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
115
118
SymbolType . Function ,
116
119
CommandHelpers . StripModuleQualification ( commandName , out _ ) ,
117
120
commandAst . CommandElements [ 0 ] . Extent ,
118
- commandAst . Extent
119
- ) ;
121
+ commandAst . Extent ) ;
120
122
121
123
return AstVisitAction . Continue ;
122
124
}
@@ -151,7 +153,8 @@ public override AstVisitAction VisitCommandParameter(CommandParameterAst command
151
153
SymbolType . Parameter ,
152
154
commandParameterAst . Extent . Text ,
153
155
commandParameterAst . Extent ,
154
- commandParameterAst . Extent ) ;
156
+ commandParameterAst . Extent ,
157
+ isDeclaration : true ) ;
155
158
156
159
return AstVisitAction . Continue ;
157
160
}
@@ -164,8 +167,8 @@ public override AstVisitAction VisitVariableExpression(VariableExpressionAst var
164
167
SymbolType . Variable ,
165
168
$ "${ variableExpressionAst . VariablePath . UserPath } ",
166
169
variableExpressionAst . Extent ,
167
- variableExpressionAst . Extent
168
- ) ;
170
+ variableExpressionAst . Extent , // TODO: Maybe parent?
171
+ isDeclaration : variableExpressionAst . Parent is AssignmentStatementAst or ParameterAst ) ;
169
172
170
173
return AstVisitAction . Continue ;
171
174
}
@@ -181,7 +184,8 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit
181
184
symbolType ,
182
185
typeDefinitionAst . Name ,
183
186
nameExtent ,
184
- typeDefinitionAst . Extent ) ;
187
+ typeDefinitionAst . Extent ,
188
+ isDeclaration : true ) ;
185
189
186
190
return AstVisitAction . Continue ;
187
191
}
@@ -214,12 +218,17 @@ public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMem
214
218
? SymbolType . Constructor
215
219
: SymbolType . Method ;
216
220
217
- IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionMemberAst , true , false ) ;
221
+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent (
222
+ functionMemberAst ,
223
+ useQualifiedName : false ,
224
+ includeReturnType : false ) ;
225
+
218
226
_references . AddReference (
219
227
symbolType ,
220
- nameExtent . Text ,
228
+ functionMemberAst . Name , // We bucket all the overloads.
221
229
nameExtent ,
222
- functionMemberAst . Extent ) ;
230
+ functionMemberAst . Extent ,
231
+ isDeclaration : true ) ;
223
232
224
233
return AstVisitAction . Continue ;
225
234
}
@@ -230,12 +239,47 @@ public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMem
230
239
propertyMemberAst . Parent is TypeDefinitionAst typeAst && typeAst . IsEnum
231
240
? SymbolType . EnumMember : SymbolType . Property ;
232
241
233
- IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( propertyMemberAst , false ) ;
242
+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( propertyMemberAst , false , false ) ;
234
243
_references . AddReference (
235
244
symbolType ,
236
245
nameExtent . Text ,
237
246
nameExtent ,
238
- propertyMemberAst . Extent ) ;
247
+ propertyMemberAst . Extent ,
248
+ isDeclaration : true ) ;
249
+
250
+ return AstVisitAction . Continue ;
251
+ }
252
+
253
+ public override AstVisitAction VisitMemberExpression ( MemberExpressionAst memberExpressionAst )
254
+ {
255
+ string ? memberName = memberExpressionAst . Member is StringConstantExpressionAst stringConstant ? stringConstant . Value : null ;
256
+ if ( string . IsNullOrEmpty ( memberName ) )
257
+ {
258
+ return AstVisitAction . Continue ;
259
+ }
260
+
261
+ _references . AddReference (
262
+ SymbolType . Property ,
263
+ memberName ,
264
+ memberExpressionAst . Member . Extent ,
265
+ memberExpressionAst . Extent ) ;
266
+
267
+ return AstVisitAction . Continue ;
268
+ }
269
+
270
+ public override AstVisitAction VisitInvokeMemberExpression ( InvokeMemberExpressionAst methodCallAst )
271
+ {
272
+ string ? memberName = methodCallAst . Member is StringConstantExpressionAst stringConstant ? stringConstant . Value : null ;
273
+ if ( string . IsNullOrEmpty ( memberName ) )
274
+ {
275
+ return AstVisitAction . Continue ;
276
+ }
277
+
278
+ _references . AddReference (
279
+ SymbolType . Method ,
280
+ memberName ,
281
+ methodCallAst . Member . Extent ,
282
+ methodCallAst . Extent ) ;
239
283
240
284
return AstVisitAction . Continue ;
241
285
}
@@ -247,7 +291,8 @@ public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinit
247
291
SymbolType . Configuration ,
248
292
nameExtent . Text ,
249
293
nameExtent ,
250
- configurationDefinitionAst . Extent ) ;
294
+ configurationDefinitionAst . Extent ,
295
+ isDeclaration : true ) ;
251
296
252
297
return AstVisitAction . Continue ;
253
298
}
0 commit comments