From b7955eac38b1e8346da3e017735c87eecfcdd5e4 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 9 Feb 2022 15:31:14 +0100 Subject: [PATCH] finalize inlay hints provider API, https://github.com/microsoft/vscode/issues/16221 --- .../typescript-language-features/package.json | 1 - extensions/vscode-api-tests/package.json | 1 - .../workbench/api/common/extHost.api.impl.ts | 1 - .../common/extensionsApiProposals.ts | 1 - src/vscode-dts/vscode.d.ts | 173 ++++++++++++++++ .../vscode.proposed.inlayHints.d.ts | 188 ------------------ 6 files changed, 173 insertions(+), 192 deletions(-) delete mode 100644 src/vscode-dts/vscode.proposed.inlayHints.d.ts diff --git a/extensions/typescript-language-features/package.json b/extensions/typescript-language-features/package.json index 73c434dec1753..821bff8ebb56e 100644 --- a/extensions/typescript-language-features/package.json +++ b/extensions/typescript-language-features/package.json @@ -8,7 +8,6 @@ "license": "MIT", "aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217", "enabledApiProposals": [ - "inlayHints", "markdownStringBaseUri", "resolvers", "workspaceTrust" diff --git a/extensions/vscode-api-tests/package.json b/extensions/vscode-api-tests/package.json index 1f9007e1fcc89..3719ac8b1ad7d 100644 --- a/extensions/vscode-api-tests/package.json +++ b/extensions/vscode-api-tests/package.json @@ -16,7 +16,6 @@ "fileSearchProvider", "findTextInFiles", "fsChunks", - "inlayHints", "inlineCompletions", "markdownStringBaseUri", "notebookCellExecutionState", diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index ba2cc271a3e53..8a8395db25ccc 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -521,7 +521,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I return extHostLanguages.tokenAtPosition(doc, pos); }, registerInlayHintsProvider(selector: vscode.DocumentSelector, provider: vscode.InlayHintsProvider): vscode.Disposable { - checkProposedApiEnabled(extension, 'inlayHints'); return extHostLanguageFeatures.registerInlayHintsProvider(extension, selector, provider); }, createLanguageStatusItem(id: string, selector: vscode.DocumentSelector): vscode.LanguageStatusItem { diff --git a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts index caf03166e4918..603d60ef93891 100644 --- a/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts +++ b/src/vs/workbench/services/extensions/common/extensionsApiProposals.ts @@ -25,7 +25,6 @@ export const allApiProposals = Object.freeze({ findTextInFiles: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.findTextInFiles.d.ts', fsChunks: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.fsChunks.d.ts', idToken: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.idToken.d.ts', - inlayHints: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.inlayHints.d.ts', inlineCompletions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.inlineCompletions.d.ts', ipc: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.ipc.d.ts', markdownStringBaseUri: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.markdownStringBaseUri.d.ts', diff --git a/src/vscode-dts/vscode.d.ts b/src/vscode-dts/vscode.d.ts index b3403898723ea..ad1275df3edba 100644 --- a/src/vscode-dts/vscode.d.ts +++ b/src/vscode-dts/vscode.d.ts @@ -4567,6 +4567,166 @@ declare module 'vscode' { provideColorPresentations(color: Color, context: { readonly document: TextDocument; readonly range: Range }, token: CancellationToken): ProviderResult; } + /** + * Inlay hint kinds. + * + * The kind of an inline hint defines its appearance, e.g the corresponding foreground and background colors are being + * used. + */ + export enum InlayHintKind { + /** + * An inlay hint that for a type annotation. + */ + Type = 1, + /** + * An inlay hint that is for a parameter. + */ + Parameter = 2, + } + + /** + * An inlay hint label part allows for interactive and composite labels of inlay hints. + */ + export class InlayHintLabelPart { + + /** + * The value of this label part. + */ + value: string; + + /** + * The tooltip text when you hover over this label part. + * + * *Note* that this property can be set late during + * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. + */ + tooltip?: string | MarkdownString | undefined; + + /** + * An optional {@link Location 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. + * + * *Note* that this property can be set late during + * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. + */ + location?: Location | undefined; + + /** + * An optional command for this label part. + * + * The editor renders parts with commands as clickable links. The command is added to the context menu + * when a label part defines {@link InlayHintLabelPart.location location} and {@link InlayHintLabelPart.command command} . + * + * *Note* that this property can be set late during + * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. + */ + command?: Command | undefined; + + /** + * Creates a new inlay hint label part. + * + * @param value The value of the part. + */ + constructor(value: string); + } + + /** + * Inlay hint information. + */ + export class InlayHint { + + /** + * The position of this hint. + */ + position: Position; + + /** + * The label of this hint. A human readable string or an array of {@link InlayHintLabelPart label parts}. + * + * *Note* that neither the string nor the label part can be empty. + */ + label: string | InlayHintLabelPart[]; + + /** + * The tooltip text when you hover over this item. + */ + tooltip?: string | MarkdownString | undefined; + + /** + * Optional command that will be the default gesture of this inlay hint. + */ + command?: Command; + + /** + * The kind of this hint. The inlay hint kind defines the appearance of this inlay hint. + */ + kind?: InlayHintKind; + + /** + * Render padding before the hint. Padding will 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. Padding will 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; + + /** + * Creates a new inlay hint. + * + * @param position The position of the hint. + * @param label The label of the hint. + * @param kind The {@link InlayHintKind kind} of the hint. + */ + constructor(position: Position, label: string | InlayHintLabelPart[], kind?: InlayHintKind); + } + + /** + * The inlay hints provider interface defines the contract between extensions and + * the inlay hints feature. + */ + export interface InlayHintsProvider { + + /** + * An optional event to signal that inlay hints from this provider have changed. + */ + onDidChangeInlayHints?: Event; + + /** + * Provide inlay hints for the given range and document. + * + * *Note* that inlay hints that are not {@link Range.contains contained} by the given range are ignored. + * + * @param document The document in which the command was invoked. + * @param range The range for which inlay hints should be computed. + * @param token A cancellation token. + * @return An array of inlay hints or a thenable that resolves to such. + */ + provideInlayHints(document: TextDocument, range: Range, token: CancellationToken): ProviderResult; + + /** + * Given an inlay hint fill in {@link InlayHint.tooltip tooltip}, {@link InlayHint.command command}, or complete + * label {@link InlayHintLabelPart parts}. + * + * *Note* that the editor will resolve an inlay hint at most once. + * + * @param hint An inlay hint. + * @param token A cancellation token. + * @return The resolved inlay hint or a thenable that resolves to such. It is OK to return the given `item`. When no result is returned, the given `item` will be used. + */ + resolveInlayHint?(hint: T, token: CancellationToken): ProviderResult; + } + /** * A line based folding range. To be valid, start and end line must be bigger than zero and smaller than the number of lines in the document. * Invalid ranges will be ignored. @@ -12002,6 +12162,19 @@ declare module 'vscode' { */ export function registerColorProvider(selector: DocumentSelector, provider: DocumentColorProvider): Disposable; + /** + * Register a inlay hints provider. + * + * Multiple providers can be registered for a language. In that case providers are asked in + * parallel and the results are merged. A failing provider (rejected promise or exception) will + * not cause a failure of the whole operation. + * + * @param selector A selector that defines the documents this provider is applicable to. + * @param provider An inlay hints provider. + * @return A {@link Disposable} that unregisters this provider when being disposed. + */ + export function registerInlayHintsProvider(selector: DocumentSelector, provider: InlayHintsProvider): Disposable; + /** * Register a folding range provider. * diff --git a/src/vscode-dts/vscode.proposed.inlayHints.d.ts b/src/vscode-dts/vscode.proposed.inlayHints.d.ts deleted file mode 100644 index 33a2b1b24c481..0000000000000 --- a/src/vscode-dts/vscode.proposed.inlayHints.d.ts +++ /dev/null @@ -1,188 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -declare module 'vscode' { - - // https://github.com/microsoft/vscode/issues/16221 - - // todo@API support over an optional overlay range - // todo@API all for more InlayHintLabelPart commands - // todo@API allow for InlayHintLabelPart#colors? - - export namespace languages { - /** - * Register a inlay hints provider. - * - * Multiple providers can be registered for a language. In that case providers are asked in - * parallel and the results are merged. A failing provider (rejected promise or exception) will - * not cause a failure of the whole operation. - * - * @param selector A selector that defines the documents this provider is applicable to. - * @param provider An inlay hints provider. - * @return A {@link Disposable} that unregisters this provider when being disposed. - */ - export function registerInlayHintsProvider(selector: DocumentSelector, provider: InlayHintsProvider): Disposable; - } - - /** - * Inlay hint kinds. - * - * The kind of an inline hint defines its appearance, e.g the corresponding foreground and background colors are being - * used. - */ - export enum InlayHintKind { - /** - * An inlay hint that for a type annotation. - */ - Type = 1, - /** - * An inlay hint that is for a parameter. - */ - Parameter = 2, - } - - /** - * An inlay hint label part allows for interactive and composite labels of inlay hints. - */ - export class InlayHintLabelPart { - - /** - * The value of this label part. - */ - value: string; - - /** - * The tooltip text when you hover over this label part. - * - * *Note* that this property can be set late during - * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. - */ - tooltip?: string | MarkdownString | undefined; - - /** - * An optional {@link Location 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. - * - * *Note* that this property can be set late during - * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. - */ - location?: Location | undefined; - - /** - * An optional command for this label part. - * - * The editor renders parts with commands as clickable links. The command is added to the context menu - * when a label part defines {@link InlayHintLabelPart.location location} and {@link InlayHintLabelPart.command command} . - * - * *Note* that this property can be set late during - * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. - */ - command?: Command | undefined; - - /** - * Creates a new inlay hint label part. - * - * @param value The value of the part. - */ - constructor(value: string); - } - - /** - * Inlay hint information. - */ - export class InlayHint { - - /** - * The position of this hint. - */ - position: Position; - - /** - * The label of this hint. A human readable string or an array of {@link InlayHintLabelPart label parts}. - * - * *Note* that neither the string nor the label part can be empty. - */ - label: string | InlayHintLabelPart[]; - - /** - * The tooltip text when you hover over this item. - */ - tooltip?: string | MarkdownString | undefined; - - /** - * Optional command that will be the default gesture of this inlay hint. - */ - command?: Command; - - /** - * The kind of this hint. The inlay hint kind defines the appearance of this inlay hint. - */ - kind?: InlayHintKind; - - /** - * Render padding before the hint. Padding will 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. Padding will 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; - - /** - * Creates a new inlay hint. - * - * @param position The position of the hint. - * @param label The label of the hint. - * @param kind The {@link InlayHintKind kind} of the hint. - */ - constructor(position: Position, label: string | InlayHintLabelPart[], kind?: InlayHintKind); - } - - /** - * The inlay hints provider interface defines the contract between extensions and - * the inlay hints feature. - */ - export interface InlayHintsProvider { - - /** - * An optional event to signal that inlay hints from this provider have changed. - */ - onDidChangeInlayHints?: Event; - - /** - * Provide inlay hints for the given range and document. - * - * *Note* that inlay hints that are not {@link Range.contains contained} by the given range are ignored. - * - * @param document The document in which the command was invoked. - * @param range The range for which inlay hints should be computed. - * @param token A cancellation token. - * @return An array of inlay hints or a thenable that resolves to such. - */ - provideInlayHints(document: TextDocument, range: Range, token: CancellationToken): ProviderResult; - - /** - * Given an inlay hint fill in {@link InlayHint.tooltip tooltip}, {@link InlayHint.command command}, or complete - * label {@link InlayHintLabelPart parts}. - * - * *Note* that the editor will resolve an inlay hint at most once. - * - * @param hint An inlay hint. - * @param token A cancellation token. - * @return The resolved inlay hint or a thenable that resolves to such. It is OK to return the given `item`. When no result is returned, the given `item` will be used. - */ - resolveInlayHint?(hint: T, token: CancellationToken): ProviderResult; - } -}