forked from genericptr/pascal-language-server
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcapabilities.pas
212 lines (167 loc) · 7.62 KB
/
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
// 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 capabilities;
{$mode objfpc}{$H+}
interface
uses
Classes, options, documentSymbol, settings,basic;
type
{ TWorkspaceClientCapabilities }
TWorkspaceClientCapabilities = class(TPersistent)
private
fApplyEdit: Boolean;
fWorkspaceFolders: boolean;
fConfiguration: boolean;
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(TPersistent)
private
fSupported: boolean;
fChangeNotifications: boolean;
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 = class(TPersistent)
private
fWorkspaceFolders: TWorkspaceFoldersServerCapabilities;
published
// The server supports workspace folder.
property workspaceFolders: TWorkspaceFoldersServerCapabilities read fWorkspaceFolders write fWorkspaceFolders;
public
constructor Create;
end;
{ TTextDocumentClientCapabilities }
TTextDocumentClientCapabilities = class(TPersistent)
private
published
end;
{ TClientCapabilities }
TClientCapabilities = class(TPersistent)
private
fWorkspace: TWorkspaceClientCapabilities;
fTextDocument: TTextDocumentClientCapabilities;
published
property workspace: TWorkspaceClientCapabilities read fWorkspace write fWorkspace;
property textDocument: TTextDocumentClientCapabilities read fTextDocument write fTextDocument;
end;
{ TServerCapabilities }
TServerCapabilities = class(TPersistent)
private
fTextDocumentSync: TTextDocumentSyncOptions;
fWorkspace: TWorkspaceServerCapabilities;
fCompletionProvider: TCompletionOptions;
fHoverProvider: boolean;
fDefinitionProvider: boolean;
fDeclarationProvider: boolean;
fReferencesProvider: boolean;
fImplementationProvider: boolean;
fCodeActionProvider: TCodeActionOptions;
fDocumentHighlightProvider: boolean;
fDocumentSymbolProvider: boolean;
fWorkspaceSymbolProvider: boolean;
fSignatureHelpProvider: TSignatureHelpOptions;
//The server provides execute command support.
fexecuteCommandProvider: TExecuteCommandOptions;
frenameProvider:TRenameOptions;
public
constructor Create(settings: TServerSettings);
published
property textDocumentSync: TTextDocumentSyncOptions read fTextDocumentSync write fTextDocumentSync;
property workspace: TWorkspaceServerCapabilities read fWorkspace write fWorkspace;
property completionProvider: TCompletionOptions read fCompletionProvider write fCompletionProvider;
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: TCodeActionOptions 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 fSignatureHelpProvider;
property executeCommandProvider: TExecuteCommandOptions read fexecuteCommandProvider write fexecuteCommandProvider;
property renameProvider:TRenameOptions read frenameProvider write frenameProvider;
end;
implementation
uses codeAction;
{ TWorkspaceServerCapabilities }
constructor TWorkspaceServerCapabilities.Create;
begin
workspaceFolders := TWorkspaceFoldersServerCapabilities.Create;
end;
{ TServerCapabilities }
constructor TServerCapabilities.Create(settings: TServerSettings);
var
triggerCharacters: TStringList;
begin
textDocumentSync := TTextDocumentSyncOptions.Create;
textDocumentSync.save := TSaveOptions.Create(false);
textDocumentSync.change := TTextDocumentSyncKind.Incremental;
//textDocumentSync.openClose:=False;
workspace := TWorkspaceServerCapabilities.Create;
workspace.workspaceFolders.supported := true;
workspace.workspaceFolders.changeNotifications := true;
hoverProvider := true;
declarationProvider := true;
definitionProvider := true;
implementationProvider := true;
referencesProvider := true;
// todo: disabling this until we can figure out how to highlight
// only begin/end keywords. too annoying right now.
documentHighlightProvider := false;
documentSymbolProvider := Assigned(SymbolManager);
workspaceSymbolProvider := settings.CanProvideWorkspaceSymbols;
completionProvider := TCompletionOptions.Create;
triggerCharacters := TStringList.Create;
triggerCharacters.Add('.');
triggerCharacters.Add('^');
completionProvider.triggerCharacters := triggerCharacters;
signatureHelpProvider := TSignatureHelpOptions.Create;
triggerCharacters := TStringList.Create;
triggerCharacters.Add('(');
triggerCharacters.Add(')');
triggerCharacters.Add(',');
signatureHelpProvider.triggerCharacters := triggerCharacters;
codeActionProvider:=TCodeActionOptions.Create;
codeActionProvider.codeActionKinds.Add(TCodeActionKind.Refactor);
codeActionProvider.codeActionKinds.Add(TCodeActionKind.Source);
codeActionProvider.codeActionKinds.Add(TCodeActionKind.QuickFix);
codeActionProvider.resolveProvider:=false;
renameProvider:=TRenameOptions.Create;
renameProvider.prepareProvider:=false;
renameProvider.workDoneProgress:=false;
executeCommandProvider:=TExecuteCommandOptions.Create;
executeCommandProvider.commands:=TStringList.Create;
executeCommandProvider.commands.Add(TCommandKind.CompleteCode);
executeCommandProvider.commands.Add(TCommandKind.RemoveUnusedUnit);
end;
end.