@@ -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 ;
@@ -122,15 +134,12 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun
122
134
return AstVisitAction . Continue ;
123
135
}
124
136
125
- // We only want the function name as the extent for highlighting (and so forth).
126
- //
127
- // TODO: After we replace the deprecated SymbolInformation usage with DocumentSymbol,
128
- // we'll want *both* the name extent and the full extent.
129
137
IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionDefinitionAst ) ;
130
138
_references . AddReference (
131
139
symbolType ,
132
140
functionDefinitionAst . Name ,
133
141
nameExtent ,
142
+ functionDefinitionAst . Extent ,
134
143
isDeclaration : true ) ;
135
144
136
145
return AstVisitAction . Continue ;
@@ -141,6 +150,7 @@ public override AstVisitAction VisitCommandParameter(CommandParameterAst command
141
150
_references . AddReference (
142
151
SymbolType . Parameter ,
143
152
commandParameterAst . Extent . Text ,
153
+ commandParameterAst . Extent ,
144
154
commandParameterAst . Extent ) ;
145
155
146
156
return AstVisitAction . Continue ;
@@ -153,6 +163,7 @@ public override AstVisitAction VisitVariableExpression(VariableExpressionAst var
153
163
_references . AddReference (
154
164
SymbolType . Variable ,
155
165
$ "${ variableExpressionAst . VariablePath . UserPath } ",
166
+ variableExpressionAst . Extent ,
156
167
variableExpressionAst . Extent
157
168
) ;
158
169
@@ -166,7 +177,11 @@ public override AstVisitAction VisitTypeDefinition(TypeDefinitionAst typeDefinit
166
177
: SymbolType . Class ;
167
178
168
179
IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( typeDefinitionAst ) ;
169
- _references . AddReference ( symbolType , typeDefinitionAst . Name , nameExtent ) ;
180
+ _references . AddReference (
181
+ symbolType ,
182
+ typeDefinitionAst . Name ,
183
+ nameExtent ,
184
+ typeDefinitionAst . Extent ) ;
170
185
171
186
return AstVisitAction . Continue ;
172
187
}
@@ -176,14 +191,19 @@ public override AstVisitAction VisitTypeExpression(TypeExpressionAst typeExpress
176
191
_references . AddReference (
177
192
SymbolType . Type ,
178
193
typeExpressionAst . TypeName . Name ,
194
+ typeExpressionAst . Extent ,
179
195
typeExpressionAst . Extent ) ;
180
196
181
197
return AstVisitAction . Continue ;
182
198
}
183
199
184
200
public override AstVisitAction VisitTypeConstraint ( TypeConstraintAst typeConstraintAst )
185
201
{
186
- _references . AddReference ( SymbolType . Type , typeConstraintAst . TypeName . Name , typeConstraintAst . Extent ) ;
202
+ _references . AddReference (
203
+ SymbolType . Type ,
204
+ typeConstraintAst . TypeName . Name ,
205
+ typeConstraintAst . Extent ,
206
+ typeConstraintAst . Extent ) ;
187
207
188
208
return AstVisitAction . Continue ;
189
209
}
@@ -197,8 +217,9 @@ public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMem
197
217
IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( functionMemberAst , true , false ) ;
198
218
_references . AddReference (
199
219
symbolType ,
200
- VisitorUtils . GetMemberOverloadName ( functionMemberAst , true , false ) ,
201
- nameExtent ) ;
220
+ nameExtent . Text ,
221
+ nameExtent ,
222
+ functionMemberAst . Extent ) ;
202
223
203
224
return AstVisitAction . Continue ;
204
225
}
@@ -212,8 +233,9 @@ propertyMemberAst.Parent is TypeDefinitionAst typeAst && typeAst.IsEnum
212
233
IScriptExtent nameExtent = VisitorUtils . GetNameExtent ( propertyMemberAst , false ) ;
213
234
_references . AddReference (
214
235
symbolType ,
215
- VisitorUtils . GetMemberOverloadName ( propertyMemberAst , false ) ,
216
- nameExtent ) ;
236
+ nameExtent . Text ,
237
+ nameExtent ,
238
+ propertyMemberAst . Extent ) ;
217
239
218
240
return AstVisitAction . Continue ;
219
241
}
@@ -224,7 +246,8 @@ public override AstVisitAction VisitConfigurationDefinition(ConfigurationDefinit
224
246
_references . AddReference (
225
247
SymbolType . Configuration ,
226
248
nameExtent . Text ,
227
- nameExtent ) ;
249
+ nameExtent ,
250
+ configurationDefinitionAst . Extent ) ;
228
251
229
252
return AstVisitAction . Continue ;
230
253
}
0 commit comments