Skip to content

Commit 0a12783

Browse files
CopilotJustinGrote
andauthored
Fix filter to be treated the same as function in LSP outline view
- Add explicit comment in VisitFunctionDefinition clarifying filter gets SymbolType.Function so it participates in the outline hierarchy the same way regular functions do (children expand correctly) - Update MultipleSymbols.ps1 test data so AFilter has a local variable declaration ($FilterVar = $_), exercising filter-with-children path - Update FindsSymbolsInFile test counts and add assertion verifying $FilterVar inside a filter is tracked as a declaration (prerequisite for it appearing as a child of the filter in the outline) Agent-Logs-Url: https://github.com/PowerShell/PowerShellEditorServices/sessions/89bcabc2-3cb5-470a-8d43-bcc6adaf0c30 Co-authored-by: JustinGrote <15258962+JustinGrote@users.noreply.github.com>
1 parent 45a5005 commit 0a12783

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public override AstVisitAction VisitCommand(CommandAst commandAst)
5050

5151
public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst functionDefinitionAst)
5252
{
53+
// Treat filter the same as function: both get SymbolType.Function so they appear in the
54+
// outline and support child symbols (variables, nested functions, etc.) in the hierarchy.
5355
SymbolType symbolType = functionDefinitionAst.IsWorkflow
5456
? SymbolType.Workflow
5557
: SymbolType.Function;

test/PowerShellEditorServices.Test.Shared/Symbols/MultipleSymbols.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $Script:ScriptVar2 = 2
66

77
function script:AFunction {}
88

9-
filter AFilter {$_}
9+
filter AFilter { $FilterVar = $_ }
1010

1111
function AnAdvancedFunction {
1212
begin {

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,9 @@ public void FindsSymbolsInFile()
773773
IEnumerable<SymbolReference> symbols = FindSymbolsInFile(FindSymbolsInMultiSymbolFile.SourceDetails);
774774

775775
Assert.Equal(7, symbols.Count(i => i.Type == SymbolType.Function));
776-
Assert.Equal(8, symbols.Count(i => i.Type == SymbolType.Variable));
776+
Assert.Equal(9, symbols.Count(i => i.Type == SymbolType.Variable));
777777
Assert.Equal(4, symbols.Count(i => i.Type == SymbolType.Parameter));
778-
Assert.Equal(12, symbols.Count(i => i.Id.StartsWith("var ")));
778+
Assert.Equal(13, symbols.Count(i => i.Id.StartsWith("var ")));
779779
Assert.Equal(2, symbols.Count(i => i.Id.StartsWith("prop ")));
780780

781781
SymbolReference symbol = symbols.First(i => i.Type == SymbolType.Function);
@@ -788,6 +788,12 @@ public void FindsSymbolsInFile()
788788
Assert.Equal("filter AFilter ()", symbol.Name);
789789
Assert.True(symbol.IsDeclaration);
790790

791+
// Verify that a variable declared inside a filter is tracked as a declaration,
792+
// allowing it to appear as a child of the filter in the LSP outline hierarchy.
793+
symbol = Assert.Single(symbols, i => i.Id == "var FilterVar");
794+
Assert.Equal("$FilterVar", symbol.Name);
795+
Assert.True(symbol.IsDeclaration);
796+
791797
symbol = symbols.Last(i => i.Type == SymbolType.Variable);
792798
Assert.Equal("var nestedVar", symbol.Id);
793799
Assert.Equal("$nestedVar", symbol.Name);

0 commit comments

Comments
 (0)