File tree Expand file tree Collapse file tree 2 files changed +39
-7
lines changed
src/PowerShellEditorServices/Services/TextDocument/Handlers
test/PowerShellEditorServices.Test.E2E Expand file tree Collapse file tree 2 files changed +39
-7
lines changed Original file line number Diff line number Diff line change 44//
55
66using System ;
7- using System . Collections . Generic ;
87using System . Threading ;
98using System . Threading . Tasks ;
109using Microsoft . Extensions . Logging ;
@@ -52,23 +51,19 @@ public TextDocumentHandler(
5251
5352 public Task < Unit > Handle ( DidChangeTextDocumentParams notification , CancellationToken token )
5453 {
55- List < ScriptFile > changedFiles = new List < ScriptFile > ( ) ;
54+ ScriptFile changedFile = _workspaceService . GetFile ( notification . TextDocument . Uri . ToString ( ) ) ;
5655
5756 // A text change notification can batch multiple change requests
5857 foreach ( TextDocumentContentChangeEvent textChange in notification . ContentChanges )
5958 {
60- ScriptFile changedFile = _workspaceService . GetFile ( notification . TextDocument . Uri . ToString ( ) ) ;
61-
6259 changedFile . ApplyChange (
6360 GetFileChangeDetails (
6461 textChange . Range ,
6562 textChange . Text ) ) ;
66-
67- changedFiles . Add ( changedFile ) ;
6863 }
6964
7065 // TODO: Get all recently edited files in the workspace
71- _analysisService . RunScriptDiagnosticsAsync ( changedFiles . ToArray ( ) ) ;
66+ _analysisService . RunScriptDiagnosticsAsync ( new ScriptFile [ ] { changedFile } ) ;
7267 return Unit . Task ;
7368 }
7469
Original file line number Diff line number Diff line change @@ -145,6 +145,43 @@ public async Task CanReceiveDiagnosticsFromFileOpen()
145145 Assert . Equal ( "PSUseDeclaredVarsMoreThanAssignments" , diagnostic . Code ) ;
146146 }
147147
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+
148185 [ Fact ]
149186 public async Task CanReceiveDiagnosticsFromConfigurationChange ( )
150187 {
You can’t perform that action at this time.
0 commit comments