1919
2020namespace Microsoft . PowerShell . EditorServices . Handlers
2121{
22- class PsesTextDocumentHandler : ITextDocumentSyncHandler
22+ class PsesTextDocumentHandler : TextDocumentSyncHandlerBase
2323 {
2424 private static readonly Uri s_fakeUri = new Uri ( "Untitled:fake" ) ;
2525
2626 private readonly ILogger _logger ;
2727 private readonly AnalysisService _analysisService ;
2828 private readonly WorkspaceService _workspaceService ;
2929 private readonly RemoteFileManagerService _remoteFileManagerService ;
30- private SynchronizationCapability _capability ;
3130
3231 public TextDocumentSyncKind Change => TextDocumentSyncKind . Incremental ;
3332
@@ -43,7 +42,7 @@ public PsesTextDocumentHandler(
4342 _remoteFileManagerService = remoteFileManagerService ;
4443 }
4544
46- public Task < Unit > Handle ( DidChangeTextDocumentParams notification , CancellationToken token )
45+ public override Task < Unit > Handle ( DidChangeTextDocumentParams notification , CancellationToken token )
4746 {
4847 ScriptFile changedFile = _workspaceService . GetFile ( notification . TextDocument . Uri ) ;
4948
@@ -62,21 +61,14 @@ public Task<Unit> Handle(DidChangeTextDocumentParams notification, CancellationT
6261 return Unit . Task ;
6362 }
6463
65- TextDocumentChangeRegistrationOptions IRegistration < TextDocumentChangeRegistrationOptions > . GetRegistrationOptions ( )
64+ protected override TextDocumentSyncRegistrationOptions CreateRegistrationOptions ( SynchronizationCapability capability , ClientCapabilities clientCapabilities ) => new TextDocumentSyncRegistrationOptions ( )
6665 {
67- return new TextDocumentChangeRegistrationOptions ( )
68- {
69- DocumentSelector = LspUtils . PowerShellDocumentSelector ,
70- SyncKind = Change
71- } ;
72- }
66+ DocumentSelector = LspUtils . PowerShellDocumentSelector ,
67+ Change = Change ,
68+ Save = new SaveOptions { IncludeText = true }
69+ } ;
7370
74- public void SetCapability ( SynchronizationCapability capability )
75- {
76- _capability = capability ;
77- }
78-
79- public Task < Unit > Handle ( DidOpenTextDocumentParams notification , CancellationToken token )
71+ public override Task < Unit > Handle ( DidOpenTextDocumentParams notification , CancellationToken token )
8072 {
8173 ScriptFile openedFile =
8274 _workspaceService . GetFileBuffer (
@@ -98,15 +90,7 @@ public Task<Unit> Handle(DidOpenTextDocumentParams notification, CancellationTok
9890 return Unit . Task ;
9991 }
10092
101- TextDocumentRegistrationOptions IRegistration < TextDocumentRegistrationOptions > . GetRegistrationOptions ( )
102- {
103- return new TextDocumentRegistrationOptions ( )
104- {
105- DocumentSelector = LspUtils . PowerShellDocumentSelector ,
106- } ;
107- }
108-
109- public Task < Unit > Handle ( DidCloseTextDocumentParams notification , CancellationToken token )
93+ public override Task < Unit > Handle ( DidCloseTextDocumentParams notification , CancellationToken token )
11094 {
11195 // Find and close the file in the current session
11296 var fileToClose = _workspaceService . GetFile ( notification . TextDocument . Uri ) ;
@@ -121,7 +105,7 @@ public Task<Unit> Handle(DidCloseTextDocumentParams notification, CancellationTo
121105 return Unit . Task ;
122106 }
123107
124- public async Task < Unit > Handle ( DidSaveTextDocumentParams notification , CancellationToken token )
108+ public override async Task < Unit > Handle ( DidSaveTextDocumentParams notification , CancellationToken token )
125109 {
126110 ScriptFile savedFile = _workspaceService . GetFile ( notification . TextDocument . Uri ) ;
127111
@@ -135,18 +119,7 @@ public async Task<Unit> Handle(DidSaveTextDocumentParams notification, Cancellat
135119 return Unit . Value ;
136120 }
137121
138- TextDocumentSaveRegistrationOptions IRegistration < TextDocumentSaveRegistrationOptions > . GetRegistrationOptions ( )
139- {
140- return new TextDocumentSaveRegistrationOptions ( )
141- {
142- DocumentSelector = LspUtils . PowerShellDocumentSelector ,
143- IncludeText = true
144- } ;
145- }
146- public TextDocumentAttributes GetTextDocumentAttributes ( DocumentUri uri )
147- {
148- return new TextDocumentAttributes ( uri , "powershell" ) ;
149- }
122+ public override TextDocumentAttributes GetTextDocumentAttributes ( DocumentUri uri ) => new TextDocumentAttributes ( uri , "powershell" ) ;
150123
151124 private static FileChange GetFileChangeDetails ( Range changeRange , string insertString )
152125 {
0 commit comments