19
19
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
20
20
using Microsoft . PowerShell . EditorServices . Services . Extension ;
21
21
22
-
23
22
namespace Microsoft . PowerShell . EditorServices . Handlers
24
23
{
25
24
internal class PsesConfigurationHandler : DidChangeConfigurationHandlerBase
@@ -31,7 +30,7 @@ internal class PsesConfigurationHandler : DidChangeConfigurationHandlerBase
31
30
private readonly PsesInternalHost _psesHost ;
32
31
private readonly ILanguageServerFacade _languageServer ;
33
32
private bool _profilesLoaded ;
34
- private bool _extensionServiceInitialized ;
33
+ private readonly bool _extensionServiceInitialized ;
35
34
private bool _cwdSet ;
36
35
37
36
public PsesConfigurationHandler (
@@ -56,10 +55,10 @@ public PsesConfigurationHandler(
56
55
public override async Task < Unit > Handle ( DidChangeConfigurationParams request , CancellationToken cancellationToken )
57
56
{
58
57
LanguageServerSettingsWrapper incomingSettings = request . Settings . ToObject < LanguageServerSettingsWrapper > ( ) ;
59
- this . _logger . LogTrace ( "Handling DidChangeConfiguration" ) ;
58
+ _logger . LogTrace ( "Handling DidChangeConfiguration" ) ;
60
59
if ( incomingSettings is null || incomingSettings . Powershell is null )
61
60
{
62
- this . _logger . LogTrace ( "Incoming settings were null" ) ;
61
+ _logger . LogTrace ( "Incoming settings were null" ) ;
63
62
return await Unit . Task . ConfigureAwait ( false ) ;
64
63
}
65
64
@@ -102,32 +101,31 @@ public override async Task<Unit> Handle(DidChangeConfigurationParams request, Ca
102
101
}
103
102
104
103
// TODO: Load profiles when the host is already running
105
-
106
- if ( ! this . _cwdSet )
104
+ if ( ! _cwdSet )
107
105
{
108
106
if ( ! string . IsNullOrEmpty ( _configurationService . CurrentSettings . Cwd )
109
107
&& Directory . Exists ( _configurationService . CurrentSettings . Cwd ) )
110
108
{
111
- this . _logger . LogTrace ( $ "Setting CWD (from config) to { _configurationService . CurrentSettings . Cwd } ") ;
109
+ _logger . LogTrace ( $ "Setting CWD (from config) to { _configurationService . CurrentSettings . Cwd } ") ;
112
110
await _psesHost . SetInitialWorkingDirectoryAsync (
113
111
_configurationService . CurrentSettings . Cwd ,
114
112
CancellationToken . None ) . ConfigureAwait ( false ) ;
115
113
116
114
}
117
- else if ( _workspaceService . WorkspacePath != null
115
+ else if ( _workspaceService . WorkspacePath is not null
118
116
&& Directory . Exists ( _workspaceService . WorkspacePath ) )
119
117
{
120
- this . _logger . LogTrace ( $ "Setting CWD (from workspace) to { _workspaceService . WorkspacePath } ") ;
118
+ _logger . LogTrace ( $ "Setting CWD (from workspace) to { _workspaceService . WorkspacePath } ") ;
121
119
await _psesHost . SetInitialWorkingDirectoryAsync (
122
120
_workspaceService . WorkspacePath ,
123
121
CancellationToken . None ) . ConfigureAwait ( false ) ;
124
122
}
125
123
else
126
124
{
127
- this . _logger . LogTrace ( "Tried to set CWD but in bad state" ) ;
125
+ _logger . LogTrace ( "Tried to set CWD but in bad state" ) ;
128
126
}
129
127
130
- this . _cwdSet = true ;
128
+ _cwdSet = true ;
131
129
}
132
130
133
131
if ( ! _extensionServiceInitialized )
@@ -136,7 +134,7 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
136
134
}
137
135
138
136
// Run any events subscribed to configuration updates
139
- this . _logger . LogTrace ( "Running configuration update event handlers" ) ;
137
+ _logger . LogTrace ( "Running configuration update event handlers" ) ;
140
138
ConfigurationUpdated ? . Invoke ( this , _configurationService . CurrentSettings ) ;
141
139
142
140
// Convert the editor file glob patterns into an array for the Workspace
@@ -146,25 +144,25 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
146
144
// "*.html": true,
147
145
// "build/*": true
148
146
// }
149
- var excludeFilePatterns = new List < string > ( ) ;
150
- if ( incomingSettings . Files ? . Exclude != null )
147
+ List < string > excludeFilePatterns = new ( ) ;
148
+ if ( incomingSettings . Files ? . Exclude is not null )
151
149
{
152
- foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Files . Exclude )
150
+ foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Files . Exclude )
153
151
{
154
152
if ( patternEntry . Value ) { excludeFilePatterns . Add ( patternEntry . Key ) ; }
155
153
}
156
154
}
157
- if ( incomingSettings . Search ? . Exclude != null )
155
+ if ( incomingSettings . Search ? . Exclude is not null )
158
156
{
159
- foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Search . Exclude )
157
+ foreach ( KeyValuePair < string , bool > patternEntry in incomingSettings . Search . Exclude )
160
158
{
161
159
if ( patternEntry . Value && ! excludeFilePatterns . Contains ( patternEntry . Key ) ) { excludeFilePatterns . Add ( patternEntry . Key ) ; }
162
160
}
163
161
}
164
162
_workspaceService . ExcludeFilesGlob = excludeFilePatterns ;
165
163
166
164
// Convert the editor file search options to Workspace properties
167
- if ( incomingSettings . Search ? . FollowSymlinks != null )
165
+ if ( incomingSettings . Search ? . FollowSymlinks is not null )
168
166
{
169
167
_workspaceService . FollowSymlinks = incomingSettings . Search . FollowSymlinks ;
170
168
}
@@ -176,11 +174,11 @@ private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingS
176
174
{
177
175
if ( incomingSettings is null )
178
176
{
179
- this . _logger . LogTrace ( "Incoming settings were null" ) ;
177
+ _logger . LogTrace ( "Incoming settings were null" ) ;
180
178
return ;
181
179
}
182
180
183
- var configChanges = new Dictionary < string , bool > ( ) ;
181
+ Dictionary < string , bool > configChanges = new ( ) ;
184
182
// Send telemetry if the user opted-out of ScriptAnalysis
185
183
if ( incomingSettings . Powershell . ScriptAnalysis . Enable == false &&
186
184
_configurationService . CurrentSettings . ScriptAnalysis . Enable != incomingSettings . Powershell . ScriptAnalysis . Enable )
0 commit comments