@@ -25,6 +25,7 @@ internal class LanguageServer : IMessageProcessor
25
25
private static CancellationTokenSource existingRequestCancellation ;
26
26
27
27
private MessageDispatcher < EditorSession > messageDispatcher ;
28
+ private LanguageServerSettings currentSettings = new LanguageServerSettings ( ) ;
28
29
29
30
public LanguageServer ( )
30
31
{
@@ -42,6 +43,7 @@ public void Initialize()
42
43
this . AddEventHandler ( DidOpenTextDocumentNotification . Type , this . HandleDidOpenTextDocumentNotification ) ;
43
44
this . AddEventHandler ( DidCloseTextDocumentNotification . Type , this . HandleDidCloseTextDocumentNotification ) ;
44
45
this . AddEventHandler ( DidChangeTextDocumentNotification . Type , this . HandleDidChangeTextDocumentNotification ) ;
46
+ this . AddEventHandler ( DidChangeConfigurationNotification < SettingsWrapper > . Type , this . HandleDidChangeConfigurationNotification ) ;
45
47
46
48
this . AddRequestHandler ( DefinitionRequest . Type , this . HandleDefinitionRequest ) ;
47
49
this . AddRequestHandler ( ReferencesRequest . Type , this . HandleReferencesRequest ) ;
@@ -226,6 +228,36 @@ protected Task HandleDidChangeTextDocumentNotification(
226
228
return Task . FromResult ( true ) ;
227
229
}
228
230
231
+ protected async Task HandleDidChangeConfigurationNotification (
232
+ DidChangeConfigurationParams < SettingsWrapper > configChangeParams ,
233
+ EditorSession editorSession ,
234
+ EventContext eventContext )
235
+ {
236
+ bool oldScriptAnalysisEnabled =
237
+ this . currentSettings . ScriptAnalysis . Enable . HasValue ;
238
+
239
+ this . currentSettings . Update (
240
+ configChangeParams . Settings . Powershell ) ;
241
+
242
+ if ( oldScriptAnalysisEnabled != this . currentSettings . ScriptAnalysis . Enable )
243
+ {
244
+ // If the user just turned off script analysis, send a diagnostics
245
+ // event to clear the analysis markers that they already have
246
+ if ( ! this . currentSettings . ScriptAnalysis . Enable . Value )
247
+ {
248
+ ScriptFileMarker [ ] emptyAnalysisDiagnostics = new ScriptFileMarker [ 0 ] ;
249
+
250
+ foreach ( var scriptFile in editorSession . Workspace . GetOpenedFiles ( ) )
251
+ {
252
+ await PublishScriptDiagnostics (
253
+ scriptFile ,
254
+ emptyAnalysisDiagnostics ,
255
+ eventContext ) ;
256
+ }
257
+ }
258
+ }
259
+ }
260
+
229
261
protected async Task HandleDefinitionRequest (
230
262
TextDocumentPosition textDocumentPosition ,
231
263
EditorSession editorSession ,
@@ -744,6 +776,12 @@ private Task RunScriptDiagnostics(
744
776
EditorSession editorSession ,
745
777
EventContext eventContext )
746
778
{
779
+ if ( ! this . currentSettings . ScriptAnalysis . Enable . Value )
780
+ {
781
+ // If the user has disabled script analysis, skip it entirely
782
+ return TaskConstants . Completed ;
783
+ }
784
+
747
785
// If there's an existing task, attempt to cancel it
748
786
try
749
787
{
@@ -827,24 +865,36 @@ private static async Task DelayThenInvokeDiagnostics(
827
865
828
866
var allMarkers = scriptFile . SyntaxMarkers . Concat ( semanticMarkers ) ;
829
867
830
- // Always send syntax and semantic errors. We want to
831
- // make sure no out-of-date markers are being displayed.
832
- await eventContext . SendEvent (
833
- PublishDiagnosticsNotification . Type ,
834
- new PublishDiagnosticsNotification
835
- {
836
- Uri = scriptFile . ClientFilePath ,
837
- Diagnostics =
838
- allMarkers
839
- . Select ( GetDiagnosticFromMarker )
840
- . ToArray ( )
841
- } ) ;
842
-
868
+ await PublishScriptDiagnostics (
869
+ scriptFile ,
870
+ semanticMarkers ,
871
+ eventContext ) ;
843
872
}
844
873
845
874
Logger . Write ( LogLevel . Verbose , "Analysis complete." ) ;
846
875
}
847
876
877
+ private async static Task PublishScriptDiagnostics (
878
+ ScriptFile scriptFile ,
879
+ ScriptFileMarker [ ] semanticMarkers ,
880
+ EventContext eventContext )
881
+ {
882
+ var allMarkers = scriptFile . SyntaxMarkers . Concat ( semanticMarkers ) ;
883
+
884
+ // Always send syntax and semantic errors. We want to
885
+ // make sure no out-of-date markers are being displayed.
886
+ await eventContext . SendEvent (
887
+ PublishDiagnosticsNotification . Type ,
888
+ new PublishDiagnosticsNotification
889
+ {
890
+ Uri = scriptFile . ClientFilePath ,
891
+ Diagnostics =
892
+ allMarkers
893
+ . Select ( GetDiagnosticFromMarker )
894
+ . ToArray ( )
895
+ } ) ;
896
+ }
897
+
848
898
private static Diagnostic GetDiagnosticFromMarker ( ScriptFileMarker scriptFileMarker )
849
899
{
850
900
return new Diagnostic
0 commit comments