Skip to content

Commit d08775d

Browse files
committed
Detter symbol detection was timing out on larger files
1 parent 9ecc372 commit d08775d

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@ public async Task<PrepareRenameSymbolResult> Handle(PrepareRenameSymbolParams re
5454
{
5555
message = ""
5656
};
57-
58-
IEnumerable<Ast> tokens = scriptFile.ScriptAst.FindAll(ast =>
57+
// ast is FunctionDefinitionAst or CommandAst or VariableExpressionAst or StringConstantExpressionAst &&
58+
Ast token = scriptFile.ScriptAst.Find(ast =>
5959
{
6060
return request.Line + 1 == ast.Extent.StartLineNumber &&
6161
request.Column + 1 >= ast.Extent.StartColumnNumber;
62-
}, false);
63-
64-
Ast token = tokens.LastOrDefault();
65-
62+
}, true);
63+
IEnumerable<Ast> tokens = token.FindAll(ast =>{
64+
return ast.Extent.StartColumnNumber <= request.Column &&
65+
ast.Extent.EndColumnNumber >= request.Column;
66+
},true);
67+
token = tokens.LastOrDefault();
6668
if (token == null)
6769
{
6870
result.message = "Unable to find symbol";

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1313
using Microsoft.PowerShell.EditorServices.Refactoring;
1414
using System.Linq;
15-
1615
namespace Microsoft.PowerShell.EditorServices.Handlers
1716
{
1817
[Serial, Method("powerShell/renameSymbol")]
@@ -123,13 +122,16 @@ public async Task<RenameSymbolResult> Handle(RenameSymbolParams request, Cancell
123122
return await Task.Run(() =>
124123
{
125124

126-
IEnumerable<Ast> tokens = scriptFile.ScriptAst.FindAll(ast =>
125+
Ast token = scriptFile.ScriptAst.Find(ast =>
127126
{
128-
return request.Line+1 == ast.Extent.StartLineNumber &&
129-
request.Column+1 >= ast.Extent.StartColumnNumber;
130-
}, false);
131-
132-
Ast token = tokens.LastOrDefault();
127+
return request.Line + 1 == ast.Extent.StartLineNumber &&
128+
request.Column + 1 >= ast.Extent.StartColumnNumber;
129+
}, true);
130+
IEnumerable<Ast> tokens = token.FindAll(ast =>{
131+
return ast.Extent.StartColumnNumber <= request.Column &&
132+
ast.Extent.EndColumnNumber >= request.Column;
133+
},true);
134+
token = tokens.LastOrDefault();
133135

134136
if (token == null) { return null; }
135137

0 commit comments

Comments
 (0)