1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT License.
3+
4+ using System . Linq ;
5+ using System . Threading ;
6+ using System . Threading . Tasks ;
7+ using Microsoft . Extensions . Logging . Abstractions ;
8+ using Microsoft . PowerShell . EditorServices . Handlers ;
9+ using Microsoft . PowerShell . EditorServices . Services ;
10+ using Microsoft . PowerShell . EditorServices . Test . Shared ;
11+ using OmniSharp . Extensions . LanguageServer . Protocol ;
12+ using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
13+ using Xunit ;
14+
15+ namespace PowerShellEditorServices . Test . Language
16+ {
17+ [ Trait ( "Category" , "Symbols" ) ]
18+ public class DocumentSymbolHandlerTests
19+ {
20+ private readonly WorkspaceService workspace ;
21+ private readonly ConfigurationService configuration ;
22+ private readonly PsesDocumentSymbolHandler documentSymbolHandler ;
23+
24+ public DocumentSymbolHandlerTests ( )
25+ {
26+ workspace = new WorkspaceService ( NullLoggerFactory . Instance ) ;
27+ configuration = new ConfigurationService ( ) ;
28+ documentSymbolHandler = new PsesDocumentSymbolHandler (
29+ NullLoggerFactory . Instance ,
30+ workspace ,
31+ configuration ) ;
32+ }
33+
34+ [ Fact ]
35+ public async Task ExcludesParametersWhenParameterOutlineIsDisabled ( )
36+ {
37+ configuration . CurrentSettings . EnableParameterOutline = false ;
38+
39+ string filePath = TestUtilities . GetSharedPath (
40+ "Symbols/DocumentSymbolParameters.ps1" ) ;
41+
42+ SymbolInformationOrDocumentSymbolContainer result =
43+ await documentSymbolHandler . Handle (
44+ new DocumentSymbolParams
45+ {
46+ TextDocument = new TextDocumentIdentifier (
47+ DocumentUri . FromFileSystemPath ( filePath ) )
48+ } ,
49+ CancellationToken . None ) ;
50+
51+ DocumentSymbol function = result
52+ . Select ( symbol => symbol . DocumentSymbol )
53+ . Single ( symbol => symbol . Name . Contains ( "New-MyFunc" ) ) ;
54+
55+ Assert . DoesNotContain (
56+ function . Children ,
57+ symbol => symbol . Name . Contains ( "$MyString" ) ) ;
58+
59+ Assert . DoesNotContain (
60+ function . Children ,
61+ symbol => symbol . Name . Contains ( "$MyLooselyTypedParam" ) ) ;
62+ }
63+
64+ [ Fact ]
65+ public async Task IncludesParametersWhenParameterOutlineIsEnabled ( )
66+ {
67+ configuration . CurrentSettings . EnableParameterOutline = true ;
68+
69+ string filePath = TestUtilities . GetSharedPath (
70+ "Symbols/DocumentSymbolParameters.ps1" ) ;
71+
72+ SymbolInformationOrDocumentSymbolContainer result =
73+ await documentSymbolHandler . Handle (
74+ new DocumentSymbolParams
75+ {
76+ TextDocument = new TextDocumentIdentifier (
77+ DocumentUri . FromFileSystemPath ( filePath ) )
78+ } ,
79+ CancellationToken . None ) ;
80+
81+ DocumentSymbol function = result
82+ . Select ( symbol => symbol . DocumentSymbol )
83+ . Single ( symbol => symbol . Name . Contains ( "New-MyFunc" ) ) ;
84+
85+ Assert . Contains (
86+ function . Children ,
87+ symbol => symbol . Name . Contains ( "$MyString" ) ) ;
88+
89+ Assert . Contains (
90+ function . Children ,
91+ symbol => symbol . Name . Contains ( "$MyLooselyTypedParam" ) ) ;
92+ }
93+ }
94+ }
0 commit comments