@@ -138,13 +138,13 @@ public void RunScriptDiagnostics(
138
138
ScriptFile [ ] filesToAnalyze ,
139
139
CancellationToken cancellationToken )
140
140
{
141
- EnsureEngineSettingsCurrent ( ) ;
142
-
143
- if ( AnalysisEngine == null )
141
+ if ( _configurationService . CurrentSettings . ScriptAnalysis . Enable == false )
144
142
{
145
143
return ;
146
144
}
147
145
146
+ EnsureEngineSettingsCurrent ( ) ;
147
+
148
148
// Create a cancellation token source that will cancel if we do or if the caller does
149
149
var cancellationSource = CancellationTokenSource . CreateLinkedTokenSource ( cancellationToken ) ;
150
150
@@ -191,12 +191,6 @@ public void RunScriptDiagnostics(
191
191
public Task < string > FormatAsync ( string scriptFileContents , Hashtable formatSettings , int [ ] formatRange = null )
192
192
{
193
193
EnsureEngineSettingsCurrent ( ) ;
194
-
195
- if ( AnalysisEngine == null )
196
- {
197
- return null ;
198
- }
199
-
200
194
return AnalysisEngine . FormatAsync ( scriptFileContents , formatSettings , formatRange ) ;
201
195
}
202
196
@@ -263,32 +257,24 @@ public void ClearMarkers(ScriptFile file)
263
257
/// <param name="settings">The new language server settings.</param>
264
258
public void OnConfigurationUpdated ( object sender , LanguageServerSettings settings )
265
259
{
266
- InitializeAnalysisEngineToCurrentSettings ( ) ;
260
+ if ( settings . ScriptAnalysis . Enable ?? true )
261
+ {
262
+ InitializeAnalysisEngineToCurrentSettings ( ) ;
263
+ }
267
264
}
268
265
269
266
private void EnsureEngineSettingsCurrent ( )
270
267
{
271
- if ( _pssaSettingsFilePath != null
272
- && ! File . Exists ( _pssaSettingsFilePath ) )
268
+ if ( _analysisEngineLazy == null
269
+ || ( _pssaSettingsFilePath != null
270
+ && ! File . Exists ( _pssaSettingsFilePath ) ) )
273
271
{
274
272
InitializeAnalysisEngineToCurrentSettings ( ) ;
275
273
}
276
274
}
277
275
278
276
private void InitializeAnalysisEngineToCurrentSettings ( )
279
277
{
280
- // If script analysis has been disabled, just return null
281
- if ( _configurationService . CurrentSettings . ScriptAnalysis . Enable != true )
282
- {
283
- if ( _analysisEngineLazy != null && _analysisEngineLazy . IsValueCreated )
284
- {
285
- _analysisEngineLazy . Value . Dispose ( ) ;
286
- }
287
-
288
- _analysisEngineLazy = null ;
289
- return ;
290
- }
291
-
292
278
// We may be triggered after the lazy factory is set,
293
279
// but before it's been able to instantiate
294
280
if ( _analysisEngineLazy == null )
@@ -357,7 +343,7 @@ private bool TryFindSettingsFile(out string settingsFilePath)
357
343
if ( settingsFilePath == null
358
344
|| ! File . Exists ( settingsFilePath ) )
359
345
{
360
- _logger . LogWarning ( $ "Unable to find PSSA settings file at '{ configuredPath } '. Loading default rules.") ;
346
+ _logger . LogInformation ( $ "Unable to find PSSA settings file at '{ configuredPath } '. Loading default rules.") ;
361
347
settingsFilePath = null ;
362
348
return false ;
363
349
}
0 commit comments