Skip to content

Commit 37cf23b

Browse files
committed
Add text edit support for inlay hints
1 parent 5c2e106 commit 37cf23b

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

client/src/common/codeConverter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ export function createConverter(uriConverter?: URIConverter): Converter {
860860
: item.label.map(asInlayHintLabelPart);
861861
const result = proto.Proposed.InlayHint.create(asPosition(item.position), label);
862862
if (item.kind !== undefined) { result.kind = item.kind; }
863+
if (item.textEdits !== undefined) { result.textEdits = asTextEdits(item.textEdits); }
863864
if (item.tooltip !== undefined) { result.tooltip = asTooltip(item.tooltip); }
864865
if (item.paddingLeft !== undefined) { result.paddingLeft = item.paddingLeft; }
865866
if (item.paddingRight !== undefined) { result.paddingRight = item.paddingRight; }

client/src/common/protocolConverter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ export function createConverter(uriConverter: URIConverter | undefined, trustMar
12031203
: await async.map(value.label, asInlayHintLabelPart, token);
12041204
const result = new code.InlayHint(asPosition(value.position), label);
12051205
if (value.kind !== undefined) { result.kind = value.kind; }
1206+
if (value.textEdits !== undefined) { result.textEdits = await asTextEdits(value.textEdits, token); }
12061207
if (value.tooltip !== undefined) { result.tooltip = asTooltip(value.tooltip); }
12071208
if (value.paddingLeft !== undefined) { result.paddingLeft = value.paddingLeft; }
12081209
if (value.paddingRight !== undefined) { result.paddingRight = value.paddingRight; }

client/typings/vscode.proposed.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,17 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
declare module 'vscode' {
7+
/**
8+
* Inlay hint information.
9+
*/
10+
export interface InlayHint {
11+
/**
12+
* Optional {@link TextEdit text edits} that are performed when accepting this inlay hint. The default
13+
* gesture for accepting an inlay hint is the double click.
14+
*
15+
* *Note* that edits are expected to change the document so that the inlay hint (or its nearest variant) is
16+
* now part of the document and the inlay hint itself is now obsolete.
17+
*/
18+
textEdits?: TextEdit[];
19+
}
720
}

protocol/src/common/proposed.inlayHint.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ export type InlayHint = {
123123
*/
124124
kind?: InlayHintKind;
125125

126+
/**
127+
* Optional text edits that are performed when accepting this inlay hint.
128+
*
129+
* *Note* that edits are expected to change the document so that the inlay
130+
* hint (or its nearest variant) is now part of the document and the inlay
131+
* hint itself is now obsolete.
132+
*/
133+
textEdits?: TextEdit[];
134+
126135
/**
127136
* The tooltip text when you hover over this item.
128137
*/

protocol/src/common/proposed.inlayHint.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { RequestHandler, RequestHandler0 } from 'vscode-jsonrpc';
7-
import { Command, Location, MarkupContent, Position, Range, TextDocumentIdentifier } from 'vscode-languageserver-types';
7+
import { Command, Location, MarkupContent, Position, Range, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver-types';
88
import { ProtocolRequestType, ProtocolRequestType0 } from './messages';
99

1010
import type { StaticRegistrationOptions, TextDocumentRegistrationOptions, WorkDoneProgressOptions, WorkDoneProgressParams } from './protocol';
@@ -162,6 +162,15 @@ export type InlayHint = {
162162
*/
163163
kind?: InlayHintKind;
164164

165+
/**
166+
* Optional text edits that are performed when accepting this inlay hint.
167+
*
168+
* *Note* that edits are expected to change the document so that the inlay
169+
* hint (or its nearest variant) is now part of the document and the inlay
170+
* hint itself is now obsolete.
171+
*/
172+
textEdits?: TextEdit[];
173+
165174
/**
166175
* The tooltip text when you hover over this item.
167176
*/
@@ -201,6 +210,7 @@ export namespace InlayHint {
201210
return Is.objectLiteral(candidate) && Position.is(candidate.position)
202211
&& (Is.string(candidate.label) || Is.typedArray(candidate.label, InlayHintLabelPart.is))
203212
&& (candidate.kind === undefined || InlayHintKind.is(candidate.kind))
213+
&& (candidate.textEdits === undefined) || Is.typedArray(candidate.textEdits, TextEdit.is)
204214
&& (candidate.tooltip === undefined || Is.string(candidate.tooltip) || MarkupContent.is(candidate.tooltip))
205215
&& (candidate.paddingLeft === undefined || Is.boolean(candidate.paddingLeft))
206216
&& (candidate.paddingRight === undefined || Is.boolean(candidate.paddingRight));

0 commit comments

Comments
 (0)