Rename
Rename 请求
重命名请求从客户端发送到服务器,以要求服务器计算工作区更改,以便客户端可以对符号执行工作区范围的重命名。
客户端能力(Client capability):
- 属性路径:
textDocument.rename
- 属性类型:
RenameClientCapabilities
, 定义如下:
export interface RenameClientCapabilities {
/**
* Whether rename supports dynamic registration.
*/
dynamicRegistration?: boolean;
/**
* Client supports testing for validity of rename operations
* before execution.
*
* @since version 3.12.0
*/
prepareSupport?: boolean;
/**
* Client supports the default behavior result
* (`{ defaultBehavior: boolean }`).
*
* The value indicates the default behavior used by the
* client.
*
* @since version 3.16.0
*/
prepareSupportDefaultBehavior?: PrepareSupportDefaultBehavior;
/**
* Whether the client honors the change annotations in
* text edits and resource operations returned via the
* rename request's workspace edit by for example presenting
* the workspace edit in the user interface and asking
* for confirmation.
*
* @since 3.16.0
*/
honorsChangeAnnotations?: boolean;
}
export namespace PrepareSupportDefaultBehavior {
/**
* The client's default behavior is to select the identifier
* according to the language's syntax rule.
*/
export const Identifier: 1 = 1;
}
export type PrepareSupportDefaultBehavior = 1;
服务端能力(Server capability):
- 属性路径:
renameProvider
- 属性类型:
boolean | RenameOptions
, 定义如下:
export interface RenameOptions extends WorkDoneProgressOptions {
/**
* Renames should be checked and tested before being executed.
*/
prepareProvider?: boolean;
}
注册选项(Registration Options): RenameRegistrationOptions
, 定义如下:
export interface RenameRegistrationOptions extends
TextDocumentRegistrationOptions, RenameOptions {
}
请求(Request):
- method: "textDocument/rename"
- params:
RenameParams
, 定义如下:
interface RenameParams extends TextDocumentPositionParams,
WorkDoneProgressParams {
/**
* The new name of the symbol. If the given name is not valid the
* request must return a [ResponseError](#ResponseError) with an
* appropriate message set.
*/
newName: string;
}
响应(Response):
- result:
WorkspaceEdit | null
, 描述对工作区的修改。null
应与WorkspaceEdit
同样对待,表示无需更改。 - error:
code
和message
,以防因任何原因无法执行重命名。示例包括:给定位置没有任何东西可以重命名(如空格),给定符号不支持服务器重命名或代码无效(例如不编译)。
Prepare Rename 请求
从版本 3.12.0 开始
准备重命名请求从客户端发送到服务器,以在给定位置设置和测试重命名操作的有效性。
请求(Request):
- method: "textDocument/prepareRename"
- params:
PrepareRenameParams
, 定义如下:
export interface PrepareRenameParams extends TextDocumentPositionParams, WorkDoneProgressParams {
}
响应(Response):
- result:
Range | { range: Range, placeholder: string } | { defaultBehavior: boolean } | null
, 描述要重命名的字符串的范围和要重命名的字符串内容的占位符文本(可选)。如果返回{ defaultBehavior: boolean }
(从 3.16 开始),则重命名位置有效,客户端应使用其默认行为来计算重命名范围。如果返回null
,则认为textDocument/rename
请求在给定位置无效。 - error:
code
和message
,以防元素无法重命名。客户端应在其用户界面中显示该信息。