Skip to content

Commit 4e155bd

Browse files
authored
Merge pull request #328 from PowerShell/kapilmb/fix-markers-analysis-disabled
Show syntax markers even if analysis disabled
2 parents d1ba77b + 6a73ec0 commit 4e155bd

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+16-23
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ protected async Task HandleDidChangeConfigurationNotification(
463463
{
464464
bool oldLoadProfiles = this.currentSettings.EnableProfileLoading;
465465
bool oldScriptAnalysisEnabled =
466-
this.currentSettings.ScriptAnalysis.Enable.HasValue;
466+
this.currentSettings.ScriptAnalysis.Enable.HasValue ? this.currentSettings.ScriptAnalysis.Enable.Value : false ;
467467
string oldScriptAnalysisSettingsPath =
468468
this.currentSettings.ScriptAnalysis.SettingsPath;
469469

@@ -501,14 +501,10 @@ protected async Task HandleDidChangeConfigurationNotification(
501501
}
502502
}
503503

504-
// If script analysis is enabled and the settings file changed get new diagnostic records.
505-
if (this.currentSettings.ScriptAnalysis.Enable.Value && settingsPathChanged)
506-
{
507-
await this.RunScriptDiagnostics(
508-
this.editorSession.Workspace.GetOpenedFiles(),
509-
this.editorSession,
510-
eventContext);
511-
}
504+
await this.RunScriptDiagnostics(
505+
this.editorSession.Workspace.GetOpenedFiles(),
506+
this.editorSession,
507+
eventContext);
512508
}
513509
}
514510

@@ -1078,12 +1074,6 @@ private Task RunScriptDiagnostics(
10781074
EditorSession editorSession,
10791075
Func<EventType<PublishDiagnosticsNotification>, PublishDiagnosticsNotification, Task> eventSender)
10801076
{
1081-
if (!this.currentSettings.ScriptAnalysis.Enable.Value)
1082-
{
1083-
// If the user has disabled script analysis, skip it entirely
1084-
return Task.FromResult(true);
1085-
}
1086-
10871077
// If there's an existing task, attempt to cancel it
10881078
try
10891079
{
@@ -1122,6 +1112,7 @@ private Task RunScriptDiagnostics(
11221112
DelayThenInvokeDiagnostics(
11231113
750,
11241114
filesToAnalyze,
1115+
this.currentSettings.ScriptAnalysis.Enable.Value,
11251116
this.codeActionsPerFile,
11261117
editorSession,
11271118
eventSender,
@@ -1133,10 +1124,10 @@ private Task RunScriptDiagnostics(
11331124
return Task.FromResult(true);
11341125
}
11351126

1136-
11371127
private static async Task DelayThenInvokeDiagnostics(
11381128
int delayMilliseconds,
11391129
ScriptFile[] filesToAnalyze,
1130+
bool isScriptAnalysisEnabled,
11401131
Dictionary<string, Dictionary<string, MarkerCorrection>> correctionIndex,
11411132
EditorSession editorSession,
11421133
EventContext eventContext,
@@ -1145,6 +1136,7 @@ private static async Task DelayThenInvokeDiagnostics(
11451136
await DelayThenInvokeDiagnostics(
11461137
delayMilliseconds,
11471138
filesToAnalyze,
1139+
isScriptAnalysisEnabled,
11481140
correctionIndex,
11491141
editorSession,
11501142
eventContext.SendEvent,
@@ -1155,6 +1147,7 @@ await DelayThenInvokeDiagnostics(
11551147
private static async Task DelayThenInvokeDiagnostics(
11561148
int delayMilliseconds,
11571149
ScriptFile[] filesToAnalyze,
1150+
bool isScriptAnalysisEnabled,
11581151
Dictionary<string, Dictionary<string, MarkerCorrection>> correctionIndex,
11591152
EditorSession editorSession,
11601153
Func<EventType<PublishDiagnosticsNotification>, PublishDiagnosticsNotification, Task> eventSender,
@@ -1183,7 +1176,7 @@ private static async Task DelayThenInvokeDiagnostics(
11831176
foreach (ScriptFile scriptFile in filesToAnalyze)
11841177
{
11851178
ScriptFileMarker[] semanticMarkers = null;
1186-
if (editorSession.AnalysisService != null)
1179+
if (isScriptAnalysisEnabled && editorSession.AnalysisService != null)
11871180
{
11881181
Logger.Write(LogLevel.Verbose, "Analyzing script file: " + scriptFile.FilePath);
11891182

@@ -1199,10 +1192,10 @@ private static async Task DelayThenInvokeDiagnostics(
11991192
// isn't available
12001193
semanticMarkers = new ScriptFileMarker[0];
12011194
}
1202-
var allMarkers = scriptFile.SyntaxMarkers.Concat(semanticMarkers);
1195+
12031196
await PublishScriptDiagnostics(
12041197
scriptFile,
1205-
semanticMarkers,
1198+
scriptFile.SyntaxMarkers.Concat(semanticMarkers).ToArray(),
12061199
correctionIndex,
12071200
eventSender);
12081201
}
@@ -1220,20 +1213,20 @@ await PublishScriptDiagnostics(
12201213

12211214
private static async Task PublishScriptDiagnostics(
12221215
ScriptFile scriptFile,
1223-
ScriptFileMarker[] semanticMarkers,
1216+
ScriptFileMarker[] markers,
12241217
Dictionary<string, Dictionary<string, MarkerCorrection>> correctionIndex,
12251218
EventContext eventContext)
12261219
{
12271220
await PublishScriptDiagnostics(
12281221
scriptFile,
1229-
semanticMarkers,
1222+
markers,
12301223
correctionIndex,
12311224
eventContext.SendEvent);
12321225
}
12331226

12341227
private static async Task PublishScriptDiagnostics(
12351228
ScriptFile scriptFile,
1236-
ScriptFileMarker[] semanticMarkers,
1229+
ScriptFileMarker[] markers,
12371230
Dictionary<string, Dictionary<string, MarkerCorrection>> correctionIndex,
12381231
Func<EventType<PublishDiagnosticsNotification>, PublishDiagnosticsNotification, Task> eventSender)
12391232
{
@@ -1243,7 +1236,7 @@ private static async Task PublishScriptDiagnostics(
12431236
Dictionary<string, MarkerCorrection> fileCorrections =
12441237
new Dictionary<string, MarkerCorrection>();
12451238

1246-
foreach (var marker in scriptFile.SyntaxMarkers.Concat(semanticMarkers))
1239+
foreach (var marker in markers)
12471240
{
12481241
// Does the marker contain a correction?
12491242
Diagnostic markerDiagnostic = GetDiagnosticFromMarker(marker);

0 commit comments

Comments
 (0)