Workspace fileOperations

WillCreateFiles 请求

在实际创建文件之前,将创建文件请求从客户端发送到服务器,只要创建是从客户端内部触发的,无论是通过用户操作还是应用工作区编辑。该请求可以返回一个 WorkspaceEdit,该 WorkspaceEdit 将在创建文件之前应用于工作区。因此,WorkspaceEdit 无法操作要创建的文件的内容。请注意,如果计算编辑时间过长或服务器在此请求上不断失败,客户端可能会丢弃结果。这样做是为了保持创建的快速和可靠。

客户端能力(Client capability):

  • 属性路径: workspace.fileOperations.willCreate
  • 属性类型: boolean

服务端能力(Server capability):

  • 属性路径: workspace.fileOperations.willCreate
  • 属性类型: FileOperationRegistrationOptions, 定义如下:
/**
 * The options to register for file operations.
 *
 * @since 3.16.0
 */
interface FileOperationRegistrationOptions {
	/**
	 * The actual filters.
	 */
	filters: FileOperationFilter[];
}
/**
 * A pattern kind describing if a glob pattern matches a file a folder or
 * both.
 *
 * @since 3.16.0
 */
export namespace FileOperationPatternKind {
	/**
	 * The pattern matches a file only.
	 */
	export const file: 'file' = 'file';

	/**
	 * The pattern matches a folder only.
	 */
	export const folder: 'folder' = 'folder';
}

export type FileOperationPatternKind = 'file' | 'folder';
/**
 * Matching options for the file operation pattern.
 *
 * @since 3.16.0
 */
export interface FileOperationPatternOptions {

	/**
	 * The pattern should be matched ignoring casing.
	 */
	ignoreCase?: boolean;
}
/**
 * A pattern to describe in which file operation requests or notifications
 * the server is interested in.
 *
 * @since 3.16.0
 */
interface FileOperationPattern {
	/**
	 * The glob pattern to match. Glob patterns can have the following syntax:
	 * - `*` to match one or more characters in a path segment
	 * - `?` to match on one character in a path segment
	 * - `**` to match any number of path segments, including none
	 * - `{}` to group sub patterns into an OR expression. (e.g. `**​/*.{ts,js}`
	 *   matches all TypeScript and JavaScript files)
	 * - `[]` to declare a range of characters to match in a path segment
	 *   (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
	 * - `[!...]` 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`)
	 */
	glob: string;

	/**
	 * Whether to match files or folders with this pattern.
	 *
	 * Matches both if undefined.
	 */
	matches?: FileOperationPatternKind;

	/**
	 * Additional options used during matching.
	 */
	options?: FileOperationPatternOptions;
}

注册选项(Registration Options): undefined

请求(Request):

  • method: "workspace/willCreateFiles"
  • params: CreateFilesParams, 定义如下:
/**
 * The parameters sent in notifications/requests for user-initiated creation
 * of files.
 *
 * @since 3.16.0
 */
export interface CreateFilesParams {

	/**
	 * An array of all files/folders created in this operation.
	 */
	files: FileCreate[];
}
/**
 * Represents information on a file/folder create.
 *
 * @since 3.16.0
 */
export interface FileCreate {

	/**
	 * A file:// URI for the location of the file/folder being created.
	 */
	uri: string;
}

响应(Response):

  • result: WorkspaceEdit | null
  • error: codemessage,以防在请求期间发生异常。

DidCreateFiles 通知

从客户端内创建文件完成后,会从客户端向服务器发送此通知。

客户端能力(Client capability):

  • 属性路径: workspace.fileOperations.didCreate
  • 属性类型: boolean

服务端能力(Server capability):

  • 属性路径: workspace.fileOperations.didCreate
  • 属性类型: FileOperationRegistrationOptions

通知(Notification):

  • method: "workspace/didCreateFiles"
  • params: CreateFilesParams

WillRenameFiles 请求

在实际重命名文件之前,将此请求从客户端发送到服务器,只要重命名是从客户端内部触发的,无论是通过用户操作还是应用工作区编辑。该请求可以返回一个 WorkspaceEdit,该 WorkspaceEdit 将在重命名文件之前应用于工作区。请注意,如果计算编辑时间过长或服务器在此请求上不断失败,客户端可能会丢弃结果。这样做是为了保持重命名的快速和可靠。

客户端能力(Client capability):

  • 属性路径: workspace.fileOperations.willRename
  • 属性类型: boolean

服务端能力(Server capability):

  • 属性路径: workspace.fileOperations.willRename
  • 属性类型: FileOperationRegistrationOptions

注册选项(Registration Options): undefined

请求(Request):

  • method: "workspace/willRenameFiles"
  • params: RenameFilesParams, 定义如下:
/**
 * The parameters sent in notifications/requests for user-initiated renames
 * of files.
 *
 * @since 3.16.0
 */
export interface RenameFilesParams {

	/**
	 * An array of all files/folders renamed in this operation. When a folder
	 * is renamed, only the folder will be included, and not its children.
	 */
	files: FileRename[];
}
/**
 * Represents information on a file/folder rename.
 *
 * @since 3.16.0
 */
export interface FileRename {

	/**
	 * A file:// URI for the original location of the file/folder being renamed.
	 */
	oldUri: string;

	/**
	 * A file:// URI for the new location of the file/folder being renamed.
	 */
	newUri: string;
}

响应(Response):

  • result: WorkspaceEdit | null
  • error: codemessage,以防在请求期间发生异常。

DidRenameFiles 通知

从客户端内部重命名文件完成后,会从客户端向服务器发送此通知。

客户端能力(Client capability):

  • 属性路径: workspace.fileOperations.didRename
  • 属性类型: boolean

服务端能力(Server capability):

  • 属性路径: workspace.fileOperations.didRename
  • 属性类型: FileOperationRegistrationOptions

通知(Notification):

  • method: "workspace/didRenameFiles"
  • params: RenameFilesParams

WillDeleteFiles 请求

在实际删除文件之前,将此请求从客户端发送到服务器,只要删除是从客户端内部触发的,无论是通过用户操作还是应用工作区编辑。该请求可以返回一个 WorkspaceEdit,该 WorkspaceEdit 将在删除文件之前应用于工作区。请注意,如果计算编辑时间过长或服务器在此请求上不断失败,客户端可能会丢弃结果。这样做是为了保持删除的快速和可靠。

客户端能力(Client capability):

  • 属性路径: workspace.fileOperations.willDelete
  • 属性类型: boolean

服务端能力(Server capability):

  • 属性路径: workspace.fileOperations.willDelete
  • 属性类型: FileOperationRegistrationOptions

注册选项(Registration Options): undefined

请求(Request):

  • method: "workspace/willDeleteFiles"
  • params: DeleteFilesParams, 定义如下:
/**
 * The parameters sent in notifications/requests for user-initiated deletes
 * of files.
 *
 * @since 3.16.0
 */
export interface DeleteFilesParams {

	/**
	 * An array of all files/folders deleted in this operation.
	 */
	files: FileDelete[];
}
/**
 * Represents information on a file/folder delete.
 *
 * @since 3.16.0
 */
export interface FileDelete {

	/**
	 * A file:// URI for the location of the file/folder being deleted.
	 */
	uri: string;
}

响应(Response):

  • result: WorkspaceEdit | null, 定义如下:
  • error: codemessage,以防在请求期间发生异常。

DidDeleteFiles 通知

当从客户端中删除文件完成后,此请求会从客户端发送到服务器。

客户端能力(Client capability):

  • 属性路径: workspace.fileOperations.didDelete
  • 属性类型: boolean

服务端能力(Server capability):

  • 属性路径: workspace.fileOperations.didDelete
  • 属性类型: FileOperationRegistrationOptions

注册选项(Registration Options): undefined

通知(Notification):

  • method: "workspace/didDeleteFiles"
  • params: DeleteFilesParams