Document Color
Document Color 请求
从版本 3.6.0 开始
文档颜色请求从客户端发送到服务器,以列出在给定文本文档中找到的所有颜色参考。与范围一起,返回 RGB 中的颜色值。
客户端可以使用结果在编辑器中修饰颜色参考。例如:
-
在参照旁边显示实际颜色的颜色框
-
编辑颜色参考时显示颜色选取器
客户端能力(Client capability):
- 属性路径:
textDocument.colorProvider
- 属性类型:
DocumentColorClientCapabilities
, 定义如下:
export interface DocumentColorClientCapabilities {
/**
* Whether document color supports dynamic registration.
*/
dynamicRegistration?: boolean;
}
服务端能力(Server capability):
- 属性路径:
colorProvider
- 属性类型:
boolean | DocumentColorOptions | DocumentColorRegistrationOptions
, 定义如下:
export interface DocumentColorOptions extends WorkDoneProgressOptions {
}
注册选项(Registration Options): DocumentColorRegistrationOptions
, 定义如下:
export interface DocumentColorRegistrationOptions extends
TextDocumentRegistrationOptions, StaticRegistrationOptions,
DocumentColorOptions {
}
请求(Request):
- method: "textDocument/documentColor"
- params:
DocumentColorParams
, 定义如下:
interface DocumentColorParams extends WorkDoneProgressParams,
PartialResultParams {
/**
* The text document.
*/
textDocument: TextDocumentIdentifier;
}
响应(Response):
- result:
ColorInformation[]
, 定义如下:
interface ColorInformation {
/**
* The range in the document where this color appears.
*/
range: Range;
/**
* The actual color value for this color range.
*/
color: Color;
}
/**
* Represents a color in RGBA space.
*/
interface Color {
/**
* The red component of this color in the range [0-1].
*/
readonly red: decimal;
/**
* The green component of this color in the range [0-1].
*/
readonly green: decimal;
/**
* The blue component of this color in the range [0-1].
*/
readonly blue: decimal;
/**
* The alpha component of this color in the range [0-1].
*/
readonly alpha: decimal;
}
- partial result:
ColorInformation[]
- error:
code
和message
,以防在请求期间发生异常。
Color Presentation 请求
从版本 3.6.0 开始
颜色表示请求从客户端发送到服务器,以获取给定位置颜色值的表示列表。客户端可以使用结果来
- 修改颜色参考。
- 在颜色选取器中显示,并允许用户选择其中一个演示文稿
此请求没有特殊功能和注册选项,因为它是作为 textDocument/documentColor
请求的解析请求发送的。
请求(Request):
- method: "textDocument/colorPresentation"
- params:
ColorPresentationParams
, 定义如下:
interface ColorPresentationParams extends WorkDoneProgressParams,
PartialResultParams {
/**
* The text document.
*/
textDocument: TextDocumentIdentifier;
/**
* The color information to request presentations for.
*/
color: Color;
/**
* The range where the color would be inserted. Serves as a context.
*/
range: Range;
}
响应(Response):
- result:
ColorPresentation[]
, 定义如下:
interface ColorPresentation {
/**
* The label of this color presentation. It will be shown on the color
* picker header. By default this is also the text that is inserted when
* selecting this color presentation.
*/
label: string;
/**
* An [edit](#TextEdit) which is applied to a document when selecting
* this presentation for the color. When omitted the
* [label](#ColorPresentation.label) is used.
*/
textEdit?: TextEdit;
/**
* An optional array of additional [text edits](#TextEdit) that are applied
* when selecting this color presentation. Edits must not overlap with the
* main [edit](#ColorPresentation.textEdit) nor with themselves.
*/
additionalTextEdits?: TextEdit[];
}
- partial result:
ColorPresentation[]
- error:
code
和message
,以防在请求期间发生异常。