-
Notifications
You must be signed in to change notification settings - Fork 16
/
LSP.InlayHint.pas
159 lines (131 loc) · 4.68 KB
/
LSP.InlayHint.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
// Pascal Language Server
// Copyright 2022 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.InlayHint;
{$mode objfpc}{$H+}
{$scopedenums on}
interface
uses
{ RTL }
Classes, SysUtils,
{ LSP Protocol }
LSP.Base, LSP.Basic, LSP.BaseTypes;
type
{ TInlayHintKind }
TInlayHintKind = (
// TODO: do we need this for optionals?
__UNUSED__,
_Type, // An inlay hint that for a type annotation.
Parameter // An inlay hint that is for a parameter.
);
TOptionalInlayHintKind = specialize TOptional<TInlayHintKind>;
{ TInlayHint
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#inlayHint
Inlay hint information. }
TInlayHint = class(TCollectionItem)
private
fPosition: TPosition;
fLabel: String; // string | InlayHintLabelPart[] (not supported now)
fKind: TOptionalInlayHintKind;
fTextEdits: TTextEdits;
fTooltip: String;
public
Constructor Create(ACollection: TCollection); override;
published
// The position of this hint.
property position: TPosition read fPosition write fPosition;
// The label of this hint. A human readable string or an array of
// InlayHintLabelPart label parts.
//
// *Note* that neither the string nor the label part can be empty.
property &label: String read fLabel write fLabel;
// The kind of this hint. Can be omitted in which case the client
// should fall back to a reasonable default.
// owned by the inlayhint
property kind: TOptionalInlayHintKind read fKind write fKind;
// Optional text edits that are performed when accepting this inlay hint.
//
// *Note* that edits are expected to change the document so that the inlay
// hint (or its nearest variant) is now part of the document and the inlay
// hint itself is now obsolete.
//
// Depending on the client capability `inlayHint.resolveSupport` clients
// might resolve this property late using the resolve request.
property textEdits: TTextEdits read fTextEdits write fTextEdits;
// The tooltip text when you hover over this item.
//
// Depending on the client capability `inlayHint.resolveSupport` clients
// might resolve this property late using the resolve request.
property tooltip: String read fTooltip write fTooltip;
public
destructor Destroy; override;
end;
TInlayHints = specialize TGenericCollection<TInlayHint>;
{ TInlayHintParams
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#inlayHintParams
A parameter literal used in inlay hint requests. }
TInlayHintParams = class(TLSPStreamable)
private
fTextDocument: TTextDocumentIdentifier;
fRange: TRange;
procedure SetRange(AValue: TRange);
procedure SetTextDocument(AValue: TTextDocumentIdentifier);
published
// The text document.
property textDocument: TTextDocumentIdentifier read fTextDocument write SetTextDocument;
// The visible document range for which inlay hints should be computed.
property range: TRange read fRange write SetRange;
public
constructor create; override;
destructor Destroy; override;
end;
implementation
{ TInlayHint }
constructor TInlayHint.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
fPosition:=TPosition.Create;
fTextEdits:=TTextEdits.Create;
end;
destructor TInlayHint.Destroy;
begin
FreeAndNil(fPosition);
FreeAndNil(fKind);
FreeAndNil(fTextEdits);
inherited;
end;
{ TInlayHintParams }
procedure TInlayHintParams.SetRange(AValue: TRange);
begin
if fRange=AValue then Exit;
fRange.Assign(AValue);
end;
procedure TInlayHintParams.SetTextDocument(AValue: TTextDocumentIdentifier);
begin
if fTextDocument=AValue then Exit;
fTextDocument.Assign(AValue);
end;
constructor TInlayHintParams.create;
begin
inherited create;
ftextDocument:=TTextDocumentIdentifier.Create;
frange:=TRange.Create;
end;
destructor TInlayHintParams.Destroy;
begin
FreeAndNil(fTextDocument);
FreeAndNil(fRange);
inherited;
end;
end.