1- // Copyright (c) Microsoft Corporation.
1+ // Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
44using System ;
@@ -113,7 +113,7 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
113113 /// Decides if the current function definition is a reference of the symbol being searched for.
114114 /// A reference of the symbol will be a of type SymbolType.Function and have the same name as the symbol
115115 /// </summary>
116- /// <param name="functionDefinitionAst">A functionDefinitionAst in the script's AST</param>
116+ /// <param name="functionDefinitionAst">A FunctionDefinitionAst in the script's AST</param>
117117 /// <returns>A visit action that continues the search for references</returns>
118118 public override AstVisitAction VisitFunctionDefinition ( FunctionDefinitionAst functionDefinitionAst )
119119 {
@@ -124,31 +124,21 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun
124124 return AstVisitAction . Continue ;
125125 }
126126
127- ( int startColumnNumber , int startLineNumber ) = VisitorUtils . GetNameStartColumnAndLineNumbersFromAst ( functionDefinitionAst ) ;
128-
129- IScriptExtent nameExtent = new ScriptExtent ( )
130- {
131- Text = functionDefinitionAst . Name ,
132- StartLineNumber = startLineNumber ,
133- EndLineNumber = startLineNumber ,
134- StartColumnNumber = startColumnNumber ,
135- EndColumnNumber = startColumnNumber + functionDefinitionAst . Name . Length ,
136- File = functionDefinitionAst . Extent . File
137- } ;
138-
139127 if ( _symbolRef . SymbolType . Equals ( SymbolType . Function ) &&
140- nameExtent . Text . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
128+ functionDefinitionAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
141129 {
130+ // We only want the function name
131+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionDefinitionAst ) ;
142132 FoundReferences . Add ( new SymbolReference ( SymbolType . Function , nameExtent ) ) ;
143133 }
144134 return base . VisitFunctionDefinition ( functionDefinitionAst ) ;
145135 }
146136
147137 /// <summary>
148- /// Decides if the current function definition is a reference of the symbol being searched for.
138+ /// Decides if the current command parameter is a reference of the symbol being searched for.
149139 /// A reference of the symbol will be a of type SymbolType.Parameter and have the same name as the symbol
150140 /// </summary>
151- /// <param name="commandParameterAst">A commandParameterAst in the script's AST</param>
141+ /// <param name="commandParameterAst">A CommandParameterAst in the script's AST</param>
152142 /// <returns>A visit action that continues the search for references</returns>
153143 public override AstVisitAction VisitCommandParameter ( CommandParameterAst commandParameterAst )
154144 {
@@ -161,10 +151,10 @@ public override AstVisitAction VisitCommandParameter(CommandParameterAst command
161151 }
162152
163153 /// <summary>
164- /// Decides if the current function definition is a reference of the symbol being searched for.
154+ /// Decides if the current variable expression is a reference of the symbol being searched for.
165155 /// A reference of the symbol will be a of type SymbolType.Variable and have the same name as the symbol
166156 /// </summary>
167- /// <param name="variableExpressionAst">A variableExpressionAst in the script's AST</param>
157+ /// <param name="variableExpressionAst">A VariableExpressionAst in the script's AST</param>
168158 /// <returns>A visit action that continues the search for references</returns>
169159 public override AstVisitAction VisitVariableExpression ( VariableExpressionAst variableExpressionAst )
170160 {
@@ -191,21 +181,8 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit
191181 if ( ( _symbolRef . SymbolType is SymbolType . Type || _symbolRef . SymbolType . Equals ( symbolType ) ) &&
192182 typeDefinitionAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
193183 {
194- // Show only type name. Offset by StartColumn to include indentation etc.
195- int startColumnNumber =
196- typeDefinitionAst . Extent . StartColumnNumber +
197- typeDefinitionAst . Extent . Text . IndexOf ( typeDefinitionAst . Name ) ;
198-
199- IScriptExtent nameExtent = new ScriptExtent ( )
200- {
201- Text = typeDefinitionAst . Name ,
202- StartLineNumber = typeDefinitionAst . Extent . StartLineNumber ,
203- EndLineNumber = typeDefinitionAst . Extent . StartLineNumber ,
204- StartColumnNumber = startColumnNumber ,
205- EndColumnNumber = startColumnNumber + typeDefinitionAst . Name . Length ,
206- File = typeDefinitionAst . Extent . File
207- } ;
208-
184+ // We only want the type name. Get start-location for name
185+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( typeDefinitionAst ) ;
209186 FoundReferences . Add ( new SymbolReference ( symbolType , nameExtent ) ) ;
210187 }
211188 return AstVisitAction . Continue ;
@@ -260,21 +237,8 @@ public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMem
260237 if ( _symbolRef . SymbolType . Equals ( symbolType ) &&
261238 functionMemberAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
262239 {
263- // Show only method/ctor name. Offset by StartColumn to include indentation etc.
264- int startColumnNumber =
265- functionMemberAst . Extent . StartColumnNumber +
266- functionMemberAst . Extent . Text . IndexOf ( functionMemberAst . Name ) ;
267-
268- IScriptExtent nameExtent = new ScriptExtent ( )
269- {
270- Text = functionMemberAst . Name ,
271- StartLineNumber = functionMemberAst . Extent . StartLineNumber ,
272- EndLineNumber = functionMemberAst . Extent . StartLineNumber ,
273- StartColumnNumber = startColumnNumber ,
274- EndColumnNumber = startColumnNumber + functionMemberAst . Name . Length ,
275- File = functionMemberAst . Extent . File
276- } ;
277-
240+ // We only want the method/ctor name. Get start-location for name
241+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionMemberAst ) ;
278242 FoundReferences . Add ( new SymbolReference ( symbolType , nameExtent ) ) ;
279243 }
280244 return AstVisitAction . Continue ;
@@ -291,7 +255,9 @@ public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMem
291255 if ( _symbolRef . SymbolType . Equals ( SymbolType . Property ) &&
292256 propertyMemberAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
293257 {
294- FoundReferences . Add ( new SymbolReference ( SymbolType . Property , propertyMemberAst . Extent ) ) ;
258+ // We only want the property name. Get start-location for name
259+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( propertyMemberAst ) ;
260+ FoundReferences . Add ( new SymbolReference ( SymbolType . Property , nameExtent ) ) ;
295261 }
296262 return AstVisitAction . Continue ;
297263 }
0 commit comments