Skip to content

Commit b9c428a

Browse files
authored
Make AnalysisService use the latest version of PSScriptAnalyzer (#677)
* Use latest version of PSSA for AnalysisService * Make AnalysisService constructor private * Refactor redundant code * Make AnalysisService absorb all exceptions it generates * Address @tylerl0706's feedback, convert logging to string builder, implement dispose pattern * Update disposal methods
1 parent f035aed commit b9c428a

File tree

7 files changed

+273
-144
lines changed

7 files changed

+273
-144
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ protected async Task HandleDidChangeConfigurationNotification(
575575
bool oldScriptAnalysisEnabled =
576576
this.currentSettings.ScriptAnalysis.Enable.HasValue ? this.currentSettings.ScriptAnalysis.Enable.Value : false;
577577
string oldScriptAnalysisSettingsPath =
578-
this.currentSettings.ScriptAnalysis.SettingsPath;
578+
this.currentSettings.ScriptAnalysis?.SettingsPath;
579579

580580
this.currentSettings.Update(
581581
configChangeParams.Settings.Powershell,
@@ -604,12 +604,15 @@ protected async Task HandleDidChangeConfigurationNotification(
604604
string newSettingsPath = this.currentSettings.ScriptAnalysis.SettingsPath;
605605
if (!string.Equals(oldScriptAnalysisSettingsPath, newSettingsPath, StringComparison.OrdinalIgnoreCase))
606606
{
607-
this.editorSession.AnalysisService.SettingsPath = newSettingsPath;
608-
settingsPathChanged = true;
607+
if (this.editorSession.AnalysisService != null)
608+
{
609+
this.editorSession.AnalysisService.SettingsPath = newSettingsPath;
610+
settingsPathChanged = true;
611+
}
609612
}
610613

611614
// If script analysis settings have changed we need to clear & possibly update the current diagnostic records.
612-
if ((oldScriptAnalysisEnabled != this.currentSettings.ScriptAnalysis.Enable) || settingsPathChanged)
615+
if ((oldScriptAnalysisEnabled != this.currentSettings.ScriptAnalysis?.Enable) || settingsPathChanged)
613616
{
614617
// If the user just turned off script analysis or changed the settings path, send a diagnostics
615618
// event to clear the analysis markers that they already have.
@@ -1443,7 +1446,7 @@ private Task RunScriptDiagnostics(
14431446
DelayThenInvokeDiagnostics(
14441447
750,
14451448
filesToAnalyze,
1446-
this.currentSettings.ScriptAnalysis.Enable.Value,
1449+
this.currentSettings.ScriptAnalysis?.Enable.Value ?? false,
14471450
this.codeActionsPerFile,
14481451
editorSession,
14491452
eventSender,

0 commit comments

Comments
 (0)