@@ -71,9 +71,20 @@ internal void EnsureInitialized()
71
71
_parent . ScriptAst . Visit ( new ReferenceVisitor ( this ) ) ;
72
72
}
73
73
74
- private void AddReference ( SymbolType type , string name , IScriptExtent extent , bool isDeclaration = false )
74
+ private static bool ExtentIsEmpty ( IScriptExtent e ) => string . IsNullOrEmpty ( e . File ) &&
75
+ e . StartLineNumber == 0 && e . StartColumnNumber == 0 &&
76
+ e . EndLineNumber == 0 && e . EndColumnNumber == 0 &&
77
+ string . IsNullOrEmpty ( e . Text ) ;
78
+
79
+ private void AddReference ( SymbolType type , string name , IScriptExtent nameExtent , IScriptExtent extent , bool isDeclaration = false )
75
80
{
76
- SymbolReference symbol = new ( type , name , extent , _parent , isDeclaration ) ;
81
+ // We have to exclude implicit things like `$this` that don't actually exist.
82
+ if ( ExtentIsEmpty ( extent ) )
83
+ {
84
+ return ;
85
+ }
86
+
87
+ SymbolReference symbol = new ( type , name , nameExtent , extent , _parent , isDeclaration ) ;
77
88
_symbolReferences . AddOrUpdate (
78
89
name ,
79
90
_ => new ConcurrentBag < SymbolReference > { symbol } ,
@@ -103,7 +114,8 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
103
114
_references . AddReference (
104
115
SymbolType . Function ,
105
116
CommandHelpers . StripModuleQualification ( commandName , out _ ) ,
106
- commandAst . CommandElements [ 0 ] . Extent
117
+ commandAst . CommandElements [ 0 ] . Extent ,
118
+ commandAst . Extent
107
119
) ;
108
120
109
121
return AstVisitAction . Continue ;
@@ -131,6 +143,7 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun
131
143
symbolType ,
132
144
functionDefinitionAst . Name ,
133
145
nameExtent ,
146
+ functionDefinitionAst . Extent ,
134
147
isDeclaration : true ) ;
135
148
136
149
return AstVisitAction . Continue ;
@@ -141,6 +154,7 @@ public override AstVisitAction VisitCommandParameter(CommandParameterAst command
141
154
_references . AddReference (
142
155
SymbolType . Parameter ,
143
156
commandParameterAst . Extent . Text ,
157
+ commandParameterAst . Extent ,
144
158
commandParameterAst . Extent ) ;
145
159
146
160
return AstVisitAction . Continue ;
@@ -153,6 +167,7 @@ public override AstVisitAction VisitVariableExpression(VariableExpressionAst var
153
167
_references . AddReference (
154
168
SymbolType . Variable ,
155
169
$ "${ variableExpressionAst . VariablePath . UserPath } ",
170
+ variableExpressionAst . Extent ,
156
171
variableExpressionAst . Extent
157
172
) ;
158
173
@@ -166,7 +181,11 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit
166
181
: SymbolType . Class ;
167
182
168
183
IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( typeDefinitionAst ) ;
169
- _references . AddReference ( symbolType , typeDefinitionAst . Name , nameExtent ) ;
184
+ _references . AddReference (
185
+ symbolType ,
186
+ typeDefinitionAst . Name ,
187
+ nameExtent ,
188
+ typeDefinitionAst . Extent ) ;
170
189
171
190
return AstVisitAction . Continue ;
172
191
}
@@ -176,14 +195,19 @@ public override AstVisitAction VisitTypeExpression(TypeExpressionAst typeExpress
176
195
_references . AddReference (
177
196
SymbolType . Type ,
178
197
typeExpressionAst . TypeName . Name ,
198
+ typeExpressionAst . Extent ,
179
199
typeExpressionAst . Extent ) ;
180
200
181
201
return AstVisitAction . Continue ;
182
202
}
183
203
184
204
public override AstVisitAction VisitTypeConstraint ( TypeConstraintAst typeConstraintAst )
185
205
{
186
- _references . AddReference ( SymbolType . Type , typeConstraintAst . TypeName . Name , typeConstraintAst . Extent ) ;
206
+ _references . AddReference (
207
+ SymbolType . Type ,
208
+ typeConstraintAst . TypeName . Name ,
209
+ typeConstraintAst . Extent ,
210
+ typeConstraintAst . Extent ) ;
187
211
188
212
return AstVisitAction . Continue ;
189
213
}
@@ -197,8 +221,9 @@ public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMem
197
221
IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionMemberAst , true , false ) ;
198
222
_references . AddReference (
199
223
symbolType ,
200
- VisitorUtils . GetMemberOverloadName ( functionMemberAst , true , false ) ,
201
- nameExtent ) ;
224
+ nameExtent . Text ,
225
+ nameExtent ,
226
+ functionMemberAst . Extent ) ;
202
227
203
228
return AstVisitAction . Continue ;
204
229
}
@@ -212,8 +237,9 @@ propertyMemberAst.Parent is TypeDefinitionAst typeAst && typeAst.IsEnum
212
237
IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( propertyMemberAst , false ) ;
213
238
_references . AddReference (
214
239
symbolType ,
215
- VisitorUtils . GetMemberOverloadName ( propertyMemberAst , false ) ,
216
- nameExtent ) ;
240
+ nameExtent . Text ,
241
+ nameExtent ,
242
+ propertyMemberAst . Extent ) ;
217
243
218
244
return AstVisitAction . Continue ;
219
245
}
@@ -224,7 +250,8 @@ public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinit
224
250
_references . AddReference (
225
251
SymbolType . Configuration ,
226
252
nameExtent . Text ,
227
- nameExtent ) ;
253
+ nameExtent ,
254
+ configurationDefinitionAst . Extent ) ;
228
255
229
256
return AstVisitAction . Continue ;
230
257
}
0 commit comments