Document Highlights 请求
文档突出显示请求从客户端发送到服务器,以解决给定文本文档位置的文档突出显示问题。对于编程语言,这通常会突出显示对此文件范围的符号的所有引用。但是,我们将 textDocument/documentHighlight
和 textDocument/references
分开,因为第一个请求允许更加模糊。符号匹配通常 DocumentHighlightKind
为 Read
或 Write
,而模糊或文本匹配使用 Text
作为类型。
客户端能力(Client capability):
- 属性路径:
textDocument.documentHighlight
- 属性类型:
DocumentHighlightClientCapabilities
, 定义如下:
export interface DocumentHighlightClientCapabilities {
/**
* Whether document highlight supports dynamic registration.
*/
dynamicRegistration?: boolean;
}
服务端能力(Server capability):
- 属性路径:
documentHighlightProvider
- 属性类型:
boolean | DocumentHighlightOptions
,DocumentHighlightOptions
定义如下:
export interface DocumentHighlightOptions extends WorkDoneProgressOptions {
}
注册选项(Registration Options): DocumentHighlightRegistrationOptions
, 定义如下:
export interface DocumentHighlightRegistrationOptions extends
TextDocumentRegistrationOptions, DocumentHighlightOptions {
}
请求(Request):
- method: "textDocument/documentHighlight"
- params:
DocumentHighlightParams
, 定义如下:
export interface DocumentHighlightParams extends TextDocumentPositionParams,
WorkDoneProgressParams, PartialResultParams {
}
响应(Response):
- result:
DocumentHighlight[] | null
, 定义如下:
/**
* A document highlight is a range inside a text document which deserves
* special attention. Usually a document highlight is visualized by changing
* the background color of its range.
*
*/
export interface DocumentHighlight {
/**
* The range this highlight applies to.
*/
range: Range;
/**
* The highlight kind, default is DocumentHighlightKind.Text.
*/
kind?: DocumentHighlightKind;
}
/**
* A document highlight kind.
*/
export namespace DocumentHighlightKind {
/**
* A textual occurrence.
*/
export const Text = 1;
/**
* Read-access of a symbol, like reading a variable.
*/
export const Read = 2;
/**
* Write-access of a symbol, like writing to a variable.
*/
export const Write = 3;
}
export type DocumentHighlightKind = 1 | 2 | 3;
- partial result:
DocumentHighlight[]
- error:
code
和message
,以防在请求期间发生异常。