1111using Microsoft . PowerShell . EditorServices . Logging ;
1212using Microsoft . PowerShell . EditorServices . Services ;
1313using Microsoft . PowerShell . EditorServices . Services . Configuration ;
14+ using Microsoft . PowerShell . EditorServices . Services . Extension ;
15+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
1416using Newtonsoft . Json . Linq ;
1517using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
1618using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
1719using OmniSharp . Extensions . LanguageServer . Protocol . Window ;
1820using OmniSharp . Extensions . LanguageServer . Protocol . Workspace ;
19- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
20- using Microsoft . PowerShell . EditorServices . Services . Extension ;
21-
2221
2322namespace Microsoft . PowerShell . EditorServices . Handlers
2423{
@@ -31,7 +30,7 @@ internal class PsesConfigurationHandler : DidChangeConfigurationHandlerBase
3130 private readonly PsesInternalHost _psesHost ;
3231 private readonly ILanguageServerFacade _languageServer ;
3332 private bool _profilesLoaded ;
34- private bool _extensionServiceInitialized ;
33+ private readonly bool _extensionServiceInitialized ;
3534 private bool _cwdSet ;
3635
3736 public PsesConfigurationHandler (
@@ -56,10 +55,10 @@ public PsesConfigurationHandler(
5655 public override async Task < Unit > Handle ( DidChangeConfigurationParams request , CancellationToken cancellationToken )
5756 {
5857 LanguageServerSettingsWrapper incomingSettings = request . Settings . ToObject < LanguageServerSettingsWrapper > ( ) ;
59- this . _logger . LogTrace ( "Handling DidChangeConfiguration" ) ;
58+ _logger . LogTrace ( "Handling DidChangeConfiguration" ) ;
6059 if ( incomingSettings is null || incomingSettings . Powershell is null )
6160 {
62- this . _logger . LogTrace ( "Incoming settings were null" ) ;
61+ _logger . LogTrace ( "Incoming settings were null" ) ;
6362 return await Unit . Task . ConfigureAwait ( false ) ;
6463 }
6564
@@ -102,32 +101,30 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
102101 }
103102
104103 // TODO: Load profiles when the host is already running
105-
106- if ( ! this . _cwdSet )
104+ if ( ! _cwdSet )
107105 {
108106 if ( ! string . IsNullOrEmpty ( _configurationService . CurrentSettings . Cwd )
109107 && Directory . Exists ( _configurationService . CurrentSettings . Cwd ) )
110108 {
111- this . _logger . LogTrace ( $ "Setting CWD (from config) to { _configurationService . CurrentSettings . Cwd } ") ;
109+ _logger . LogTrace ( $ "Setting CWD (from config) to { _configurationService . CurrentSettings . Cwd } ") ;
112110 await _psesHost . SetInitialWorkingDirectoryAsync (
113111 _configurationService . CurrentSettings . Cwd ,
114112 CancellationToken . None ) . ConfigureAwait ( false ) ;
115-
116113 }
117- else if ( _workspaceService . WorkspacePath != null
114+ else if ( _workspaceService . WorkspacePath is not null
118115 && Directory . Exists ( _workspaceService . WorkspacePath ) )
119116 {
120- this . _logger . LogTrace ( $ "Setting CWD (from workspace) to { _workspaceService . WorkspacePath } ") ;
117+ _logger . LogTrace ( $ "Setting CWD (from workspace) to { _workspaceService . WorkspacePath } ") ;
121118 await _psesHost . SetInitialWorkingDirectoryAsync (
122119 _workspaceService . WorkspacePath ,
123120 CancellationToken . None ) . ConfigureAwait ( false ) ;
124121 }
125122 else
126123 {
127- this . _logger . LogTrace ( "Tried to set CWD but in bad state" ) ;
124+ _logger . LogTrace ( "Tried to set CWD but in bad state" ) ;
128125 }
129126
130- this . _cwdSet = true ;
127+ _cwdSet = true ;
131128 }
132129
133130 if ( ! _extensionServiceInitialized )
@@ -136,35 +133,46 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
136133 }
137134
138135 // Run any events subscribed to configuration updates
139- this . _logger . LogTrace ( "Running configuration update event handlers" ) ;
136+ _logger . LogTrace ( "Running configuration update event handlers" ) ;
140137 ConfigurationUpdated ? . Invoke ( this , _configurationService . CurrentSettings ) ;
141138
142139 // Convert the editor file glob patterns into an array for the Workspace
143140 // Both the files.exclude and search.exclude hash tables look like (glob-text, is-enabled):
141+ //
144142 // "files.exclude" : {
145143 // "Makefile": true,
146144 // "*.html": true,
145+ // "**/*.js": { "when": "$(basename).ts" },
147146 // "build/*": true
148147 // }
149- var excludeFilePatterns = new List < string > ( ) ;
150- if ( incomingSettings . Files ? . Exclude != null )
148+ //
149+ // TODO: We only support boolean values. The clause predicates are ignored, but perhaps
150+ // they shouldn't be. At least it doesn't crash!
151+ List < string > excludeFilePatterns = new ( ) ;
152+ if ( incomingSettings . Files ? . Exclude is not null )
151153 {
152- foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Files . Exclude )
154+ foreach ( KeyValuePair < string , object > patternEntry in incomingSettings . Files . Exclude )
153155 {
154- if ( patternEntry . Value ) { excludeFilePatterns . Add ( patternEntry . Key ) ; }
156+ if ( patternEntry . Value is bool v && v )
157+ {
158+ excludeFilePatterns . Add ( patternEntry . Key ) ;
159+ }
155160 }
156161 }
157- if ( incomingSettings . Search ? . Exclude != null )
162+ if ( incomingSettings . Search ? . Exclude is not null )
158163 {
159- foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Search . Exclude )
164+ foreach ( KeyValuePair < string , object > patternEntry in incomingSettings . Search . Exclude )
160165 {
161- if ( patternEntry . Value && ! excludeFilePatterns . Contains ( patternEntry . Key ) ) { excludeFilePatterns . Add ( patternEntry . Key ) ; }
166+ if ( patternEntry . Value is bool v && v && ! excludeFilePatterns . Contains ( patternEntry . Key ) )
167+ {
168+ excludeFilePatterns . Add ( patternEntry . Key ) ;
169+ }
162170 }
163171 }
164172 _workspaceService . ExcludeFilesGlob = excludeFilePatterns ;
165173
166174 // Convert the editor file search options to Workspace properties
167- if ( incomingSettings . Search ? . FollowSymlinks != null )
175+ if ( incomingSettings . Search ? . FollowSymlinks is not null )
168176 {
169177 _workspaceService . FollowSymlinks = incomingSettings . Search . FollowSymlinks ;
170178 }
@@ -176,11 +184,11 @@ private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingS
176184 {
177185 if ( incomingSettings is null )
178186 {
179- this . _logger . LogTrace ( "Incoming settings were null" ) ;
187+ _logger . LogTrace ( "Incoming settings were null" ) ;
180188 return ;
181189 }
182190
183- var configChanges = new Dictionary < string , bool > ( ) ;
191+ Dictionary < string , bool > configChanges = new ( ) ;
184192 // Send telemetry if the user opted-out of ScriptAnalysis
185193 if ( incomingSettings . Powershell . ScriptAnalysis . Enable == false &&
186194 _configurationService . CurrentSettings . ScriptAnalysis . Enable != incomingSettings . Powershell . ScriptAnalysis . Enable )
0 commit comments