File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
src/PowerShellEditorServices
Services/Symbols/Visitors Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -94,11 +94,11 @@ public override AstVisitAction VisitVariableExpression(VariableExpressionAst var
94
94
return AstVisitAction . Continue ;
95
95
}
96
96
97
- // TODO: Consider tracking unscoped variable references only when they declared within
97
+ // TODO: Consider tracking unscoped variable references only when they're declared within
98
98
// the same function definition.
99
99
return _action ( new SymbolReference (
100
100
SymbolType . Variable ,
101
- "var " + variableExpressionAst . VariablePath . UserPath ,
101
+ "var " + VisitorUtils . GetUnqualifiedVariableName ( variableExpressionAst . VariablePath ) ,
102
102
"$" + variableExpressionAst . VariablePath . UserPath ,
103
103
variableExpressionAst . Extent ,
104
104
variableExpressionAst . Extent , // TODO: Maybe parent?
Original file line number Diff line number Diff line change 5
5
6
6
using System ;
7
7
using System . Collections . Generic ;
8
+ using System . Management . Automation ;
8
9
using System . Management . Automation . Language ;
9
10
using System . Text ;
10
11
using PSESSymbols = Microsoft . PowerShell . EditorServices . Services . Symbols ;
@@ -32,6 +33,14 @@ internal static class VisitorUtils
32
33
return PSESSymbols . AstOperations . TryGetInferredValue ( expandableStringExpressionAst , out string value ) ? value : null ;
33
34
}
34
35
36
+ // Strip the qualification, if there is any, so $var is a reference of $script:var etc.
37
+ internal static string GetUnqualifiedVariableName ( VariablePath variablePath )
38
+ {
39
+ return variablePath . IsUnqualified
40
+ ? variablePath . UserPath
41
+ : variablePath . UserPath . Substring ( variablePath . UserPath . IndexOf ( ':' ) + 1 ) ;
42
+ }
43
+
35
44
/// <summary>
36
45
/// Calculates the start line and column of the actual symbol name in a AST.
37
46
/// </summary>
You can’t perform that action at this time.
0 commit comments