Inlay Hint

Inlay Hint 请求

镶嵌提示请求从客户端发送到服务器,以计算给定 [text document, range] 元组的镶嵌提示,这些元组可以在编辑器中与其他文本一起呈现。

inlay-hint

客户端能力(Client capability):

  • 属性路径: textDocument.inlayHint
  • 属性类型: InlayHintClientCapabilities, 定义如下:
/**
 * Inlay hint client capabilities.
 *
 * @since 3.17.0
 */
export interface InlayHintClientCapabilities {

	/**
	 * Whether inlay hints support dynamic registration.
	 */
	dynamicRegistration?: boolean;

	/**
	 * Indicates which properties a client can resolve lazily on an inlay
	 * hint.
	 */
	resolveSupport?: {

		/**
		 * The properties that a client can resolve lazily.
		 */
		properties: string[];
	};
}

服务端能力(Server capability):

  • 属性路径: inlayHintProvider
  • 属性类型: InlayHintOptions, 定义如下:
/**
 * Inlay hint options used during static registration.
 *
 * @since 3.17.0
 */
export interface InlayHintOptions extends WorkDoneProgressOptions {
	/**
	 * The server provides support to resolve additional
	 * information for an inlay hint item.
	 */
	resolveProvider?: boolean;
}

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

/**
 * Inlay hint options used during static or dynamic registration.
 *
 * @since 3.17.0
 */
export interface InlayHintRegistrationOptions extends InlayHintOptions,
	TextDocumentRegistrationOptions, StaticRegistrationOptions {
}

请求(Request):

  • method: "textDocument/inlayHint"
  • params: InlayHintParams, 定义如下:
/**
 * A parameter literal used in inlay hint requests.
 *
 * @since 3.17.0
 */
export interface InlayHintParams extends WorkDoneProgressParams {
	/**
	 * The text document.
	 */
	textDocument: TextDocumentIdentifier;

	/**
	 * The visible document range for which inlay hints should be computed.
	 */
	range: Range;
}

响应(Response):

  • result: InlayHint[] | null, 定义如下:
/**
 * Inlay hint information.
 *
 * @since 3.17.0
 */
export interface InlayHint {

	/**
	 * The position of this hint.
	 * 
	 * If multiple hints have the same position, they will be shown in the order
	 * they appear in the response.
	 */
	position: Position;

	/**
	 * The label of this hint. A human readable string or an array of
	 * InlayHintLabelPart label parts.
	 *
	 * *Note* that neither the string nor the label part can be empty.
	 */
	label: string | InlayHintLabelPart[];

	/**
	 * The kind of this hint. Can be omitted in which case the client
	 * should fall back to a reasonable default.
	 */
	kind?: InlayHintKind;

	/**
	 * Optional text edits that are performed when accepting this inlay hint.
	 *
	 * *Note* that edits are expected to change the document so that the inlay
	 * hint (or its nearest variant) is now part of the document and the inlay
	 * hint itself is now obsolete.
	 *
	 * Depending on the client capability `inlayHint.resolveSupport` clients
	 * might resolve this property late using the resolve request.
	 */
	textEdits?: TextEdit[];

	/**
	 * The tooltip text when you hover over this item.
	 *
	 * Depending on the client capability `inlayHint.resolveSupport` clients
	 * might resolve this property late using the resolve request.
	 */
	tooltip?: string | MarkupContent;

	/**
	 * Render padding before the hint.
	 *
	 * Note: Padding should use the editor's background color, not the
	 * background color of the hint itself. That means padding can be used
	 * to visually align/separate an inlay hint.
	 */
	paddingLeft?: boolean;

	/**
	 * Render padding after the hint.
	 *
	 * Note: Padding should use the editor's background color, not the
	 * background color of the hint itself. That means padding can be used
	 * to visually align/separate an inlay hint.
	 */
	paddingRight?: boolean;


	/**
	 * A data entry field that is preserved on an inlay hint between
	 * a `textDocument/inlayHint` and a `inlayHint/resolve` request.
	 */
	data?: LSPAny;
}
/**
 * An inlay hint label part allows for interactive and composite labels
 * of inlay hints.
 *
 * @since 3.17.0
 */
export interface InlayHintLabelPart {

	/**
	 * The value of this label part.
	 */
	value: string;

	/**
	 * The tooltip text when you hover over this label part. Depending on
	 * the client capability `inlayHint.resolveSupport` clients might resolve
	 * this property late using the resolve request.
	 */
	tooltip?: string | MarkupContent;

	/**
	 * An optional source code location that represents this
	 * label part.
	 *
	 * The editor will use this location for the hover and for code navigation
	 * features: This part will become a clickable link that resolves to the
	 * definition of the symbol at the given location (not necessarily the
	 * location itself), it shows the hover that shows at the given location,
	 * and it shows a context menu with further code navigation commands.
	 *
	 * Depending on the client capability `inlayHint.resolveSupport` clients
	 * might resolve this property late using the resolve request.
	 */
	location?: Location;

	/**
	 * An optional command for this label part.
	 *
	 * Depending on the client capability `inlayHint.resolveSupport` clients
	 * might resolve this property late using the resolve request.
	 */
	command?: Command;
}
/**
 * Inlay hint kinds.
 *
 * @since 3.17.0
 */
export namespace InlayHintKind {

	/**
	 * An inlay hint that for a type annotation.
	 */
	export const Type = 1;

	/**
	 * An inlay hint that is for a parameter.
	 */
	export const Parameter = 2;
}

export type InlayHintKind = 1 | 2;
  • error: codemessage,以防在请求期间发生异常。

Inlay Hint Resolve 请求

从版本 3.17.0 开始

请求从客户端发送到服务器,以解析给定镶嵌提示的附加信息。这通常用于计算镶嵌提示的 label 部分的 tooltiplocationcommand 属性,以避免在 textDocument/inlayHint 请求期间进行不必要的计算。

假设客户端将 label.location 属性宣布为可以使用客户端能力延迟解析的属性:

textDocument.inlayHint.resolveSupport = { properties: ['label.location'] };

然后,需要使用 inlayHint/resolve 请求解析带有 没有 location 的 label 部分的镶嵌提示,然后才能使用。

客户端能力(Client capability):

  • 属性路径: textDocument.inlayHint.resolveSupport
  • 属性类型: { properties: string[]; }

请求(Request):

  • method: "inlayHint/resolve"
  • params: InlayHint

响应(Response):

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

Inlay Hint Refresh 请求

从版本 3.17.0 开始

请求从服务器发送到客户端。服务器可以使用它来要求客户端刷新当前显示在编辑器中的镶嵌提示。因此,客户端应要求服务器重新计算这些编辑器的镶嵌提示。如果服务器检测到需要重新计算所有镶嵌提示的配置更改,这将非常有用。请注意,例如,如果编辑器当前不可见,客户端仍然可以自由延迟镶嵌提示的重新计算。

客户端能力(Client capability):

  • 属性路径: workspace.inlayHint
  • 属性类型: InlayHintWorkspaceClientCapabilities, 定义如下:
/**
 * Client workspace capabilities specific to inlay hints.
 *
 * @since 3.17.0
 */
export interface InlayHintWorkspaceClientCapabilities {
	/**
	 * Whether the client implementation supports a refresh request sent from
	 * the server to the client.
	 *
	 * Note that this event is global and will force the client to refresh all
	 * inlay hints currently shown. It should be used with absolute care and
	 * is useful for situation where a server for example detects a project wide
	 * change that requires such a calculation.
	 */
	refreshSupport?: boolean;
}

请求(Request):

  • method: "workspace/inlayHint/refresh"
  • params: none

响应(Response):

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