Skip to content

Commit 6f5e416

Browse files
committed
finalised dot source detection and notification
1 parent 545bd0c commit 6f5e416

File tree

3 files changed

+12
-37
lines changed

3 files changed

+12
-37
lines changed

src/PowerShellEditorServices/Services/PowerShell/Handlers/PrepareRenameSymbol.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ public async Task<PrepareRenameSymbolResult> Handle(PrepareRenameSymbolParams re
5555
};
5656
// ast is FunctionDefinitionAst or CommandAst or VariableExpressionAst or StringConstantExpressionAst &&
5757
SymbolReference symbol = scriptFile.References.TryGetSymbolAtPosition(request.Line + 1, request.Column + 1);
58-
Ast token = Utilities.GetAst(request.Line + 1,request.Column + 1,scriptFile.ScriptAst);
58+
Ast token = Utilities.GetAst(request.Line + 1, request.Column + 1, scriptFile.ScriptAst);
5959

6060
if (token == null)
6161
{
6262
result.message = "Unable to find symbol";
6363
return result;
6464
}
65-
65+
if (Utilities.AssertContainsDotSourced(scriptFile.ScriptAst))
66+
{
67+
result.message = "Dot Source detected, this is currently not supported operation aborted";
68+
return result;
69+
}
6670
switch (token)
6771
{
6872
case FunctionDefinitionAst funcDef:
@@ -87,28 +91,17 @@ public async Task<PrepareRenameSymbolResult> Handle(PrepareRenameSymbolParams re
8791

8892
case VariableExpressionAst or CommandAst or CommandParameterAst or ParameterAst or StringConstantExpressionAst:
8993
{
90-
91-
try
94+
IterativeVariableRename visitor = new(request.RenameTo,
95+
token.Extent.StartLineNumber,
96+
token.Extent.StartColumnNumber,
97+
scriptFile.ScriptAst);
98+
if (visitor.TargetVariableAst == null)
9299
{
93-
IterativeVariableRename visitor = new(request.RenameTo,
94-
token.Extent.StartLineNumber,
95-
token.Extent.StartColumnNumber,
96-
scriptFile.ScriptAst);
97-
if (visitor.TargetVariableAst == null)
98-
{
99-
result.message = "Failed to find variable definition within the current file";
100-
}
100+
result.message = "Failed to find variable definition within the current file";
101101
}
102-
catch (TargetVariableIsDotSourcedException)
103-
{
104-
105-
result.message = "Variable is dot sourced which is currently not supported unable to perform a rename";
106-
}
107-
108102
break;
109103
}
110104
}
111-
112105
return result;
113106
}).ConfigureAwait(false);
114107
}

src/PowerShellEditorServices/Services/PowerShell/Refactoring/Exceptions.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,6 @@ public TargetSymbolNotFoundException(string message, Exception inner)
2222
}
2323
}
2424

25-
public class TargetVariableIsDotSourcedException : Exception
26-
{
27-
public TargetVariableIsDotSourcedException()
28-
{
29-
}
30-
31-
public TargetVariableIsDotSourcedException(string message)
32-
: base(message)
33-
{
34-
}
35-
36-
public TargetVariableIsDotSourcedException(string message, Exception inner)
37-
: base(message, inner)
38-
{
39-
}
40-
}
41-
4225
public class FunctionDefinitionNotFoundException : Exception
4326
{
4427
public FunctionDefinitionNotFoundException()

src/PowerShellEditorServices/Services/PowerShell/Refactoring/IterativeVariableVisitor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ internal class IterativeVariableRename
1919
internal int StartLineNumber;
2020
internal int StartColumnNumber;
2121
internal VariableExpressionAst TargetVariableAst;
22-
internal List<string> dotSourcedScripts = new();
2322
internal readonly Ast ScriptAst;
2423
internal bool isParam;
2524
internal bool AliasSet;

0 commit comments

Comments
 (0)