12
12
using System . Threading ;
13
13
using System . Threading . Tasks ;
14
14
using Microsoft . PowerShell . EditorServices . Handlers ;
15
- using Microsoft . PowerShell . EditorServices . Logging ;
16
15
using Microsoft . PowerShell . EditorServices . Services . Configuration ;
17
16
using Microsoft . PowerShell . EditorServices . Services . PowerShell ;
18
17
using Microsoft . PowerShell . EditorServices . Services . Template ;
@@ -40,7 +39,6 @@ public class LanguageServerProtocolMessageTests : IClassFixture<LSPTestsFixture>
40
39
private readonly ILanguageClient PsesLanguageClient ;
41
40
private readonly List < LogMessageParams > Messages ;
42
41
private readonly List < Diagnostic > Diagnostics ;
43
- private readonly List < PsesTelemetryEvent > TelemetryEvents ;
44
42
private readonly string PwshExe ;
45
43
46
44
public LanguageServerProtocolMessageTests ( ITestOutputHelper output , LSPTestsFixture data )
@@ -51,15 +49,12 @@ public LanguageServerProtocolMessageTests(ITestOutputHelper output, LSPTestsFixt
51
49
Messages . Clear ( ) ;
52
50
Diagnostics = data . Diagnostics ;
53
51
Diagnostics . Clear ( ) ;
54
- TelemetryEvents = data . TelemetryEvents ;
55
- TelemetryEvents . Clear ( ) ;
56
52
PwshExe = PsesStdioProcess . PwshExe ;
57
53
}
58
54
59
55
public void Dispose ( )
60
56
{
61
57
Diagnostics . Clear ( ) ;
62
- TelemetryEvents . Clear ( ) ;
63
58
GC . SuppressFinalize ( this ) ;
64
59
}
65
60
@@ -91,26 +86,12 @@ private async Task WaitForDiagnosticsAsync()
91
86
// Wait for PSSA to finish.
92
87
for ( int i = 0 ; Diagnostics . Count == 0 ; i ++ )
93
88
{
94
- if ( i >= 10 )
89
+ if ( i >= 30 )
95
90
{
96
91
throw new InvalidDataException ( "No diagnostics showed up after 20s." ) ;
97
92
}
98
93
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 ) ;
114
95
}
115
96
}
116
97
@@ -233,12 +214,6 @@ public async Task CanReceiveDiagnosticsFromConfigurationChangeAsync()
233
214
Skip . If ( PsesStdioProcess . RunningInConstrainedLanguageMode && PsesStdioProcess . IsWindowsPowerShell ,
234
215
"Windows PowerShell doesn't trust PSScriptAnalyzer by default so it won't load." ) ;
235
216
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
-
242
217
PsesLanguageClient . SendNotification ( "workspace/didChangeConfiguration" ,
243
218
new DidChangeConfigurationParams
244
219
{
@@ -256,18 +231,12 @@ public async Task CanReceiveDiagnosticsFromConfigurationChangeAsync()
256
231
} )
257
232
} ) ;
258
233
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" ) ;
263
235
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 ) ;
265
238
Assert . Empty ( Diagnostics ) ;
266
239
267
- // Clear telemetry events so we can test to make sure telemetry doesn't
268
- // come through with default settings.
269
- TelemetryEvents . Clear ( ) ;
270
-
271
240
// Restore default configuration
272
241
PsesLanguageClient . SendNotification ( "workspace/didChangeConfiguration" ,
273
242
new DidChangeConfigurationParams
@@ -280,10 +249,22 @@ public async Task CanReceiveDiagnosticsFromConfigurationChangeAsync()
280
249
} )
281
250
} ) ;
282
251
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 ) ;
287
268
}
288
269
289
270
[ Fact ]
0 commit comments