Skip to content

Commit

Permalink
finalize inlay hints provider API, #16221
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Feb 9, 2022
1 parent 5163f61 commit b7955ea
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 192 deletions.
1 change: 0 additions & 1 deletion extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"license": "MIT",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"enabledApiProposals": [
"inlayHints",
"markdownStringBaseUri",
"resolvers",
"workspaceTrust"
Expand Down
1 change: 0 additions & 1 deletion extensions/vscode-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"fileSearchProvider",
"findTextInFiles",
"fsChunks",
"inlayHints",
"inlineCompletions",
"markdownStringBaseUri",
"notebookCellExecutionState",
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
173 changes: 173 additions & 0 deletions src/vscode-dts/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4567,6 +4567,166 @@ declare module 'vscode' {
provideColorPresentations(color: Color, context: { readonly document: TextDocument; readonly range: Range }, token: CancellationToken): ProviderResult<ColorPresentation[]>;
}

/**
* 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<T extends InlayHint = InlayHint> {

/**
* An optional event to signal that inlay hints from this provider have changed.
*/
onDidChangeInlayHints?: Event<void>;

/**
* 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<T[]>;

/**
* 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<T>;
}

/**
* 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.
Expand Down Expand Up @@ -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.
*
Expand Down
Loading

0 comments on commit b7955ea

Please sign in to comment.