Skip to content

Commit 7da6f9d

Browse files
committed
Strip qualifier from variable name in symbol identifier
1 parent 0135baa commit 7da6f9d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/PowerShellEditorServices/Services/Symbols/Visitors/SymbolVisitor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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?

src/PowerShellEditorServices/Utility/VisitorUtils.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System;
77
using System.Collections.Generic;
8+
using System.Management.Automation;
89
using System.Management.Automation.Language;
910
using System.Text;
1011
using 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>

0 commit comments

Comments
 (0)