-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathLSP.SignatureHelp.pas
More file actions
226 lines (181 loc) · 6.89 KB
/
LSP.SignatureHelp.pas
File metadata and controls
226 lines (181 loc) · 6.89 KB
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
// 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.SignatureHelp;
{$mode objfpc}{$H+}
interface
uses
{ RTL }
Classes,
{ Protocol }
LSP.Base, LSP.Basic, LSP.BaseTypes;
type
{ TParameterInformation }
{ Represents a parameter of a callable-signature. A parameter can
have a label and a doc-comment. }
TParameterInformation = class(TCollectionItem)
private
fLabel: string;
fDocumentation: TMarkupContent;
procedure SetDocumentation(AValue: TMarkupContent);
Public
Constructor Create(ACollection: TCollection); override;
Destructor Destroy; override;
Procedure Assign(Source: TPersistent); override;
published
// The label of this parameter information.
//
// Either a string or an inclusive start and exclusive end offsets within its containing
// signature label. (see SignatureInformation.label). The offsets are based on a UTF-16
// string representation as `Position` and `Range` does.
//
// *Note*: a label of type string should be a substring of its containing signature label.
// Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`.
property &label: string read fLabel write fLabel;
// The human-readable doc-comment of this parameter. Will be shown
// in the UI but can be omitted.
property documentation: TMarkupContent read fDocumentation write SetDocumentation;
end;
TParameterInformationCollection = specialize TGenericCollection<TParameterInformation>;
{ TSignatureInformation }
{ Represents the signature of something callable. A signature
can have a label, like a function-name, a doc-comment, and
a set of parameters. }
TSignatureInformation = class(TCollectionItem)
private
fLabel: string;
fDocumentation: TMarkupContent;
fParameters: TParameterInformationCollection;
procedure SetDocumentation(AValue: TMarkupContent);
procedure SetParameters(AValue: TParameterInformationCollection);
Public
Constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
published
// The label of this signature. Will be shown in
// the UI.
property &label: string read fLabel write fLabel;
// The human-readable doc-comment of this signature. Will be shown
// in the UI but can be omitted.
property documentation: TMarkupContent read fDocumentation write SetDocumentation;
// The parameters of this signature.
property parameters: TParameterInformationCollection read fParameters write SetParameters;
end;
TSignatureInformationCollection = specialize TGenericCollection<TSignatureInformation>;
{ TSignatureHelp
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#signatureHelp
Signature help represents the signature of something callable.
There can be multiple signature but only one active and only one active parameter. }
TSignatureHelp = class(TLSPStreamable)
private
fSignatures: TSignatureInformationCollection;
fActiveSignature: integer;
fActiveParameter: integer;
procedure SetSignatures(AValue: TSignatureInformationCollection);
Public
Constructor Create; override;
Destructor Destroy; override;
published
// One or more signatures.
property signatures: TSignatureInformationCollection read fSignatures write SetSignatures;
// The active signature. If omitted or the value lies outside the
// range of `signatures` the value defaults to zero or is ignored if
// `signatures.length === 0`. Whenever possible implementors should
// make an active decision about the active signature and shouldn't
// rely on a default value.
// In future version of the protocol this property might become
// mandatory to better express this.
property activeSignature: integer read fActiveSignature write fActiveSignature;
// The active parameter of the active signature. If omitted or the value
// lies outside the range of `signatures[activeSignature].parameters`
// defaults to 0 if the active signature has parameters. If
// the active signature has no parameters it is ignored.
// In future version of the protocol this property might become
// mandatory to better express the active parameter if the
// active signature does have any.
property activeParameter: integer read fActiveParameter write fActiveParameter;
end;
implementation
uses
{ RTL }
SysUtils;
{ TParameterInformation }
procedure TParameterInformation.SetDocumentation(AValue: TMarkupContent);
begin
if fDocumentation=AValue then Exit;
fDocumentation.Assign(AValue);
end;
constructor TParameterInformation.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
fDocumentation:=TMarkupContent.Create;
end;
destructor TParameterInformation.Destroy;
begin
FreeAndNil(fDocumentation);
Inherited;
end;
procedure TParameterInformation.Assign(Source: TPersistent);
var
Src: TParameterInformation absolute Source;
begin
if Source is TParameterInformation then
begin
fLabel:=Src.fLabel;
Documentation.Assign(Src.documentation);
end
else
inherited Assign(Source);
end;
{ TSignatureInformation }
procedure TSignatureInformation.SetDocumentation(AValue: TMarkupContent);
begin
if fDocumentation=AValue then Exit;
fDocumentation.Assign(AValue);
end;
procedure TSignatureInformation.SetParameters(
AValue: TParameterInformationCollection);
begin
if fParameters=AValue then Exit;
fParameters.Assign(AValue);
end;
constructor TSignatureInformation.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
fDocumentation:=TMarkupContent.Create;
fParameters:=TParameterInformationCollection.Create;
end;
destructor TSignatureInformation.Destroy;
begin
FreeAndNil(fDocumentation);
FreeAndNil(fParameters);
inherited Destroy;
end;
{ TSignatureHelp }
procedure TSignatureHelp.SetSignatures(AValue: TSignatureInformationCollection);
begin
if fSignatures=AValue then Exit;
fSignatures.Assign(AValue);
end;
constructor TSignatureHelp.Create;
begin
inherited Create;
fSignatures:=TSignatureInformationCollection.Create;
end;
destructor TSignatureHelp.Destroy;
begin
FreeAndNil(fSignatures);
inherited Destroy;
end;
end.