1212using System . Threading ;
1313using System . Threading . Tasks ;
1414using Microsoft . PowerShell . EditorServices . Handlers ;
15- using Microsoft . PowerShell . EditorServices . Logging ;
1615using Microsoft . PowerShell . EditorServices . Services . Configuration ;
1716using Microsoft . PowerShell . EditorServices . Services . PowerShell ;
1817using Microsoft . PowerShell . EditorServices . Services . Template ;
@@ -40,7 +39,6 @@ public class LanguageServerProtocolMessageTests : IClassFixture<LSPTestsFixture>
4039 private readonly ILanguageClient PsesLanguageClient ;
4140 private readonly List < LogMessageParams > Messages ;
4241 private readonly List < Diagnostic > Diagnostics ;
43- private readonly List < PsesTelemetryEvent > TelemetryEvents ;
4442 private readonly string PwshExe ;
4543
4644 public LanguageServerProtocolMessageTests ( ITestOutputHelper output , LSPTestsFixture data )
@@ -51,15 +49,12 @@ public LanguageServerProtocolMessageTests(ITestOutputHelper output, LSPTestsFixt
5149 Messages . Clear ( ) ;
5250 Diagnostics = data . Diagnostics ;
5351 Diagnostics . Clear ( ) ;
54- TelemetryEvents = data . TelemetryEvents ;
55- TelemetryEvents . Clear ( ) ;
5652 PwshExe = PsesStdioProcess . PwshExe ;
5753 }
5854
5955 public void Dispose ( )
6056 {
6157 Diagnostics . Clear ( ) ;
62- TelemetryEvents . Clear ( ) ;
6358 GC . SuppressFinalize ( this ) ;
6459 }
6560
@@ -91,26 +86,12 @@ private async Task WaitForDiagnosticsAsync()
9186 // Wait for PSSA to finish.
9287 for ( int i = 0 ; Diagnostics . Count == 0 ; i ++ )
9388 {
94- if ( i >= 10 )
89+ if ( i >= 30 )
9590 {
9691 throw new InvalidDataException ( "No diagnostics showed up after 20s." ) ;
9792 }
9893
99- await Task . Delay ( 2000 ) . ConfigureAwait ( true ) ;
100- }
101- }
102-
103- private async Task WaitForTelemetryEventsAsync ( )
104- {
105- // Wait for PSSA to finish.
106- for ( int i = 0 ; TelemetryEvents . Count == 0 ; i ++ )
107- {
108- if ( i >= 10 )
109- {
110- throw new InvalidDataException ( "No telemetry events showed up after 20s." ) ;
111- }
112-
113- await Task . Delay ( 2000 ) . ConfigureAwait ( true ) ;
94+ await Task . Delay ( 1000 ) . ConfigureAwait ( true ) ;
11495 }
11596 }
11697
@@ -233,12 +214,6 @@ public async Task CanReceiveDiagnosticsFromConfigurationChangeAsync()
233214 Skip . If ( PsesStdioProcess . RunningInConstrainedLanguageMode && PsesStdioProcess . IsWindowsPowerShell ,
234215 "Windows PowerShell doesn't trust PSScriptAnalyzer by default so it won't load." ) ;
235216
236- NewTestFile ( "gci | % { $_ }" ) ;
237- await WaitForDiagnosticsAsync ( ) . ConfigureAwait ( true ) ;
238-
239- // NewTestFile doesn't clear diagnostic notifications so we need to do that for this test.
240- Diagnostics . Clear ( ) ;
241-
242217 PsesLanguageClient . SendNotification ( "workspace/didChangeConfiguration" ,
243218 new DidChangeConfigurationParams
244219 {
@@ -256,18 +231,12 @@ public async Task CanReceiveDiagnosticsFromConfigurationChangeAsync()
256231 } )
257232 } ) ;
258233
259- await WaitForTelemetryEventsAsync ( ) . ConfigureAwait ( true ) ;
260- PsesTelemetryEvent telemetryEvent = Assert . Single ( TelemetryEvents ) ;
261- Assert . Equal ( "NonDefaultPsesFeatureConfiguration" , telemetryEvent . EventName ) ;
262- Assert . False ( ( bool ) telemetryEvent . Data . GetValue ( "ScriptAnalysis" ) ) ;
234+ string filePath = NewTestFile ( "$a = 4" ) ;
263235
264- // We also shouldn't get any Diagnostics because ScriptAnalysis is disabled.
236+ // Wait a bit to make sure no diagnostics came through
237+ await Task . Delay ( 2000 ) . ConfigureAwait ( true ) ;
265238 Assert . Empty ( Diagnostics ) ;
266239
267- // Clear telemetry events so we can test to make sure telemetry doesn't
268- // come through with default settings.
269- TelemetryEvents . Clear ( ) ;
270-
271240 // Restore default configuration
272241 PsesLanguageClient . SendNotification ( "workspace/didChangeConfiguration" ,
273242 new DidChangeConfigurationParams
@@ -280,10 +249,22 @@ public async Task CanReceiveDiagnosticsFromConfigurationChangeAsync()
280249 } )
281250 } ) ;
282251
283- // Wait a bit to make sure no telemetry events came through
284- await Task . Delay ( 2000 ) . ConfigureAwait ( true ) ;
285- // Since we have default settings we should not get any telemetry events about
286- Assert . Empty ( TelemetryEvents . Where ( e => e . EventName == "NonDefaultPsesFeatureConfiguration" ) ) ;
252+ // That notification does not trigger re-analyzing open files. For that we have to send
253+ // a textDocument/didChange notification.
254+ PsesLanguageClient . SendNotification ( "textDocument/didChange" , new DidChangeTextDocumentParams
255+ {
256+ ContentChanges = new Container < TextDocumentContentChangeEvent > ( ) ,
257+ TextDocument = new OptionalVersionedTextDocumentIdentifier
258+ {
259+ Version = 4 ,
260+ Uri = new Uri ( filePath )
261+ }
262+ } ) ;
263+
264+ await WaitForDiagnosticsAsync ( ) . ConfigureAwait ( true ) ;
265+
266+ Diagnostic diagnostic = Assert . Single ( Diagnostics ) ;
267+ Assert . Equal ( "PSUseDeclaredVarsMoreThanAssignments" , diagnostic . Code ) ;
287268 }
288269
289270 [ Fact ]
0 commit comments