Skip to content

Commit d061bcf

Browse files
committed
Clean up ConfigurationHandler.cs
1 parent eb47061 commit d061bcf

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
2020
using Microsoft.PowerShell.EditorServices.Services.Extension;
2121

22-
2322
namespace Microsoft.PowerShell.EditorServices.Handlers
2423
{
2524
internal class PsesConfigurationHandler : DidChangeConfigurationHandlerBase
@@ -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,31 @@ 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);
115113

116114
}
117-
else if (_workspaceService.WorkspacePath != null
115+
else if (_workspaceService.WorkspacePath is not null
118116
&& Directory.Exists(_workspaceService.WorkspacePath))
119117
{
120-
this._logger.LogTrace($"Setting CWD (from workspace) to {_workspaceService.WorkspacePath}");
118+
_logger.LogTrace($"Setting CWD (from workspace) to {_workspaceService.WorkspacePath}");
121119
await _psesHost.SetInitialWorkingDirectoryAsync(
122120
_workspaceService.WorkspacePath,
123121
CancellationToken.None).ConfigureAwait(false);
124122
}
125123
else
126124
{
127-
this._logger.LogTrace("Tried to set CWD but in bad state");
125+
_logger.LogTrace("Tried to set CWD but in bad state");
128126
}
129127

130-
this._cwdSet = true;
128+
_cwdSet = true;
131129
}
132130

133131
if (!_extensionServiceInitialized)
@@ -136,7 +134,7 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
136134
}
137135

138136
// Run any events subscribed to configuration updates
139-
this._logger.LogTrace("Running configuration update event handlers");
137+
_logger.LogTrace("Running configuration update event handlers");
140138
ConfigurationUpdated?.Invoke(this, _configurationService.CurrentSettings);
141139

142140
// Convert the editor file glob patterns into an array for the Workspace
@@ -146,25 +144,25 @@ await _psesHost.SetInitialWorkingDirectoryAsync(
146144
// "*.html": true,
147145
// "build/*": true
148146
// }
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)
151149
{
152-
foreach(KeyValuePair<string, bool> patternEntry in incomingSettings.Files.Exclude)
150+
foreach (KeyValuePair<string, bool> patternEntry in incomingSettings.Files.Exclude)
153151
{
154152
if (patternEntry.Value) { excludeFilePatterns.Add(patternEntry.Key); }
155153
}
156154
}
157-
if (incomingSettings.Search?.Exclude != null)
155+
if (incomingSettings.Search?.Exclude is not null)
158156
{
159-
foreach(KeyValuePair<string, bool> patternEntry in incomingSettings.Search.Exclude)
157+
foreach (KeyValuePair<string, bool> patternEntry in incomingSettings.Search.Exclude)
160158
{
161159
if (patternEntry.Value && !excludeFilePatterns.Contains(patternEntry.Key)) { excludeFilePatterns.Add(patternEntry.Key); }
162160
}
163161
}
164162
_workspaceService.ExcludeFilesGlob = excludeFilePatterns;
165163

166164
// Convert the editor file search options to Workspace properties
167-
if (incomingSettings.Search?.FollowSymlinks != null)
165+
if (incomingSettings.Search?.FollowSymlinks is not null)
168166
{
169167
_workspaceService.FollowSymlinks = incomingSettings.Search.FollowSymlinks;
170168
}
@@ -176,11 +174,11 @@ private void SendFeatureChangesTelemetry(LanguageServerSettingsWrapper incomingS
176174
{
177175
if (incomingSettings is null)
178176
{
179-
this._logger.LogTrace("Incoming settings were null");
177+
_logger.LogTrace("Incoming settings were null");
180178
return;
181179
}
182180

183-
var configChanges = new Dictionary<string, bool>();
181+
Dictionary<string, bool> configChanges = new();
184182
// Send telemetry if the user opted-out of ScriptAnalysis
185183
if (incomingSettings.Powershell.ScriptAnalysis.Enable == false &&
186184
_configurationService.CurrentSettings.ScriptAnalysis.Enable != incomingSettings.Powershell.ScriptAnalysis.Enable)

0 commit comments

Comments
 (0)