File tree 2 files changed +39
-7
lines changed
src/PowerShellEditorServices/Services/TextDocument/Handlers
test/PowerShellEditorServices.Test.E2E
2 files changed +39
-7
lines changed Original file line number Diff line number Diff line change 4
4
//
5
5
6
6
using System ;
7
- using System . Collections . Generic ;
8
7
using System . Threading ;
9
8
using System . Threading . Tasks ;
10
9
using Microsoft . Extensions . Logging ;
@@ -52,23 +51,19 @@ public TextDocumentHandler(
52
51
53
52
public Task < Unit > Handle ( DidChangeTextDocumentParams notification , CancellationToken token )
54
53
{
55
- List < ScriptFile > changedFiles = new List < ScriptFile > ( ) ;
54
+ ScriptFile changedFile = _workspaceService . GetFile ( notification . TextDocument . Uri . ToString ( ) ) ;
56
55
57
56
// A text change notification can batch multiple change requests
58
57
foreach ( TextDocumentContentChangeEvent textChange in notification . ContentChanges )
59
58
{
60
- ScriptFile changedFile = _workspaceService . GetFile ( notification . TextDocument . Uri . ToString ( ) ) ;
61
-
62
59
changedFile . ApplyChange (
63
60
GetFileChangeDetails (
64
61
textChange . Range ,
65
62
textChange . Text ) ) ;
66
-
67
- changedFiles . Add ( changedFile ) ;
68
63
}
69
64
70
65
// TODO: Get all recently edited files in the workspace
71
- _analysisService . RunScriptDiagnosticsAsync ( changedFiles . ToArray ( ) ) ;
66
+ _analysisService . RunScriptDiagnosticsAsync ( new ScriptFile [ ] { changedFile } ) ;
72
67
return Unit . Task ;
73
68
}
74
69
Original file line number Diff line number Diff line change @@ -145,6 +145,43 @@ public async Task CanReceiveDiagnosticsFromFileOpen()
145
145
Assert . Equal ( "PSUseDeclaredVarsMoreThanAssignments" , diagnostic . Code ) ;
146
146
}
147
147
148
+ [ Fact ]
149
+ public async Task CanReceiveDiagnosticsFromFileChanged ( )
150
+ {
151
+ string filePath = NewTestFile ( "$a = 4" ) ;
152
+ await WaitForDiagnostics ( ) ;
153
+ Diagnostics . Clear ( ) ;
154
+
155
+ LanguageClient . SendNotification ( "textDocument/didChange" , new DidChangeTextDocumentParams
156
+ {
157
+ // Include several content changes to test against duplicate Diagnostics showing up.
158
+ ContentChanges = new Container < TextDocumentContentChangeEvent > ( new [ ]
159
+ {
160
+ new TextDocumentContentChangeEvent
161
+ {
162
+ Text = "$a = 5"
163
+ } ,
164
+ new TextDocumentContentChangeEvent
165
+ {
166
+ Text = "$a = 6"
167
+ } ,
168
+ new TextDocumentContentChangeEvent
169
+ {
170
+ Text = "$a = 7"
171
+ }
172
+ } ) ,
173
+ TextDocument = new VersionedTextDocumentIdentifier
174
+ {
175
+ Version = 4 ,
176
+ Uri = new Uri ( filePath )
177
+ }
178
+ } ) ;
179
+
180
+ await WaitForDiagnostics ( ) ;
181
+ Diagnostic diagnostic = Assert . Single ( Diagnostics ) ;
182
+ Assert . Equal ( "PSUseDeclaredVarsMoreThanAssignments" , diagnostic . Code ) ;
183
+ }
184
+
148
185
[ Fact ]
149
186
public async Task CanReceiveDiagnosticsFromConfigurationChange ( )
150
187
{
You can’t perform that action at this time.
0 commit comments