-
Notifications
You must be signed in to change notification settings - Fork 16
/
LSP.Capabilities.pas
375 lines (313 loc) · 11.7 KB
/
LSP.Capabilities.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// Pascal Language Server
// Copyright 2020 Arjan Adriaanse
// Copyright 2020 Ryan Joseph
// This file is part of Pascal Language Server.
// Pascal Language Server is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Pascal Language Server is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Pascal Language Server. If not, see
// <https://www.gnu.org/licenses/>.
unit LSP.Capabilities;
{$mode objfpc}{$H+}
interface
uses
{ RTL }
SysUtils, Classes,
{ Protocol }
LSP.BaseTypes, LSP.Options;
type
{ TWorkspaceClientCapabilities }
TWorkspaceClientCapabilities = class(TLSPStreamable)
private
fApplyEdit: Boolean;
fWorkspaceFolders: boolean;
fConfiguration: boolean;
Public
Procedure Assign(Source : TPersistent); override;
published
// The client supports applying batch edits to the workspace by supporting
// the request 'workspace/applyEdit'
property applyEdit: Boolean read fApplyEdit write fApplyEdit;
// The client has support for workspace folders.
property workspaceFolders: Boolean read fWorkspaceFolders write fWorkspaceFolders;
// The client supports `workspace/configuration` requests.
property configuration: Boolean read fConfiguration write fConfiguration;
end;
{ TWorkspaceFoldersServerCapabilities }
TWorkspaceFoldersServerCapabilities = class(TLSPStreamable)
private
fSupported: boolean;
fChangeNotifications: boolean;
Public
Procedure Assign(Source : TPersistent); override;
published
// The server has support for workspace folders
property supported: Boolean read fSupported write fSupported;
// Whether the server wants to receive workspace folder
// change notifications.
//
// If a string is provided, the string is treated as an ID
// under which the notification is registered on the client
// side. The ID can be used to unregister for these events
// using the `client/unregisterCapability` request.
property changeNotifications: boolean read fChangeNotifications write fChangeNotifications;
end;
{ TWorkspaceServerCapabilities }
TWorkspaceServerCapabilities = class(TLSPStreamable)
private
fWorkspaceFolders: TWorkspaceFoldersServerCapabilities;
procedure SetWorkspaceFolders(AValue: TWorkspaceFoldersServerCapabilities);
public
constructor Create; override;
Destructor Destroy; override;
Procedure Assign(Source : TPersistent); override;
published
// The server supports workspace folder.
property workspaceFolders: TWorkspaceFoldersServerCapabilities read fWorkspaceFolders write SetWorkspaceFolders;
end;
{ TTextDocumentClientCapabilities }
TTextDocumentClientCapabilities = class(TLSPStreamable)
end;
{ TClientCapabilities }
TClientCapabilities = class(TLSPStreamable)
private
fWorkspace: TWorkspaceClientCapabilities;
fTextDocument: TTextDocumentClientCapabilities;
procedure SetTextDocument(AValue: TTextDocumentClientCapabilities);
procedure SetWorkspace(AValue: TWorkspaceClientCapabilities);
Public
constructor Create; override;
destructor destroy; override;
Procedure Assign(Source : TPersistent); override;
published
property workspace: TWorkspaceClientCapabilities read fWorkspace write SetWorkspace;
property textDocument: TTextDocumentClientCapabilities read fTextDocument write SetTextDocument;
end;
{ TServerCapabilities }
TServerCapabilities = class(TLSPStreamable)
private
fTextDocumentSync: TTextDocumentSyncOptions;
fWorkspace: TWorkspaceServerCapabilities;
fCompletionProvider: TCompletionOptions;
fHoverProvider: boolean;
fDefinitionProvider: boolean;
fDeclarationProvider: boolean;
fReferencesProvider: boolean;
fImplementationProvider: boolean;
fCodeActionProvider: boolean;
fDocumentHighlightProvider: boolean;
fDocumentSymbolProvider: boolean;
fWorkspaceSymbolProvider: boolean;
fSignatureHelpProvider: TSignatureHelpOptions;
fExecuteCommandProvider: TExecuteCommandOptions;
fInlayHintProvider: TInlayHintOptions;
procedure SetCompletionProvider(AValue: TCompletionOptions);
procedure SetExecuteCommandProvider(AValue: TExecuteCommandOptions);
procedure SetInlayHintProvider(AValue: TInlayHintOptions);
procedure SetSignatureHelpProvider(AValue: TSignatureHelpOptions);
procedure SetTextDocumentSync(AValue: TTextDocumentSyncOptions);
procedure SetWorkspace(AValue: TWorkspaceServerCapabilities);
public
constructor Create; override;
destructor destroy; override;
Procedure Assign(Source : TPersistent); override;
published
property textDocumentSync: TTextDocumentSyncOptions read fTextDocumentSync write SetTextDocumentSync;
property workspace: TWorkspaceServerCapabilities read fWorkspace write SetWorkspace;
property completionProvider: TCompletionOptions read fCompletionProvider write SetCompletionProvider;
property hoverProvider: boolean read fHoverProvider write fHoverProvider;
property definitionProvider: boolean read fDefinitionProvider write fDefinitionProvider;
property declarationProvider: boolean read fDeclarationProvider write fDeclarationProvider;
property referencesProvider: boolean read fReferencesProvider write fReferencesProvider;
property implementationProvider: boolean read fImplementationProvider write fImplementationProvider;
property codeActionProvider: boolean read fCodeActionProvider write fCodeActionProvider;
property documentHighlightProvider: boolean read fDocumentHighlightProvider write fDocumentHighlightProvider;
property documentSymbolProvider: boolean read fDocumentSymbolProvider write fDocumentSymbolProvider;
property workspaceSymbolProvider: boolean read fWorkspaceSymbolProvider write fWorkspaceSymbolProvider;
property signatureHelpProvider: TSignatureHelpOptions read fSignatureHelpProvider write SetSignatureHelpProvider;
property executeCommandProvider: TExecuteCommandOptions read fExecuteCommandProvider write SetExecuteCommandProvider;
property inlayHintProvider: TInlayHintOptions read fInlayHintProvider write SetInlayHintProvider;
end;
implementation
{ TWorkspaceClientCapabilities }
procedure TWorkspaceClientCapabilities.Assign(Source : TPersistent);
var
Src : TWorkspaceClientCapabilities absolute Source;
begin
if Source is TWorkspaceClientCapabilities then
begin
ApplyEdit:=Src.ApplyEdit;
WorkspaceFolders:=Src.workspaceFolders;
Configuration:=Src.configuration;
end
else
inherited Assign(Source);
end;
{ TWorkspaceFoldersServerCapabilities }
procedure TWorkspaceFoldersServerCapabilities.Assign(Source : TPersistent);
var
Src : TWorkspaceFoldersServerCapabilities absolute source;
begin
if Source is TWorkspaceFoldersServerCapabilities then
begin
Supported:=Src.supported;
ChangeNotifications:=Src.changeNotifications;
end
else
inherited Assign(Source);
end;
{ TWorkspaceServerCapabilities }
procedure TWorkspaceServerCapabilities.SetWorkspaceFolders(
AValue: TWorkspaceFoldersServerCapabilities);
begin
if fWorkspaceFolders=AValue then Exit;
fWorkspaceFolders.Assign(AValue);
end;
constructor TWorkspaceServerCapabilities.Create;
begin
Inherited;
FWorkspaceFolders := TWorkspaceFoldersServerCapabilities.Create;
end;
destructor TWorkspaceServerCapabilities.Destroy;
begin
FreeAndNil(FWorkspaceFolders);
inherited Destroy;
end;
procedure TWorkspaceServerCapabilities.Assign(Source : TPersistent);
var
Src : TWorkspaceServerCapabilities absolute Source;
begin
If Source is TWorkspaceServerCapabilities then
begin
workspaceFolders:=Src.workspaceFolders;
end
else
inherited Assign(Source);
end;
{ TClientCapabilities }
procedure TClientCapabilities.SetTextDocument(
AValue: TTextDocumentClientCapabilities);
begin
if fTextDocument=AValue then Exit;
fTextDocument.Assign(AValue);
end;
procedure TClientCapabilities.SetWorkspace(AValue: TWorkspaceClientCapabilities
);
begin
if fWorkspace=AValue then Exit;
fWorkspace.Assign(AValue);
end;
constructor TClientCapabilities.Create;
begin
Inherited;
fWorkspace:=TWorkspaceClientCapabilities.Create;
fTextDocument:=TTextDocumentClientCapabilities.Create;
end;
destructor TClientCapabilities.destroy;
begin
FreeAndNil(fWorkspace);
FreeAndNil(fTextDocument);
inherited destroy;
end;
procedure TClientCapabilities.Assign(Source : TPersistent);
Var
CP : TClientCapabilities absolute source;
begin
if Source is TClientCapabilities then
begin
Workspace:=cp.Workspace;
TextDocument:=cp.textDocument;
end
else
inherited Assign(Source);
end;
{ TServerCapabilities }
procedure TServerCapabilities.SetCompletionProvider(AValue: TCompletionOptions);
begin
if fCompletionProvider=AValue then Exit;
fCompletionProvider.Assign(AValue);
end;
procedure TServerCapabilities.SetExecuteCommandProvider(
AValue: TExecuteCommandOptions);
begin
if fExecuteCommandProvider=AValue then Exit;
fExecuteCommandProvider.Assign(AValue);
end;
procedure TServerCapabilities.SetInlayHintProvider(AValue: TInlayHintOptions);
begin
if fInlayHintProvider=AValue then Exit;
// May not have been created during constructor, so we need to create it here.
if fInlayHintProvider=Nil then
fInlayHintProvider:=TInlayHintOptions.Create;
fInlayHintProvider.Assign(AValue);
end;
procedure TServerCapabilities.SetSignatureHelpProvider(
AValue: TSignatureHelpOptions);
begin
if fSignatureHelpProvider=AValue then Exit;
fSignatureHelpProvider.Assign(AValue);
end;
procedure TServerCapabilities.SetTextDocumentSync(
AValue: TTextDocumentSyncOptions);
begin
if fTextDocumentSync=AValue then Exit;
fTextDocumentSync.Assign(AValue);
end;
procedure TServerCapabilities.SetWorkspace(AValue: TWorkspaceServerCapabilities
);
begin
if fWorkspace=AValue then Exit;
fWorkspace.Assign(AValue);
end;
constructor TServerCapabilities.Create;
begin
inherited Create;
ftextDocumentSync := TTextDocumentSyncOptions.Create;
fworkspace := TWorkspaceServerCapabilities.Create;
fcompletionProvider := TCompletionOptions.Create;
fsignatureHelpProvider := TSignatureHelpOptions.Create;
fexecuteCommandProvider := TExecuteCommandOptions.Create;
ftextDocumentSync.change := TTextDocumentSyncKind.Full;
end;
destructor TServerCapabilities.destroy;
begin
FreeAndNil(fTextDocumentSync);
FreeAndNil(fWorkspace);
FreeAndNil(fCompletionProvider);
FreeAndNil(fSignatureHelpProvider);
FreeAndNil(fExecuteCommandProvider);
FreeAndNil(fInlayHintProvider);
inherited destroy;
end;
procedure TServerCapabilities.Assign(Source : TPersistent);
var
Src : TServerCapabilities absolute source;
begin
if Source is TServerCapabilities then
begin
TextDocumentSync:=TextDocumentSync;
Workspace:=Src.Workspace;
CompletionProvider:=Src.CompletionProvider;
HoverProvider:= Src.HoverProvider;
DefinitionProvider:=Src.DefinitionProvider;
DeclarationProvider:=Src.DeclarationProvider;
ReferencesProvider:=Src.ReferencesProvider;
ImplementationProvider:=Src.ImplementationProvider;
CodeActionProvider:=Src.CodeActionProvider;
DocumentHighlightProvider:=Src.DocumentHighlightProvider;
DocumentSymbolProvider:=Src.DocumentSymbolProvider;
WorkspaceSymbolProvider:=Src.WorkspaceSymbolProvider;
SignatureHelpProvider:=Src.SignatureHelpProvider;
ExecuteCommandProvider:=Src.ExecuteCommandProvider;
InlayHintProvider:=Src.inlayHintProvider;
end
else
inherited Assign(Source);
end;
end.