-
Notifications
You must be signed in to change notification settings - Fork 22
/
general.pas
159 lines (118 loc) · 3.82 KB
/
general.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
// Pascal Language Server
// Copyright 2020 Arjan Adriaanse
// 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 general;
{$mode objfpc}{$H+}
interface
uses
Classes, CodeToolManager, CodeToolsConfig, URIParser, LazUTF8,
lsp, capabilities;
type
{ TVoidParams }
TVoidParams = class(TPersistent);
{ TInitializeParams }
TInitializeParams = class(TPersistent)
private
//fProcessId: string;
fRootUri: string;
fCapabilities: TClientCapabilities;
published
//property processId: string read fProcessId write fProcessId;
property rootUri: string read fRootUri write fRootUri;
property capabilities: TClientCapabilities read fCapabilities write fCapabilities;
end;
{ TInitializeResult }
TInitializeResult = class(TPersistent)
private
fCapabilities: TServerCapabilities;
published
property capabilities: TServerCapabilities read fCapabilities write fCapabilities;
end;
{ TInitialize }
TInitialize = class(specialize TLSPRequest<TInitializeParams, TInitializeResult>)
function Process(var Params : TInitializeParams): TInitializeResult; override;
end;
{ TInitialized }
TInitialized = class(specialize TLSPNotification<TVoidParams>)
procedure Process(var Params : TVoidParams); override;
end;
{ TCancelParams }
TCancelParams = class(TPersistent)
private
fId: Integer;
published
property id: Integer read fId write fId;
end;
{ TShutdown }
TShutdown = class(specialize TLSPRequest<TVoidParams, TPersistent>)
function Process(var Params : TVoidParams): TPersistent; override;
end;
{ TExit }
TExit = class(specialize TLSPNotification<TVoidParams>)
procedure Process(var Params : TVoidParams); override;
end;
{ TCancel }
TCancel = class(specialize TLSPNotification<TCancelParams>)
procedure Process(var Params : TCancelParams); override;
end;
implementation
{ TInitialize }
function TInitialize.Process(var Params : TInitializeParams): TInitializeResult;
var
CodeToolsOptions: TCodeToolsOptions;
begin with Params do
begin
CodeToolsOptions := TCodeToolsOptions.Create;
with CodeToolsOptions do
begin
InitWithEnvironmentVariables;
ProjectDir := ParseURI(rootUri).Path;
end;
with CodeToolBoss do
begin
Init(CodeToolsOptions);
IdentifierList.SortForHistory := True;
IdentifierList.SortForScope := True;
end;
Result := TInitializeResult.Create;
Result.capabilities := TServerCapabilities.Create;
end;
end;
{ TInitialized }
procedure TInitialized.Process(var Params : TVoidParams);
begin
// do nothing
end;
{ TShutdown }
function TShutdown.Process(var Params : TVoidParams): TPersistent;
begin
// do nothing
end;
{ TExit }
procedure TExit.Process(var Params : TVoidParams);
begin
Halt(0);
end;
{ TCancel }
procedure TCancel.Process(var Params : TCancelParams);
begin
// not supported
end;
initialization
LSPHandlerManager.RegisterHandler('initialize', TInitialize);
LSPHandlerManager.RegisterHandler('initialized', TInitialized);
LSPHandlerManager.RegisterHandler('shutdown', TShutdown);
LSPHandlerManager.RegisterHandler('exit', TExit);
LSPHandlerManager.RegisterHandler('$/cancelRequest', TCancel);
end.