diff --git a/src/PowerShellEditorServices/Services/Symbols/Visitors/SymbolVisitor.cs b/src/PowerShellEditorServices/Services/Symbols/Visitors/SymbolVisitor.cs index 58d7f581a5..7603a73b2c 100644 --- a/src/PowerShellEditorServices/Services/Symbols/Visitors/SymbolVisitor.cs +++ b/src/PowerShellEditorServices/Services/Symbols/Visitors/SymbolVisitor.cs @@ -50,6 +50,8 @@ public override AstVisitAction VisitCommand(CommandAst commandAst) public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst functionDefinitionAst) { + // Treat filter the same as function: both get SymbolType.Function so they appear in the + // outline and support child symbols (variables, nested functions, etc.) in the hierarchy. SymbolType symbolType = functionDefinitionAst.IsWorkflow ? SymbolType.Workflow : SymbolType.Function; diff --git a/test/PowerShellEditorServices.Test.Shared/Symbols/MultipleSymbols.ps1 b/test/PowerShellEditorServices.Test.Shared/Symbols/MultipleSymbols.ps1 index 2831ea3320..79aacc0812 100644 --- a/test/PowerShellEditorServices.Test.Shared/Symbols/MultipleSymbols.ps1 +++ b/test/PowerShellEditorServices.Test.Shared/Symbols/MultipleSymbols.ps1 @@ -6,7 +6,7 @@ $Script:ScriptVar2 = 2 function script:AFunction {} -filter AFilter {$_} +filter AFilter { $FilterVar = $_ } function AnAdvancedFunction { begin { diff --git a/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs b/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs index 593fddb040..c23a8e23fe 100644 --- a/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs @@ -773,9 +773,9 @@ public void FindsSymbolsInFile() IEnumerable symbols = FindSymbolsInFile(FindSymbolsInMultiSymbolFile.SourceDetails); Assert.Equal(7, symbols.Count(i => i.Type == SymbolType.Function)); - Assert.Equal(8, symbols.Count(i => i.Type == SymbolType.Variable)); + Assert.Equal(9, symbols.Count(i => i.Type == SymbolType.Variable)); Assert.Equal(4, symbols.Count(i => i.Type == SymbolType.Parameter)); - Assert.Equal(12, symbols.Count(i => i.Id.StartsWith("var "))); + Assert.Equal(13, symbols.Count(i => i.Id.StartsWith("var "))); Assert.Equal(2, symbols.Count(i => i.Id.StartsWith("prop "))); SymbolReference symbol = symbols.First(i => i.Type == SymbolType.Function); @@ -788,6 +788,12 @@ public void FindsSymbolsInFile() Assert.Equal("filter AFilter ()", symbol.Name); Assert.True(symbol.IsDeclaration); + // Verify that a variable declared inside a filter is tracked as a declaration, + // allowing it to appear as a child of the filter in the LSP outline hierarchy. + symbol = Assert.Single(symbols, i => i.Id == "var FilterVar"); + Assert.Equal("$FilterVar", symbol.Name); + Assert.True(symbol.IsDeclaration); + symbol = symbols.Last(i => i.Type == SymbolType.Variable); Assert.Equal("var nestedVar", symbol.Id); Assert.Equal("$nestedVar", symbol.Name);