Selection Range 请求

从版本 3.15.0 开始

选择范围请求从客户端发送到服务器,以返回给定位置数组的建议选择范围。选择范围是用户可能有兴趣选择的光标位置周围的范围。

返回数组中的选择范围用于同一索引处提供的参数中的位置。因此,positions[i] 必须包含在 result[i].range 中。为了允许某些位置具有选择范围而其他位置没有选择范围的结果,result[i].range 可以是位于 positions[i] 的空范围。

通常,选择范围对应于语法树的节点,但不是必需的。

selection-range

客户端能力(Client capability):

  • 属性路径: textDocument.selectionRange
  • 属性类型: SelectionRangeClientCapabilities, 定义如下:
export interface SelectionRangeClientCapabilities {
	/**
	 * Whether implementation supports dynamic registration for selection range
	 * providers. If this is set to `true` the client supports the new
	 * `SelectionRangeRegistrationOptions` return value for the corresponding
	 * server capability as well.
	 */
	dynamicRegistration?: boolean;
}

服务端能力(Server capability):

  • 属性路径: selectionRangeProvider
  • 属性类型: boolean | SelectionRangeOptions | SelectionRangeRegistrationOptions, 定义如下:
export interface SelectionRangeOptions extends WorkDoneProgressOptions {
}

注册选项(Registration Options): SelectionRangeRegistrationOptions, 定义如下:

export interface SelectionRangeRegistrationOptions extends
	SelectionRangeOptions, TextDocumentRegistrationOptions,
	StaticRegistrationOptions {
}

请求(Request):

  • method: "textDocument/selectionRange"
  • params: SelectionRangeParams, 定义如下:
export interface SelectionRangeParams extends WorkDoneProgressParams,
	PartialResultParams {
	/**
	 * The text document.
	 */
	textDocument: TextDocumentIdentifier;

	/**
	 * The positions inside the text document.
	 */
	positions: Position[];
}

响应(Response):

  • result: SelectionRange[] | null, 定义如下:
export interface SelectionRange {
	/**
	 * The [range](#Range) of this selection range.
	 */
	range: Range;
	/**
	 * The parent selection range containing this range. Therefore
	 * `parent.range` must contain `this.range`.
	 */
	parent?: SelectionRange;
}
  • partial result: SelectionRange[]
  • error: codemessage,以防在请求期间发生异常。