diff --git a/src/vs/editor/common/languages.ts b/src/vs/editor/common/languages.ts index 312f4293829..f68c9d48c59 100644 --- a/src/vs/editor/common/languages.ts +++ b/src/vs/editor/common/languages.ts @@ -190,18 +190,25 @@ export interface HoverProvider { * position will be merged by the editor. A hover can have a range which defaults * to the word range at the position when omitted. */ - provideHover(model: model.ITextModel, position: Position, token: CancellationToken, context?: HoverContext): ProviderResult; + provideHover(model: model.ITextModel, position: Position, token: CancellationToken, context?: HoverContext): ProviderResult; } export interface HoverContext { + /** + * Hover verbosity request + */ + verbosityRequest?: HoverVerbosityRequest; +} + +export interface HoverVerbosityRequest { /** * Whether to increase or decrease the hover's verbosity */ - action?: HoverVerbosityAction; + action: HoverVerbosityAction; /** * The previous hover for the same position */ - previousHover?: THover; + previousHover: THover; } export enum HoverVerbosityAction { diff --git a/src/vs/editor/contrib/hover/browser/markdownHoverParticipant.ts b/src/vs/editor/contrib/hover/browser/markdownHoverParticipant.ts index 7c3030a9362..d8e8baf8d91 100644 --- a/src/vs/editor/contrib/hover/browser/markdownHoverParticipant.ts +++ b/src/vs/editor/contrib/hover/browser/markdownHoverParticipant.ts @@ -352,7 +352,7 @@ class MarkdownRenderedHoverParts extends Disposable { const hoverPosition = hoverRenderedPart.hoverSource.hoverPosition; const hoverProvider = hoverRenderedPart.hoverSource.hoverProvider; const hover = hoverRenderedPart.hoverSource.hover; - const hoverContext: HoverContext = { action, previousHover: hover }; + const hoverContext: HoverContext = { verbosityRequest: { action, previousHover: hover } }; let newHover: Hover | null | undefined; try { diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 99a91de5388..13d15eaba71 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -6852,18 +6852,25 @@ declare namespace monaco.languages { * position will be merged by the editor. A hover can have a range which defaults * to the word range at the position when omitted. */ - provideHover(model: editor.ITextModel, position: Position, token: CancellationToken, context?: HoverContext): ProviderResult; + provideHover(model: editor.ITextModel, position: Position, token: CancellationToken, context?: HoverContext): ProviderResult; } export interface HoverContext { + /** + * Hover verbosity request + */ + verbosityRequest?: HoverVerbosityRequest; + } + + export interface HoverVerbosityRequest { /** * Whether to increase or decrease the hover's verbosity */ - action?: HoverVerbosityAction; + action: HoverVerbosityAction; /** * The previous hover for the same position */ - previousHover?: THover; + previousHover: THover; } export enum HoverVerbosityAction { diff --git a/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts b/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts index 316816a6f9c..2bb88fd7458 100644 --- a/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts +++ b/src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts @@ -256,9 +256,15 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread this._proxy.$releaseHover(handle, hoverId); }); */ - this._registrations.set(handle, this._languageFeaturesService.hoverProvider.register(selector, { - provideHover: async (model: ITextModel, position: EditorPosition, token: CancellationToken, context?: languages.HoverContext<{ id: number }>): Promise => { - const hover = await this._proxy.$provideHover(handle, model.uri, position, context, token); + this._registrations.set(handle, this._languageFeaturesService.hoverProvider.register(selector, >{ + provideHover: async (model: ITextModel, position: EditorPosition, token: CancellationToken, context?: languages.HoverContext): Promise => { + const serializedContext: languages.HoverContext<{ id: number }> = { + verbosityRequest: context?.verbosityRequest ? { + action: context.verbosityRequest.action, + previousHover: { id: context.verbosityRequest.previousHover.id } + } : undefined, + }; + const hover = await this._proxy.$provideHover(handle, model.uri, position, serializedContext, token); // hoverFinalizationRegistry.register(hover, hover.id); return hover; } diff --git a/src/vs/workbench/api/common/extHostLanguageFeatures.ts b/src/vs/workbench/api/common/extHostLanguageFeatures.ts index 51612967509..a50f5371519 100644 --- a/src/vs/workbench/api/common/extHostLanguageFeatures.ts +++ b/src/vs/workbench/api/common/extHostLanguageFeatures.ts @@ -271,13 +271,13 @@ class HoverAdapter { const pos = typeConvert.Position.to(position); let value: vscode.Hover | null | undefined; - if (context && context.previousHover !== undefined && context.action !== undefined) { - const previousHoverId = context.previousHover.id; + if (context && context.verbosityRequest) { + const previousHoverId = context.verbosityRequest.previousHover.id; const previousHover = this._hoverMap.get(previousHoverId); if (!previousHover) { throw new Error(`Hover with id ${previousHoverId} not found`); } - const hoverContext: vscode.HoverContext = { action: context.action, previousHover }; + const hoverContext: vscode.HoverContext = { action: context.verbosityRequest.action, previousHover }; value = await this._provider.provideHover(doc, pos, token, hoverContext); } else { value = await this._provider.provideHover(doc, pos, token);