@@ -15,78 +15,61 @@ namespace Microsoft.PowerShell.EditorServices.Services.Configuration
15
15
{
16
16
internal class LanguageServerSettings
17
17
{
18
- private readonly object updateLock = new object ( ) ;
19
-
20
- public bool EnableProfileLoading { get ; set ; } = false ;
21
-
18
+ private readonly object updateLock = new ( ) ;
19
+ public bool EnableProfileLoading { get ; set ; }
22
20
public bool PromptToUpdatePackageManagement { get ; set ; } = true ;
23
-
24
21
public ScriptAnalysisSettings ScriptAnalysis { get ; set ; }
25
-
26
22
public CodeFormattingSettings CodeFormatting { get ; set ; }
27
-
28
23
public CodeFoldingSettings CodeFolding { get ; set ; }
29
-
30
24
public PesterSettings Pester { get ; set ; }
31
-
32
25
public string Cwd { get ; set ; }
33
26
34
27
public LanguageServerSettings ( )
35
28
{
36
- this . ScriptAnalysis = new ScriptAnalysisSettings ( ) ;
37
- this . CodeFormatting = new CodeFormattingSettings ( ) ;
38
- this . CodeFolding = new CodeFoldingSettings ( ) ;
39
- this . Pester = new PesterSettings ( ) ;
29
+ ScriptAnalysis = new ScriptAnalysisSettings ( ) ;
30
+ CodeFormatting = new CodeFormattingSettings ( ) ;
31
+ CodeFolding = new CodeFoldingSettings ( ) ;
32
+ Pester = new PesterSettings ( ) ;
40
33
}
41
34
42
35
public void Update (
43
36
LanguageServerSettings settings ,
44
37
string workspaceRootPath ,
45
38
ILogger logger )
46
39
{
47
- if ( settings != null )
40
+ if ( settings is not null )
48
41
{
49
42
lock ( updateLock )
50
43
{
51
- this . EnableProfileLoading = settings . EnableProfileLoading ;
52
- this . PromptToUpdatePackageManagement = settings . PromptToUpdatePackageManagement ;
53
- this . ScriptAnalysis . Update (
54
- settings . ScriptAnalysis ,
55
- workspaceRootPath ,
56
- logger ) ;
57
- this . CodeFormatting = new CodeFormattingSettings ( settings . CodeFormatting ) ;
58
- this . CodeFolding . Update ( settings . CodeFolding , logger ) ;
59
- this . Pester . Update ( settings . Pester , logger ) ;
60
- this . Cwd = settings . Cwd ;
44
+ EnableProfileLoading = settings . EnableProfileLoading ;
45
+ PromptToUpdatePackageManagement = settings . PromptToUpdatePackageManagement ;
46
+ ScriptAnalysis . Update ( settings . ScriptAnalysis , workspaceRootPath , logger ) ;
47
+ CodeFormatting = new CodeFormattingSettings ( settings . CodeFormatting ) ;
48
+ CodeFolding . Update ( settings . CodeFolding , logger ) ;
49
+ Pester . Update ( settings . Pester , logger ) ;
50
+ Cwd = settings . Cwd ;
61
51
}
62
52
}
63
53
}
64
54
}
65
55
66
56
internal class ScriptAnalysisSettings
67
57
{
68
- private readonly object updateLock = new object ( ) ;
69
-
58
+ private readonly object updateLock = new ( ) ;
70
59
public bool ? Enable { get ; set ; }
71
-
72
60
public string SettingsPath { get ; set ; }
73
-
74
- public ScriptAnalysisSettings ( )
75
- {
76
- this . Enable = true ;
77
- }
61
+ public ScriptAnalysisSettings ( ) { Enable = true ; }
78
62
79
63
public void Update (
80
64
ScriptAnalysisSettings settings ,
81
65
string workspaceRootPath ,
82
66
ILogger logger )
83
67
{
84
- if ( settings != null )
68
+ if ( settings is not null )
85
69
{
86
- lock ( updateLock )
70
+ lock ( updateLock )
87
71
{
88
- this . Enable = settings . Enable ;
89
-
72
+ Enable = settings . Enable ;
90
73
string settingsPath = settings . SettingsPath ;
91
74
92
75
try
@@ -105,29 +88,22 @@ public void Update(
105
88
// In this case we should just log an error and let
106
89
// the specified settings path go through even though
107
90
// it will fail to load.
108
- logger . LogError (
109
- "Could not resolve Script Analyzer settings path due to null or empty workspaceRootPath." ) ;
91
+ logger . LogError ( "Could not resolve Script Analyzer settings path due to null or empty workspaceRootPath." ) ;
110
92
}
111
93
else
112
94
{
113
95
settingsPath = Path . GetFullPath ( Path . Combine ( workspaceRootPath , settingsPath ) ) ;
114
96
}
115
97
}
116
98
117
- this . SettingsPath = settingsPath ;
99
+ SettingsPath = settingsPath ;
118
100
logger . LogTrace ( $ "Using Script Analyzer settings path - '{ settingsPath ?? "" } '.") ;
119
101
}
120
- catch ( Exception ex ) when (
121
- ex is NotSupportedException ||
122
- ex is PathTooLongException ||
123
- ex is SecurityException )
102
+ catch ( Exception ex ) when ( ex is NotSupportedException or PathTooLongException or SecurityException )
124
103
{
125
104
// Invalid chars in path like ${env:HOME} can cause Path.GetFullPath() to throw, catch such errors here
126
- logger . LogException (
127
- $ "Invalid Script Analyzer settings path - '{ settingsPath } '.",
128
- ex ) ;
129
-
130
- this . SettingsPath = null ;
105
+ logger . LogException ( $ "Invalid Script Analyzer settings path - '{ settingsPath } '.", ex ) ;
106
+ SettingsPath = null ;
131
107
}
132
108
}
133
109
}
@@ -192,22 +168,20 @@ internal class CodeFormattingSettings
192
168
/// <summary>
193
169
/// Default constructor.
194
170
/// </summary>>
195
- public CodeFormattingSettings ( )
196
- {
197
- }
171
+ public CodeFormattingSettings ( ) { }
198
172
199
173
/// <summary>
200
174
/// Copy constructor.
201
175
/// </summary>
202
176
/// <param name="codeFormattingSettings">An instance of type CodeFormattingSettings.</param>
203
177
public CodeFormattingSettings ( CodeFormattingSettings codeFormattingSettings )
204
178
{
205
- if ( codeFormattingSettings == null )
179
+ if ( codeFormattingSettings is null )
206
180
{
207
181
throw new ArgumentNullException ( nameof ( codeFormattingSettings ) ) ;
208
182
}
209
183
210
- foreach ( var prop in this . GetType ( ) . GetProperties ( BindingFlags . Public | BindingFlags . Instance ) )
184
+ foreach ( PropertyInfo prop in GetType ( ) . GetProperties ( BindingFlags . Public | BindingFlags . Instance ) )
211
185
{
212
186
prop . SetValue ( this , prop . GetValue ( codeFormattingSettings ) ) ;
213
187
}
@@ -226,29 +200,28 @@ public CodeFormattingSettings(CodeFormattingSettings codeFormattingSettings)
226
200
public bool WhitespaceBeforeOpenParen { get ; set ; }
227
201
public bool WhitespaceAroundOperator { get ; set ; }
228
202
public bool WhitespaceAfterSeparator { get ; set ; }
229
- public bool WhitespaceBetweenParameters { get ; set ; }
203
+ public bool WhitespaceBetweenParameters { get ; set ; }
230
204
public bool WhitespaceInsideBrace { get ; set ; }
231
205
public bool IgnoreOneLineBlock { get ; set ; }
232
206
public bool AlignPropertyValuePairs { get ; set ; }
233
207
public bool UseCorrectCasing { get ; set ; }
234
208
235
-
236
209
/// <summary>
237
210
/// Get the settings hashtable that will be consumed by PSScriptAnalyzer.
238
211
/// </summary>
239
212
/// <param name="tabSize">The tab size in the number spaces.</param>
240
213
/// <param name="insertSpaces">If true, insert spaces otherwise insert tabs for indentation.</param>
241
- /// <returns></returns>
242
214
public Hashtable GetPSSASettingsHashtable (
243
215
int tabSize ,
244
216
bool insertSpaces ,
245
217
ILogger logger )
246
218
{
247
- var settings = GetCustomPSSASettingsHashtable ( tabSize , insertSpaces ) ;
248
- var ruleSettings = ( Hashtable ) ( settings [ "Rules" ] ) ;
249
- var closeBraceSettings = ( Hashtable ) ruleSettings [ "PSPlaceCloseBrace" ] ;
250
- var openBraceSettings = ( Hashtable ) ruleSettings [ "PSPlaceOpenBrace" ] ;
251
- switch ( Preset )
219
+ Hashtable settings = GetCustomPSSASettingsHashtable ( tabSize , insertSpaces ) ;
220
+ Hashtable ruleSettings = settings [ "Rules" ] as Hashtable ;
221
+ Hashtable closeBraceSettings = ruleSettings [ "PSPlaceCloseBrace" ] as Hashtable ;
222
+ Hashtable openBraceSettings = ruleSettings [ "PSPlaceOpenBrace" ] as Hashtable ;
223
+
224
+ switch ( Preset )
252
225
{
253
226
case CodeFormattingPreset . Allman :
254
227
openBraceSettings [ "OnSameLine" ] = false ;
@@ -268,6 +241,7 @@ public Hashtable GetPSSASettingsHashtable(
268
241
closeBraceSettings [ "NewLineAfter" ] = true ;
269
242
break ;
270
243
244
+ case CodeFormattingPreset . Custom :
271
245
default :
272
246
break ;
273
247
}
@@ -278,7 +252,7 @@ public Hashtable GetPSSASettingsHashtable(
278
252
279
253
private Hashtable GetCustomPSSASettingsHashtable ( int tabSize , bool insertSpaces )
280
254
{
281
- var ruleConfigurations = new Hashtable
255
+ Hashtable ruleConfigurations = new ( )
282
256
{
283
257
{ "PSPlaceOpenBrace" , new Hashtable {
284
258
{ "Enable" , true } ,
@@ -337,8 +311,7 @@ private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces)
337
311
"PSAlignAssignmentStatement" ,
338
312
"PSAvoidUsingDoubleQuotesForConstantString" ,
339
313
} } ,
340
- {
341
- "Rules" , ruleConfigurations
314
+ { "Rules" , ruleConfigurations
342
315
}
343
316
} ;
344
317
}
@@ -366,14 +339,17 @@ public void Update(
366
339
CodeFoldingSettings settings ,
367
340
ILogger logger )
368
341
{
369
- if ( settings != null ) {
370
- if ( this . Enable != settings . Enable ) {
371
- this . Enable = settings . Enable ;
372
- logger . LogTrace ( string . Format ( "Using Code Folding Enabled - {0}" , this . Enable ) ) ;
342
+ if ( settings is not null )
343
+ {
344
+ if ( Enable != settings . Enable )
345
+ {
346
+ Enable = settings . Enable ;
347
+ logger . LogTrace ( string . Format ( "Using Code Folding Enabled - {0}" , Enable ) ) ;
373
348
}
374
- if ( this . ShowLastLine != settings . ShowLastLine ) {
375
- this . ShowLastLine = settings . ShowLastLine ;
376
- logger . LogTrace ( string . Format ( "Using Code Folding ShowLastLine - {0}" , this . ShowLastLine ) ) ;
349
+ if ( ShowLastLine != settings . ShowLastLine )
350
+ {
351
+ ShowLastLine = settings . ShowLastLine ;
352
+ logger . LogTrace ( string . Format ( "Using Code Folding ShowLastLine - {0}" , ShowLastLine ) ) ;
377
353
}
378
354
}
379
355
}
@@ -401,20 +377,21 @@ public void Update(
401
377
PesterSettings settings ,
402
378
ILogger logger )
403
379
{
404
- if ( settings is null ) {
380
+ if ( settings is null )
381
+ {
405
382
return ;
406
383
}
407
384
408
- if ( this . CodeLens != settings . CodeLens )
385
+ if ( CodeLens != settings . CodeLens )
409
386
{
410
- this . CodeLens = settings . CodeLens ;
411
- logger . LogTrace ( string . Format ( "Using Pester Code Lens - {0}" , this . CodeLens ) ) ;
387
+ CodeLens = settings . CodeLens ;
388
+ logger . LogTrace ( string . Format ( "Using Pester Code Lens - {0}" , CodeLens ) ) ;
412
389
}
413
390
414
- if ( this . UseLegacyCodeLens != settings . UseLegacyCodeLens )
391
+ if ( UseLegacyCodeLens != settings . UseLegacyCodeLens )
415
392
{
416
- this . UseLegacyCodeLens = settings . UseLegacyCodeLens ;
417
- logger . LogTrace ( string . Format ( "Using Pester Legacy Code Lens - {0}" , this . UseLegacyCodeLens ) ) ;
393
+ UseLegacyCodeLens = settings . UseLegacyCodeLens ;
394
+ logger . LogTrace ( string . Format ( "Using Pester Legacy Code Lens - {0}" , UseLegacyCodeLens ) ) ;
418
395
}
419
396
}
420
397
}
0 commit comments