19
19
20
20
namespace Microsoft . PowerShell . EditorServices . Handlers
21
21
{
22
- class PsesTextDocumentHandler : ITextDocumentSyncHandler
22
+ class PsesTextDocumentHandler : TextDocumentSyncHandlerBase
23
23
{
24
24
private static readonly Uri s_fakeUri = new Uri ( "Untitled:fake" ) ;
25
25
26
26
private readonly ILogger _logger ;
27
27
private readonly AnalysisService _analysisService ;
28
28
private readonly WorkspaceService _workspaceService ;
29
29
private readonly RemoteFileManagerService _remoteFileManagerService ;
30
- private SynchronizationCapability _capability ;
31
30
32
31
public TextDocumentSyncKind Change => TextDocumentSyncKind . Incremental ;
33
32
@@ -43,7 +42,7 @@ public PsesTextDocumentHandler(
43
42
_remoteFileManagerService = remoteFileManagerService ;
44
43
}
45
44
46
- public Task < Unit > Handle ( DidChangeTextDocumentParams notification , CancellationToken token )
45
+ public override Task < Unit > Handle ( DidChangeTextDocumentParams notification , CancellationToken token )
47
46
{
48
47
ScriptFile changedFile = _workspaceService . GetFile ( notification . TextDocument . Uri ) ;
49
48
@@ -62,21 +61,14 @@ public Task<Unit> Handle(DidChangeTextDocumentParams notification, CancellationT
62
61
return Unit . Task ;
63
62
}
64
63
65
- TextDocumentChangeRegistrationOptions IRegistration < TextDocumentChangeRegistrationOptions > . GetRegistrationOptions ( )
64
+ protected override TextDocumentSyncRegistrationOptions CreateRegistrationOptions ( SynchronizationCapability capability , ClientCapabilities clientCapabilities ) => new TextDocumentSyncRegistrationOptions ( )
66
65
{
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
+ } ;
73
70
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 )
80
72
{
81
73
ScriptFile openedFile =
82
74
_workspaceService . GetFileBuffer (
@@ -98,15 +90,7 @@ public Task<Unit> Handle(DidOpenTextDocumentParams notification, CancellationTok
98
90
return Unit . Task ;
99
91
}
100
92
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 )
110
94
{
111
95
// Find and close the file in the current session
112
96
var fileToClose = _workspaceService . GetFile ( notification . TextDocument . Uri ) ;
@@ -121,7 +105,7 @@ public Task<Unit> Handle(DidCloseTextDocumentParams notification, CancellationTo
121
105
return Unit . Task ;
122
106
}
123
107
124
- public async Task < Unit > Handle ( DidSaveTextDocumentParams notification , CancellationToken token )
108
+ public override async Task < Unit > Handle ( DidSaveTextDocumentParams notification , CancellationToken token )
125
109
{
126
110
ScriptFile savedFile = _workspaceService . GetFile ( notification . TextDocument . Uri ) ;
127
111
@@ -135,18 +119,7 @@ public async Task<Unit> Handle(DidSaveTextDocumentParams notification, Cancellat
135
119
return Unit . Value ;
136
120
}
137
121
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" ) ;
150
123
151
124
private static FileChange GetFileChangeDetails ( Range changeRange , string insertString )
152
125
{
0 commit comments