forked from genericptr/pascal-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSP.Workspace.pas
319 lines (261 loc) · 8.12 KB
/
LSP.Workspace.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
// Pascal Language Server
// 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.Workspace;
{$mode objfpc}{$H+}
interface
uses
{ RTL }
Classes, // fpjson, fpjsonrpc,
{ Protocol }
LSP.Base, LSP.Basic, LSP.BaseTypes, LSP.General;
type
{ TWorkspaceFoldersChangeEvent }
TWorkspaceFoldersChangeEvent = class(TLSPStreamable)
private
fAdded: TWorkspaceFolderItems;
fRemoved: TWorkspaceFolderItems;
Public
constructor Create; override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
// The array of added workspace folders
property added: TWorkspaceFolderItems read fAdded write fAdded;
// The array of the removed workspace folders
property removed: TWorkspaceFolderItems read fRemoved write fRemoved;
end;
{ TDidChangeWorkspaceFoldersParams }
TDidChangeWorkspaceFoldersParams = class(TLSPStreamable)
private
fEvent: TWorkspaceFoldersChangeEvent;
procedure SetEvent(AValue: TWorkspaceFoldersChangeEvent);
Public
constructor Create; override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property event: TWorkspaceFoldersChangeEvent read fEvent write SetEvent;
end;
{ The parameters of a Workspace Symbol Request. }
{ TWorkspaceSymbolParams }
TWorkspaceSymbolParams = class(TLSPStreamable)
private
fQuery: string;
Public
Procedure Assign(Source: TPersistent); override;
published
// A query string to filter symbols by. Clients may send an empty
// string here to request all symbols.
property query: string read fQuery write fQuery;
end;
{ TDidChangeConfigurationParams }
TDidChangeConfigurationParams = class(TLSPStreamable)
private
fSettings: TInitializationOptions;
procedure SetSettings(AValue: TInitializationOptions);
Protected
function createSettings: TInitializationOptions; virtual;
Public
Constructor Create; override;
Destructor Destroy; override;
Procedure Assign(Source: TPersistent); override;
published
property settings: TInitializationOptions read fSettings write SetSettings;
end;
{ TApplyWorkspaceEditParams }
TApplyWorkspaceEditParams = class(TLSPStreamable)
private
fLabel: TOptionalString;
fEdit: TWorkspaceEdit;
procedure SetEdit(AValue: TWorkspaceEdit);
procedure SetLabel(AValue: TOptionalString);
Public
Constructor Create; override;
Destructor Destroy; override;
Procedure Assign(Source : TPersistent); override;
published
// An optional label of the workspace edit. This label is
// presented in the user interface for example on an undo
// stack to undo the workspace edit.
// Once set, the instance owns the value
property &label: TOptionalString read fLabel write SetLabel;
// The edits to apply.
property edit: TWorkspaceEdit read fEdit write SetEdit;
end;
{ TApplyWorkspaceEditResult
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#applyWorkspaceEditResult }
TApplyWorkspaceEditResult = class(TLSPStreamable)
private
fApplied: boolean;
fFailureReason: TOptionalString;
fFailedChange: TOptionalNumber;
Public
Destructor Destroy; override;
published
// Indicates whether the edit was applied or not.
property applied: Boolean read fApplied write fApplied;
// An optional textual description for why the edit was not applied.
// This may be used by the server for diagnostic logging or to provide
// a suitable error for a request that triggered the edit.
property failureReason: TOptionalString read fFailureReason write fFailureReason;
// Depending on the client's failure handling strategy `failedChange`
// might contain the index of the change that failed. This property is
// only available if the client signals a `failureHandling` strategy
// in its client capabilities.
property failedChange: TOptionalNumber read fFailedChange write fFailedChange;
end;
implementation
uses
SysUtils, DateUtils;
{ TApplyWorkspaceEditParams }
procedure TApplyWorkspaceEditParams.SetEdit(AValue: TWorkspaceEdit);
begin
if fEdit=AValue then Exit;
fEdit.Assign(AValue);
end;
procedure TApplyWorkspaceEditParams.SetLabel(AValue: TOptionalString);
begin
if fLabel=AValue then Exit;
FreeAndNil(fLabel);
fLabel:=AValue;
end;
constructor TApplyWorkspaceEditParams.Create;
begin
inherited Create;
fEdit:=TWorkspaceEdit.Create;
end;
destructor TApplyWorkspaceEditParams.Destroy;
begin
&Label:=Nil;
FreeAndNil(fEdit);
inherited Destroy;
end;
procedure TApplyWorkspaceEditParams.Assign(Source: TPersistent);
var
Src: TApplyWorkspaceEditParams absolute source;
begin
if Source is TApplyWorkspaceEditParams then
begin
Edit.Assign(Src.Edit);
if Assigned(Src.&Label) then
fLabel.Value:=Src.&Label.Value;
end
else
inherited Assign(Source);
end;
{ TApplyWorkspaceEditResult }
destructor TApplyWorkspaceEditResult.Destroy;
begin
FreeAndnil(fFailureReason);
FreeAndnil(fFailedChange);
inherited Destroy;
end;
{ TWorkspaceFoldersChangeEvent }
constructor TWorkspaceFoldersChangeEvent.Create;
begin
inherited Create;
fAdded:=TWorkspaceFolderItems.Create;
fRemoved:=TWorkspaceFolderItems.Create;
end;
destructor TWorkspaceFoldersChangeEvent.Destroy;
begin
FreeAndNil(fAdded);
FreeAndNil(fRemoved);
inherited Destroy;
end;
procedure TWorkspaceFoldersChangeEvent.Assign(Source: TPersistent);
var
Src: TWorkspaceFoldersChangeEvent absolute Source;
begin
if Source is TWorkspaceFoldersChangeEvent then
begin
Added.Assign(Src.Added);
Removed.Assign(Src.Removed);
end
else
inherited Assign(Source);
end;
{ TDidChangeWorkspaceFoldersParams }
procedure TDidChangeWorkspaceFoldersParams.SetEvent(
AValue: TWorkspaceFoldersChangeEvent);
begin
if fEvent=AValue then Exit;
fEvent.Assign(AValue);
end;
constructor TDidChangeWorkspaceFoldersParams.Create;
begin
inherited Create;
fEvent:=TWorkspaceFoldersChangeEvent.Create;
end;
destructor TDidChangeWorkspaceFoldersParams.Destroy;
begin
FreeAndNil(fEvent);
inherited Destroy;
end;
procedure TDidChangeWorkspaceFoldersParams.Assign(Source: TPersistent);
var
Src: TDidChangeWorkspaceFoldersParams absolute Source;
begin
if Source is TDidChangeWorkspaceFoldersParams then
begin
Event.Assign(Src.event)
end
else
inherited Assign(Source);
end;
{ TWorkspaceSymbolParams }
procedure TWorkspaceSymbolParams.Assign(Source: TPersistent);
var
Src: TWorkspaceSymbolParams absolute Source;
begin
if Source is TWorkspaceSymbolParams then
begin
Query:=Src.query;
end
else
inherited Assign(Source);
end;
{ TDidChangeConfigurationParams }
procedure TDidChangeConfigurationParams.SetSettings(AValue: TInitializationOptions);
begin
if fSettings=AValue then Exit;
fSettings.Assign(AValue);
end;
function TDidChangeConfigurationParams.createSettings: TInitializationOptions;
begin
Result := TInitializationOptions.Create;
end;
constructor TDidChangeConfigurationParams.Create;
begin
inherited Create;
fSettings := createSettings;
end;
destructor TDidChangeConfigurationParams.Destroy;
begin
FreeAndNil(FSettings);
inherited Destroy;
end;
procedure TDidChangeConfigurationParams.Assign(Source: TPersistent);
var
Src: TDidChangeConfigurationParams absolute source;
begin
if Source is TDidChangeConfigurationParams then
begin
Settings.Assign(Src.settings);
end
else
inherited Assign(Source);
end;
end.