|
| 1 | +#### <a href="#textDocument_inlayHints" name="textDocument_inlayHints" class="anchor">Inlay hints</a> |
| 2 | + |
| 3 | +Inlay hints are short textual annotations that are attached to points in the source code. |
| 4 | +These typically spell out some inferred information, such as the parameter name when passing a value to a function. |
| 5 | + |
| 6 | +```typescript |
| 7 | +/** |
| 8 | + * Well-known kinds of information conveyed by InlayHints. |
| 9 | + * Clients may choose which categories to display according to user preferences. |
| 10 | + */ |
| 11 | +export enum InlayHintCategory { |
| 12 | + /** |
| 13 | + * The range is an expression passed as an argument to a function. |
| 14 | + * The label is the name of the parameter. |
| 15 | + */ |
| 16 | + Parameter = 'parameter', |
| 17 | + /** |
| 18 | + * The range is an entity whose type is unknown. |
| 19 | + * The label is its inferred type. |
| 20 | + */ |
| 21 | + Type = 'type' |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +The `textDocument/inlayHints` request is sent from the client to the server to retrieve inlay hints for a document. |
| 26 | + |
| 27 | +_Client Capabilities_: |
| 28 | + |
| 29 | +* property name (optional): `textDocument.inlayHints` |
| 30 | +* property type: `InlayHintsClientCapabilities` defined as follows: |
| 31 | + |
| 32 | +```typescript |
| 33 | +interface InlayHintsClientCapabilities { |
| 34 | + /** |
| 35 | + * Whether implementation supports dynamic registration. If this is set to |
| 36 | + * `true` the client supports the new `(TextDocumentRegistrationOptions & |
| 37 | + * StaticRegistrationOptions)` return value for the corresponding server |
| 38 | + * capability as well. |
| 39 | + */ |
| 40 | + dynamicRegistration?: boolean; |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +_Server Capability_: |
| 45 | + |
| 46 | +* property name (optional): `inlayHintsProvider` |
| 47 | +* property type: `boolean | InlayHintsOptions | InlayHintsRegistrationOptions` is defined as follows: |
| 48 | + |
| 49 | +```typescript |
| 50 | +export interface InlayHintsOptions extends WorkDoneProgressOptions { |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +_Registration Options_: `InlayHintsRegistrationOptions` defined as follows: |
| 55 | + |
| 56 | +```typescript |
| 57 | +export interface InlayHintsRegistrationOptions extends |
| 58 | + TextDocumentRegistrationOptions, InlayHintsOptions { |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +_Request_: |
| 63 | + |
| 64 | +* method: `textDocument/inlayHints` |
| 65 | +* params: `InlayHintsParams` defined as follows: |
| 66 | + |
| 67 | +```typescript |
| 68 | +export interface InlayHintsParams extends WorkDoneProgressParams, PartialResultParams { |
| 69 | + /** |
| 70 | + * The text document. |
| 71 | + */ |
| 72 | + textDocument: TextDocumentIdentifier; |
| 73 | + |
| 74 | + /** |
| 75 | + * The range the inlay hints are requested for. |
| 76 | + * If unset, returns all hints for the document. |
| 77 | + */ |
| 78 | + range?: Range; |
| 79 | + |
| 80 | + /** |
| 81 | + * The categories of inlay hints that are interesting to the client. |
| 82 | + * The client should filter out hints of other categories, so the server may |
| 83 | + * skip computing them. |
| 84 | + */ |
| 85 | + only?: string[]; |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +_Response_: |
| 90 | + |
| 91 | +* result: `InlayHint[]` |
| 92 | +* partial result: `InlayHint[]` |
| 93 | +* error: code and message set in case an exception happens during the 'textDocument/inlayHint' request |
| 94 | + |
| 95 | +`InlayHint` is defined as follows: |
| 96 | + |
| 97 | +```typescript |
| 98 | +/** |
| 99 | + * An inlay hint is a short textual annotation for a range of source code. |
| 100 | + */ |
| 101 | +export interface InlayHint { |
| 102 | + /** |
| 103 | + * The text to be shown. |
| 104 | + */ |
| 105 | + label: string; |
| 106 | + |
| 107 | + /** |
| 108 | + * The position within the code this hint is attached to. |
| 109 | + */ |
| 110 | + position: Position; |
| 111 | + |
| 112 | + /** |
| 113 | + * The kind of information this hint conveys. |
| 114 | + * May be an InlayHintCategory or any other value, clients should treat |
| 115 | + * unrecognized values as if missing. |
| 116 | + */ |
| 117 | + category?: string; |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +**TODO**: Do we need a `/refresh` server->client call, like with SemanticTokens and Code Lens? |
| 122 | + |
| 123 | +**TODO**: Likely future evolution: add a `/resolve` call enabling interactions with hints. Should we foreshadow this? |
0 commit comments