@@ -95,8 +95,11 @@ private void AddReference(SymbolType type, string name, IScriptExtent nameExtent
9595 } ) ;
9696 }
9797
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.
100103 private sealed class ReferenceVisitor : AstVisitor2
101104 {
102105 private readonly ReferenceTable _references ;
@@ -115,8 +118,7 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
115118 SymbolType . Function ,
116119 CommandHelpers . StripModuleQualification ( commandName , out _ ) ,
117120 commandAst . CommandElements [ 0 ] . Extent ,
118- commandAst . Extent
119- ) ;
121+ commandAst . Extent ) ;
120122
121123 return AstVisitAction . Continue ;
122124 }
@@ -151,7 +153,8 @@ public override AstVisitAction VisitCommandParameter(CommandParameterAst command
151153 SymbolType . Parameter ,
152154 commandParameterAst . Extent . Text ,
153155 commandParameterAst . Extent ,
154- commandParameterAst . Extent ) ;
156+ commandParameterAst . Extent ,
157+ isDeclaration : true ) ;
155158
156159 return AstVisitAction . Continue ;
157160 }
@@ -164,8 +167,8 @@ public override AstVisitAction VisitVariableExpression(VariableExpressionAst var
164167 SymbolType . Variable ,
165168 $ "${ variableExpressionAst . VariablePath . UserPath } ",
166169 variableExpressionAst . Extent ,
167- variableExpressionAst . Extent
168- ) ;
170+ variableExpressionAst . Extent , // TODO: Maybe parent?
171+ isDeclaration : variableExpressionAst . Parent is AssignmentStatementAst or ParameterAst ) ;
169172
170173 return AstVisitAction . Continue ;
171174 }
@@ -181,7 +184,8 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit
181184 symbolType ,
182185 typeDefinitionAst . Name ,
183186 nameExtent ,
184- typeDefinitionAst . Extent ) ;
187+ typeDefinitionAst . Extent ,
188+ isDeclaration : true ) ;
185189
186190 return AstVisitAction . Continue ;
187191 }
@@ -214,12 +218,17 @@ public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMem
214218 ? SymbolType . Constructor
215219 : SymbolType . Method ;
216220
217- IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionMemberAst , true , false ) ;
221+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent (
222+ functionMemberAst ,
223+ useQualifiedName : false ,
224+ includeReturnType : false ) ;
225+
218226 _references . AddReference (
219227 symbolType ,
220- nameExtent . Text ,
228+ functionMemberAst . Name , // We bucket all the overloads.
221229 nameExtent ,
222- functionMemberAst . Extent ) ;
230+ functionMemberAst . Extent ,
231+ isDeclaration : true ) ;
223232
224233 return AstVisitAction . Continue ;
225234 }
@@ -230,12 +239,47 @@ public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMem
230239 propertyMemberAst . Parent is TypeDefinitionAst typeAst && typeAst . IsEnum
231240 ? SymbolType . EnumMember : SymbolType . Property ;
232241
233- IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( propertyMemberAst , false ) ;
242+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( propertyMemberAst , false , false ) ;
234243 _references . AddReference (
235244 symbolType ,
236245 nameExtent . Text ,
237246 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 ) ;
239283
240284 return AstVisitAction . Continue ;
241285 }
@@ -247,7 +291,8 @@ public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinit
247291 SymbolType . Configuration ,
248292 nameExtent . Text ,
249293 nameExtent ,
250- configurationDefinitionAst . Extent ) ;
294+ configurationDefinitionAst . Extent ,
295+ isDeclaration : true ) ;
251296
252297 return AstVisitAction . Continue ;
253298 }
0 commit comments