1
- // Copyright (c) Microsoft Corporation.
1
+ // Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
@@ -113,7 +113,7 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
113
113
/// Decides if the current function definition is a reference of the symbol being searched for.
114
114
/// A reference of the symbol will be a of type SymbolType.Function and have the same name as the symbol
115
115
/// </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>
117
117
/// <returns>A visit action that continues the search for references</returns>
118
118
public override AstVisitAction VisitFunctionDefinition ( FunctionDefinitionAst functionDefinitionAst )
119
119
{
@@ -124,31 +124,21 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun
124
124
return AstVisitAction . Continue ;
125
125
}
126
126
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
-
139
127
if ( _symbolRef . SymbolType . Equals ( SymbolType . Function ) &&
140
- nameExtent . Text . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
128
+ functionDefinitionAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
141
129
{
130
+ // We only want the function name
131
+ IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionDefinitionAst ) ;
142
132
FoundReferences . Add ( new SymbolReference ( SymbolType . Function , nameExtent ) ) ;
143
133
}
144
134
return base . VisitFunctionDefinition ( functionDefinitionAst ) ;
145
135
}
146
136
147
137
/// <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.
149
139
/// A reference of the symbol will be a of type SymbolType.Parameter and have the same name as the symbol
150
140
/// </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>
152
142
/// <returns>A visit action that continues the search for references</returns>
153
143
public override AstVisitAction VisitCommandParameter ( CommandParameterAst commandParameterAst )
154
144
{
@@ -161,10 +151,10 @@ public override AstVisitAction VisitCommandParameter(CommandParameterAst command
161
151
}
162
152
163
153
/// <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.
165
155
/// A reference of the symbol will be a of type SymbolType.Variable and have the same name as the symbol
166
156
/// </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>
168
158
/// <returns>A visit action that continues the search for references</returns>
169
159
public override AstVisitAction VisitVariableExpression ( VariableExpressionAst variableExpressionAst )
170
160
{
@@ -191,21 +181,8 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit
191
181
if ( ( _symbolRef . SymbolType is SymbolType . Type || _symbolRef . SymbolType . Equals ( symbolType ) ) &&
192
182
typeDefinitionAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
193
183
{
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 ) ;
209
186
FoundReferences . Add ( new SymbolReference ( symbolType , nameExtent ) ) ;
210
187
}
211
188
return AstVisitAction . Continue ;
@@ -260,21 +237,8 @@ public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMem
260
237
if ( _symbolRef . SymbolType . Equals ( symbolType ) &&
261
238
functionMemberAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
262
239
{
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 ) ;
278
242
FoundReferences . Add ( new SymbolReference ( symbolType , nameExtent ) ) ;
279
243
}
280
244
return AstVisitAction . Continue ;
@@ -291,7 +255,9 @@ public override AstVisitAction VisitPropertyMember(PropertyMemberAst propertyMem
291
255
if ( _symbolRef . SymbolType . Equals ( SymbolType . Property ) &&
292
256
propertyMemberAst . Name . Equals ( _symbolRef . SymbolName , StringComparison . CurrentCultureIgnoreCase ) )
293
257
{
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 ) ) ;
295
261
}
296
262
return AstVisitAction . Continue ;
297
263
}
0 commit comments