@@ -54,7 +54,7 @@ ILanguageServerConfiguration config
5454 internal bool DisclaimerAcceptedForSession ; //This is exposed to allow testing non-interactively
5555 private bool DisclaimerDeclinedForSession ;
5656 private const string ConfigSection = "powershell.rename" ;
57-
57+ private RenameServiceOptions ? options ;
5858 public async Task < RangeOrPlaceholderRange ? > PrepareRenameSymbol ( PrepareRenameParams request , CancellationToken cancellationToken )
5959 {
6060 RenameParams renameRequest = new ( )
@@ -78,7 +78,7 @@ ILanguageServerConfiguration config
7878 public async Task < WorkspaceEdit ? > RenameSymbol ( RenameParams request , CancellationToken cancellationToken )
7979 {
8080 // We want scoped settings because a workspace setting might be relevant here.
81- RenameServiceOptions options = await GetScopedSettings ( request . TextDocument . Uri , cancellationToken ) . ConfigureAwait ( false ) ;
81+ options = await GetScopedSettings ( request . TextDocument . Uri , cancellationToken ) . ConfigureAwait ( false ) ;
8282
8383 if ( ! await AcceptRenameDisclaimer ( options . acceptDisclaimer , cancellationToken ) . ConfigureAwait ( false ) ) { return null ; }
8484
@@ -98,7 +98,7 @@ or CommandAst
9898 VariableExpressionAst
9999 or CommandParameterAst
100100 or StringConstantExpressionAst
101- => RenameVariable ( tokenToRename , scriptFile . ScriptAst , request , options . createParameterAlias ) ,
101+ => RenameVariable ( tokenToRename , scriptFile . ScriptAst , request ) ,
102102
103103 _ => throw new InvalidOperationException ( "This should not happen as PrepareRename should have already checked for viability. File an issue if you see this." )
104104 } ;
@@ -120,10 +120,10 @@ private static TextEdit[] RenameFunction(Ast target, Ast scriptAst, RenameParams
120120 return visitor . VisitAndGetEdits ( scriptAst ) ;
121121 }
122122
123- private static TextEdit [ ] RenameVariable ( Ast symbol , Ast scriptAst , RenameParams requestParams , bool createParameterAlias )
123+ private TextEdit [ ] RenameVariable ( Ast symbol , Ast scriptAst , RenameParams requestParams )
124124 {
125- NewRenameVariableVisitor visitor = new (
126- symbol , requestParams . NewName
125+ RenameVariableVisitor visitor = new (
126+ symbol , requestParams . NewName , createParameterAlias : options ? . createParameterAlias ?? false
127127 ) ;
128128 return visitor . VisitAndGetEdits ( scriptAst ) ;
129129 }
@@ -407,7 +407,7 @@ internal static bool IsValidFunctionName(string name)
407407 }
408408}
409409
410- internal class NewRenameVariableVisitor ( Ast target , string newName , bool skipVerify = false ) : RenameVisitorBase
410+ internal class RenameVariableVisitor ( Ast target , string newName , bool skipVerify = false , bool createParameterAlias = false ) : RenameVisitorBase
411411{
412412 // Used to store the original definition of the variable to use as a reference.
413413 internal Ast ? VariableDefinition ;
@@ -446,6 +446,24 @@ internal AstVisitAction Visit(Ast ast)
446446
447447 if ( ShouldRename ( ast ) )
448448 {
449+ if (
450+ createParameterAlias
451+ && ast == VariableDefinition
452+ && VariableDefinition is not null and VariableExpressionAst varDefAst
453+ && varDefAst . Parent is ParameterAst paramAst
454+ )
455+ {
456+ Edits . Add ( new TextEdit
457+ {
458+ NewText = $ "[Alias('{ varDefAst . VariablePath . UserPath } ')]",
459+ Range = new Range ( )
460+ {
461+ Start = new ScriptPositionAdapter ( paramAst . Extent . StartScriptPosition ) ,
462+ End = new ScriptPositionAdapter ( paramAst . Extent . StartScriptPosition )
463+ }
464+ } ) ;
465+ }
466+
449467 Edits . Add ( GetRenameVariableEdit ( ast ) ) ;
450468 }
451469
0 commit comments