UNPKG

9.61 kBTypeScriptView Raw
1import { NotificationHandler, RequestHandler } from 'vscode-jsonrpc';
2import { WorkspaceEdit } from 'vscode-languageserver-types';
3import { MessageDirection, ProtocolNotificationType, ProtocolRequestType } from './messages';
4/**
5 * Options for notifications/requests for user operations on files.
6 *
7 * @since 3.16.0
8 */
9export interface FileOperationOptions {
10 /**
11 * The server is interested in receiving didCreateFiles notifications.
12 */
13 didCreate?: FileOperationRegistrationOptions;
14 /**
15 * The server is interested in receiving willCreateFiles requests.
16 */
17 willCreate?: FileOperationRegistrationOptions;
18 /**
19 * The server is interested in receiving didRenameFiles notifications.
20 */
21 didRename?: FileOperationRegistrationOptions;
22 /**
23 * The server is interested in receiving willRenameFiles requests.
24 */
25 willRename?: FileOperationRegistrationOptions;
26 /**
27 * The server is interested in receiving didDeleteFiles file notifications.
28 */
29 didDelete?: FileOperationRegistrationOptions;
30 /**
31 * The server is interested in receiving willDeleteFiles file requests.
32 */
33 willDelete?: FileOperationRegistrationOptions;
34}
35/**
36 * The options to register for file operations.
37 *
38 * @since 3.16.0
39 */
40export interface FileOperationRegistrationOptions {
41 /**
42 * The actual filters.
43 */
44 filters: FileOperationFilter[];
45}
46/**
47 * A pattern kind describing if a glob pattern matches a file a folder or
48 * both.
49 *
50 * @since 3.16.0
51 */
52export declare namespace FileOperationPatternKind {
53 /**
54 * The pattern matches a file only.
55 */
56 const file: 'file';
57 /**
58 * The pattern matches a folder only.
59 */
60 const folder: 'folder';
61}
62export type FileOperationPatternKind = 'file' | 'folder';
63/**
64 * Matching options for the file operation pattern.
65 *
66 * @since 3.16.0
67 */
68export interface FileOperationPatternOptions {
69 /**
70 * The pattern should be matched ignoring casing.
71 */
72 ignoreCase?: boolean;
73}
74/**
75 * A pattern to describe in which file operation requests or notifications
76 * the server is interested in receiving.
77 *
78 * @since 3.16.0
79 */
80interface FileOperationPattern {
81 /**
82 * The glob pattern to match. Glob patterns can have the following syntax:
83 * - `*` to match one or more characters in a path segment
84 * - `?` to match on one character in a path segment
85 * - `**` to match any number of path segments, including none
86 * - `{}` to group sub patterns into an OR expression. (e.g. `**​/*.{ts,js}` matches all TypeScript and JavaScript files)
87 * - `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
88 * - `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
89 */
90 glob: string;
91 /**
92 * Whether to match files or folders with this pattern.
93 *
94 * Matches both if undefined.
95 */
96 matches?: FileOperationPatternKind;
97 /**
98 * Additional options used during matching.
99 */
100 options?: FileOperationPatternOptions;
101}
102/**
103 * A filter to describe in which file operation requests or notifications
104 * the server is interested in receiving.
105 *
106 * @since 3.16.0
107 */
108export interface FileOperationFilter {
109 /**
110 * A Uri scheme like `file` or `untitled`.
111 */
112 scheme?: string;
113 /**
114 * The actual file operation pattern.
115 */
116 pattern: FileOperationPattern;
117}
118/**
119 * Capabilities relating to events from file operations by the user in the client.
120 *
121 * These events do not come from the file system, they come from user operations
122 * like renaming a file in the UI.
123 *
124 * @since 3.16.0
125 */
126export interface FileOperationClientCapabilities {
127 /**
128 * Whether the client supports dynamic registration for file requests/notifications.
129 */
130 dynamicRegistration?: boolean;
131 /**
132 * The client has support for sending didCreateFiles notifications.
133 */
134 didCreate?: boolean;
135 /**
136 * The client has support for sending willCreateFiles requests.
137 */
138 willCreate?: boolean;
139 /**
140 * The client has support for sending didRenameFiles notifications.
141 */
142 didRename?: boolean;
143 /**
144 * The client has support for sending willRenameFiles requests.
145 */
146 willRename?: boolean;
147 /**
148 * The client has support for sending didDeleteFiles notifications.
149 */
150 didDelete?: boolean;
151 /**
152 * The client has support for sending willDeleteFiles requests.
153 */
154 willDelete?: boolean;
155}
156/**
157 * The parameters sent in notifications/requests for user-initiated creation of
158 * files.
159 *
160 * @since 3.16.0
161 */
162export interface CreateFilesParams {
163 /**
164 * An array of all files/folders created in this operation.
165 */
166 files: FileCreate[];
167}
168/**
169 * Represents information on a file/folder create.
170 *
171 * @since 3.16.0
172 */
173export interface FileCreate {
174 /**
175 * A file:// URI for the location of the file/folder being created.
176 */
177 uri: string;
178}
179/**
180 * The parameters sent in notifications/requests for user-initiated renames of
181 * files.
182 *
183 * @since 3.16.0
184 */
185export interface RenameFilesParams {
186 /**
187 * An array of all files/folders renamed in this operation. When a folder is renamed, only
188 * the folder will be included, and not its children.
189 */
190 files: FileRename[];
191}
192/**
193 * Represents information on a file/folder rename.
194 *
195 * @since 3.16.0
196 */
197export interface FileRename {
198 /**
199 * A file:// URI for the original location of the file/folder being renamed.
200 */
201 oldUri: string;
202 /**
203 * A file:// URI for the new location of the file/folder being renamed.
204 */
205 newUri: string;
206}
207/**
208 * The parameters sent in notifications/requests for user-initiated deletes of
209 * files.
210 *
211 * @since 3.16.0
212 */
213export interface DeleteFilesParams {
214 /**
215 * An array of all files/folders deleted in this operation.
216 */
217 files: FileDelete[];
218}
219/**
220 * Represents information on a file/folder delete.
221 *
222 * @since 3.16.0
223 */
224export interface FileDelete {
225 /**
226 * A file:// URI for the location of the file/folder being deleted.
227 */
228 uri: string;
229}
230/**
231 * The will create files request is sent from the client to the server before files are actually
232 * created as long as the creation is triggered from within the client.
233 *
234 * The request can return a `WorkspaceEdit` which will be applied to workspace before the
235 * files are created. Hence the `WorkspaceEdit` can not manipulate the content of the file
236 * to be created.
237 *
238 * @since 3.16.0
239 */
240export declare namespace WillCreateFilesRequest {
241 const method: 'workspace/willCreateFiles';
242 const messageDirection: MessageDirection;
243 const type: ProtocolRequestType<CreateFilesParams, WorkspaceEdit | null, never, void, FileOperationRegistrationOptions>;
244 type HandlerSignature = RequestHandler<CreateFilesParams, WorkspaceEdit | undefined | null, void>;
245}
246/**
247 * The did create files notification is sent from the client to the server when
248 * files were created from within the client.
249 *
250 * @since 3.16.0
251 */
252export declare namespace DidCreateFilesNotification {
253 const method: 'workspace/didCreateFiles';
254 const messageDirection: MessageDirection;
255 const type: ProtocolNotificationType<CreateFilesParams, FileOperationRegistrationOptions>;
256 type HandlerSignature = NotificationHandler<CreateFilesParams>;
257}
258/**
259 * The will rename files request is sent from the client to the server before files are actually
260 * renamed as long as the rename is triggered from within the client.
261 *
262 * @since 3.16.0
263 */
264export declare namespace WillRenameFilesRequest {
265 const method: 'workspace/willRenameFiles';
266 const messageDirection: MessageDirection;
267 const type: ProtocolRequestType<RenameFilesParams, WorkspaceEdit | null, never, void, FileOperationRegistrationOptions>;
268 type HandlerSignature = RequestHandler<RenameFilesParams, WorkspaceEdit | undefined | null, void>;
269}
270/**
271 * The did rename files notification is sent from the client to the server when
272 * files were renamed from within the client.
273 *
274 * @since 3.16.0
275 */
276export declare namespace DidRenameFilesNotification {
277 const method: 'workspace/didRenameFiles';
278 const messageDirection: MessageDirection;
279 const type: ProtocolNotificationType<RenameFilesParams, FileOperationRegistrationOptions>;
280 type HandlerSignature = NotificationHandler<RenameFilesParams>;
281}
282/**
283 * The will delete files request is sent from the client to the server before files are actually
284 * deleted as long as the deletion is triggered from within the client.
285 *
286 * @since 3.16.0
287 */
288export declare namespace DidDeleteFilesNotification {
289 const method: 'workspace/didDeleteFiles';
290 const messageDirection: MessageDirection;
291 const type: ProtocolNotificationType<DeleteFilesParams, FileOperationRegistrationOptions>;
292 type HandlerSignature = NotificationHandler<DeleteFilesParams>;
293}
294/**
295 * The did delete files notification is sent from the client to the server when
296 * files were deleted from within the client.
297 *
298 * @since 3.16.0
299 */
300export declare namespace WillDeleteFilesRequest {
301 const method: 'workspace/willDeleteFiles';
302 const messageDirection: MessageDirection;
303 const type: ProtocolRequestType<DeleteFilesParams, WorkspaceEdit | null, never, void, FileOperationRegistrationOptions>;
304 type HandlerSignature = RequestHandler<DeleteFilesParams, WorkspaceEdit | undefined | null, void>;
305}
306export {};