@@ -138,13 +138,13 @@ public void RunScriptDiagnostics(
138138 ScriptFile [ ] filesToAnalyze ,
139139 CancellationToken cancellationToken )
140140 {
141- EnsureEngineSettingsCurrent ( ) ;
142-
143- if ( AnalysisEngine == null )
141+ if ( _configurationService . CurrentSettings . ScriptAnalysis . Enable == false )
144142 {
145143 return ;
146144 }
147145
146+ EnsureEngineSettingsCurrent ( ) ;
147+
148148 // Create a cancellation token source that will cancel if we do or if the caller does
149149 var cancellationSource = CancellationTokenSource . CreateLinkedTokenSource ( cancellationToken ) ;
150150
@@ -191,12 +191,6 @@ public void RunScriptDiagnostics(
191191 public Task < string > FormatAsync ( string scriptFileContents , Hashtable formatSettings , int [ ] formatRange = null )
192192 {
193193 EnsureEngineSettingsCurrent ( ) ;
194-
195- if ( AnalysisEngine == null )
196- {
197- return null ;
198- }
199-
200194 return AnalysisEngine . FormatAsync ( scriptFileContents , formatSettings , formatRange ) ;
201195 }
202196
@@ -263,32 +257,24 @@ public void ClearMarkers(ScriptFile file)
263257 /// <param name="settings">The new language server settings.</param>
264258 public void OnConfigurationUpdated ( object sender , LanguageServerSettings settings )
265259 {
266- InitializeAnalysisEngineToCurrentSettings ( ) ;
260+ if ( settings . ScriptAnalysis . Enable ?? true )
261+ {
262+ InitializeAnalysisEngineToCurrentSettings ( ) ;
263+ }
267264 }
268265
269266 private void EnsureEngineSettingsCurrent ( )
270267 {
271- if ( _pssaSettingsFilePath != null
272- && ! File . Exists ( _pssaSettingsFilePath ) )
268+ if ( _analysisEngineLazy == null
269+ || ( _pssaSettingsFilePath != null
270+ && ! File . Exists ( _pssaSettingsFilePath ) ) )
273271 {
274272 InitializeAnalysisEngineToCurrentSettings ( ) ;
275273 }
276274 }
277275
278276 private void InitializeAnalysisEngineToCurrentSettings ( )
279277 {
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-
292278 // We may be triggered after the lazy factory is set,
293279 // but before it's been able to instantiate
294280 if ( _analysisEngineLazy == null )
@@ -357,7 +343,7 @@ private bool TryFindSettingsFile(out string settingsFilePath)
357343 if ( settingsFilePath == null
358344 || ! File . Exists ( settingsFilePath ) )
359345 {
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.") ;
361347 settingsFilePath = null ;
362348 return false ;
363349 }
0 commit comments