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
9494 return AstVisitAction . Continue ;
9595 }
9696
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
9898 // the same function definition.
9999 return _action ( new SymbolReference (
100100 SymbolType . Variable ,
101- "var " + variableExpressionAst . VariablePath . UserPath ,
101+ "var " + VisitorUtils . GetUnqualifiedVariableName ( variableExpressionAst . VariablePath ) ,
102102 "$" + variableExpressionAst . VariablePath . UserPath ,
103103 variableExpressionAst . Extent ,
104104 variableExpressionAst . Extent , // TODO: Maybe parent?
Original file line number Diff line number Diff line change 55
66using System ;
77using System . Collections . Generic ;
8+ using System . Management . Automation ;
89using System . Management . Automation . Language ;
910using System . Text ;
1011using PSESSymbols = Microsoft . PowerShell . EditorServices . Services . Symbols ;
@@ -32,6 +33,14 @@ internal static class VisitorUtils
3233 return PSESSymbols . AstOperations . TryGetInferredValue ( expandableStringExpressionAst , out string value ) ? value : null ;
3334 }
3435
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+
3544 /// <summary>
3645 /// Calculates the start line and column of the actual symbol name in a AST.
3746 /// </summary>
You can’t perform that action at this time.
0 commit comments