Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing to add more information to the hover #204721

Closed
wants to merge 102 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
ef39b20
wip
aiday-mar Feb 8, 2024
0a4bef1
adding the boolean extended
aiday-mar Feb 15, 2024
be8a5c1
on shift, we show the extended hover
aiday-mar Feb 15, 2024
3d6459f
creating instead an api proposal
aiday-mar Feb 15, 2024
8727fa8
adding code in order to propagate the extended keyword
aiday-mar Feb 15, 2024
818a6d0
adding code in order to use insead an additional action, show extende…
aiday-mar Feb 15, 2024
3e6b577
making changes so one can transition to more extended information
aiday-mar Feb 15, 2024
423994c
making hover correctly appear
aiday-mar Feb 16, 2024
5c7b3d8
adding a setting and showing instead the extended hover information.
aiday-mar Feb 16, 2024
357e8bf
making chanegs
aiday-mar Feb 16, 2024
e85df6c
polishing the code
aiday-mar Feb 19, 2024
ab57fa9
extending the hover
aiday-mar Mar 6, 2024
d342e4b
adding the actions into a toolbar in the markdown hover when it can b…
aiday-mar Mar 6, 2024
f90f526
adding code in order to align the actions
aiday-mar Mar 7, 2024
c2e2a5e
changing the code so as to directly have the code inside of the markd…
aiday-mar Mar 7, 2024
0f2f5cb
refactoring the code
aiday-mar Mar 8, 2024
e6c0a45
polishing the code
aiday-mar Mar 8, 2024
5addb57
polishing the code
aiday-mar Mar 8, 2024
b263f15
adding the disposable store into the markdown hover participant
aiday-mar Mar 8, 2024
4c56bcb
letting the disposable store be undefined
aiday-mar Mar 8, 2024
a80074a
adding the on contents changes into the extend or constract focused m…
aiday-mar Mar 11, 2024
5b337a6
polish
aiday-mar Mar 11, 2024
6ed3d9f
changing the UI to chevron up and chevron down
aiday-mar Mar 11, 2024
c2accf2
setting different opacity level
aiday-mar Mar 11, 2024
24bee31
removing the refactoring
aiday-mar Mar 11, 2024
3f40d33
fixing compile errors
aiday-mar Mar 11, 2024
4ac442e
Merge branch 'main' into aiday/hoverExtension
aiday-mar Mar 11, 2024
9830188
changing the api
aiday-mar Mar 11, 2024
a288dad
polishing the code
aiday-mar Mar 11, 2024
ec45651
adding proposed api provideHover
aiday-mar Mar 12, 2024
79d8372
renaming the variables
aiday-mar Mar 12, 2024
f97c977
setting the boolean to undefined
aiday-mar Mar 12, 2024
336511a
polishing the code
aiday-mar Mar 12, 2024
ecaf126
polishing the code
aiday-mar Mar 12, 2024
1b66dc0
clearing the map instead
aiday-mar Mar 12, 2024
cb91f82
removing unused import
aiday-mar Mar 12, 2024
7d115e4
exchanging order of parameters, was causing token to be undefined?
aiday-mar Mar 12, 2024
b874755
calling justify content in order to center the content
aiday-mar Mar 13, 2024
dc37c8a
adding tooltip information
aiday-mar Mar 13, 2024
b10f70f
adding the keybinding service as a dependency
aiday-mar Mar 13, 2024
17f474e
using the hover context from the languages folder
aiday-mar Mar 13, 2024
e21fbe2
calling directly the method of interest
aiday-mar Mar 14, 2024
8a24d07
renaming the provider to source provider
aiday-mar Mar 14, 2024
0d4ffa4
adding a comment into the doc string
aiday-mar Mar 14, 2024
380b376
using a delta to increase the level by a specific number
aiday-mar Mar 14, 2024
c507ecd
saving directly the position, not the anchor
aiday-mar Mar 14, 2024
013a803
renaming the proposed API
aiday-mar Mar 14, 2024
e8b1471
separating into action and the enablement state
aiday-mar Mar 14, 2024
38b22ae
renaming the focus info
aiday-mar Mar 14, 2024
079e0ac
redefining the variable _focusInfo
aiday-mar Mar 14, 2024
de10c1a
using an array instead of a map
aiday-mar Mar 14, 2024
38c7a76
using instead the start range
aiday-mar Mar 14, 2024
6e8d8e9
defining directly the type
aiday-mar Mar 14, 2024
3ee89c3
removing the metadata on registration
aiday-mar Mar 14, 2024
1e8b2a3
adding changes directly to class Hover
aiday-mar Mar 14, 2024
f217d6f
placing the icons on the bottom left instead
aiday-mar Mar 14, 2024
b7de695
adding code to enable sending the initial hover
aiday-mar Mar 14, 2024
5fb5bee
Placing the VerboseHover class once again into the proposed API file
aiday-mar Mar 14, 2024
073317f
polishing the code
aiday-mar Mar 14, 2024
94a4e26
checking if the actions should be added as appropriate
aiday-mar Mar 14, 2024
53f1f14
changing font size
aiday-mar Mar 15, 2024
95e9c01
sending the whole hover in the hover context
aiday-mar Mar 15, 2024
7117aa6
saving the hover parts directly
aiday-mar Mar 15, 2024
901296e
render hover parts on markdown hover or verbose markdown hover
aiday-mar Mar 15, 2024
be380d0
polish hover
aiday-mar Mar 15, 2024
f8bcd67
making hover and verbosity action optional in context
aiday-mar Mar 20, 2024
15442c8
range and markdown cloning
aiday-mar Mar 20, 2024
936ff77
do not need the hover indices array
aiday-mar Mar 20, 2024
8a8f1d6
using same disposable store
aiday-mar Mar 20, 2024
9a97a31
changing the order
aiday-mar Mar 20, 2024
a117b51
remove space
aiday-mar Mar 20, 2024
6f5e91d
removing the cloning functions
aiday-mar Mar 21, 2024
7aa73bb
directly placing cloneHover in the map
aiday-mar Mar 21, 2024
710620d
adding changes from review
aiday-mar Apr 2, 2024
59343d0
polishing
aiday-mar Apr 3, 2024
d8bd14b
polishing the code
aiday-mar Apr 4, 2024
cf68733
polishing, requires some more polishing
aiday-mar Apr 4, 2024
e84d450
renaming code
aiday-mar Apr 5, 2024
0c1a32f
making check that hoverpart is of the appropriate type and we can inc…
aiday-mar Apr 5, 2024
94acd4f
Merge branch 'main' into aiday/hoverExtension
aiday-mar Apr 8, 2024
93fc5a9
using instead the hover service setupUpdatableHover instead of setupC…
aiday-mar Apr 8, 2024
d393019
erfactoring the code
aiday-mar Apr 8, 2024
a3cd5a2
check not undefined
aiday-mar Apr 8, 2024
a8a3aa6
polishing the pr
aiday-mar Apr 8, 2024
14df920
renaming the variables
aiday-mar Apr 8, 2024
7bc7c95
changing the condition in the if statement
aiday-mar Apr 8, 2024
7723d46
simplifying the types
aiday-mar Apr 9, 2024
7b1426d
polishing the code
aiday-mar Apr 9, 2024
150ad26
polishing
aiday-mar Apr 10, 2024
484795a
adding disposal logic
aiday-mar Apr 10, 2024
35019d3
adding disposal mechanism
aiday-mar Apr 10, 2024
0935dcc
remove the second parameter
aiday-mar Apr 10, 2024
55f878a
Merge branch 'main' into aiday/hoverExtension
aiday-mar Apr 12, 2024
d8b0bb7
polishing the code
aiday-mar Apr 12, 2024
692d65d
adding a separate file for the hover action ids
aiday-mar Apr 12, 2024
ab029cd
removing horizontal scrollbar checks in the content widget
aiday-mar Apr 12, 2024
d04e6bb
allowing to increase the hover height by 2 px more
aiday-mar Apr 12, 2024
ef2bfb8
wip
aiday-mar Apr 16, 2024
5cbe09f
fixing compiler errors, look again at the code
aiday-mar Apr 16, 2024
66d94ca
Merge branch 'main' into aiday/hoverExtension
aiday-mar Apr 16, 2024
10248d4
fixing some issues after compilation
aiday-mar Apr 16, 2024
910d013
removing spaces
aiday-mar Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ export interface Hover {
* current position itself.
*/
range?: IRange;

/**
* Meta-data concerning whether this hover can be extended/contracted or not
*/
extensionMetadata?: HoverExtensionMetadata;
}

export interface HoverExtensionMetadata {
/**
* Can extend the hover
*/
canExtend?: boolean;

/**
* Can contract the hover
*/
canContract?: boolean;
}

/**
Expand All @@ -175,11 +192,23 @@ export interface Hover {
*/
export interface HoverProvider {
/**
* Provide a hover for the given position and document. Multiple hovers at the same
* Provide a hover for the given position, extension metadata and document. Multiple hovers at the same
* 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): ProviderResult<Hover>;
provideHover(model: model.ITextModel, request: Position | HoverExtensionRequest, token: CancellationToken): ProviderResult<Hover>;
}

export interface HoverExtensionRequest {
/**
* The position for which the hover is requested.
*/
position: Position;

/**
* Wether the request is for an extension or a contraction of the given hover
*/
extend: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ColorContribution extends Disposable implements IEditorContribution
}
if (!hoverController.isColorPickerVisible) {
const range = new Range(target.range.startLineNumber, target.range.startColumn + 1, target.range.endLineNumber, target.range.endColumn + 1);
hoverController.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Mouse, false, true);
hoverController.showContentHover(range, HoverStartSource.Mouse, true, { mode: HoverStartMode.Immediate, focus: false });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class StandaloneColorPickerWidget extends Disposable implements IContentW
const context: IEditorHoverRenderContext = {
fragment,
statusBar,
disposables: undefined,
setColorPicker: (widget: ColorPickerWidget) => colorPickerWidget = widget,
onContentsChanged: () => { },
hide: () => this.hide()
Expand Down
53 changes: 38 additions & 15 deletions src/vs/editor/contrib/hover/browser/contentHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,30 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
import { ResizableContentWidget } from 'vs/editor/contrib/hover/browser/resizableContentWidget';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { MarkdownHoverParticipant } from 'vs/editor/contrib/hover/browser/markdownHoverParticipant';
import { InlayHintsHover } from 'vs/editor/contrib/inlayHints/browser/inlayHintsHover';

const $ = dom.$;

export interface IHoverOptions {
/**
* Start mode of the hover
*/
mode: HoverStartMode;
/**
* Whether the hover should be focused
*/
focus: boolean;
}

export class ContentHoverController extends Disposable {

private _currentResult: HoverResult | null = null;

private readonly _computer: ContentHoverComputer;
private readonly _widget: ContentHoverWidget;
private readonly _participants: IEditorHoverParticipant[];
private readonly _markdownHoverParticipant: MarkdownHoverParticipant | undefined;
private readonly _hoverOperation: HoverOperation<IHoverPart>;

constructor(
Expand All @@ -50,7 +64,11 @@ export class ContentHoverController extends Disposable {
// Instantiate participants and sort them by `hoverOrdinal` which is relevant for rendering order.
this._participants = [];
for (const participant of HoverParticipantRegistry.getAll()) {
this._participants.push(this._instantiationService.createInstance(participant, this._editor));
const participantInstance = this._instantiationService.createInstance(participant, this._editor);
if (participantInstance instanceof MarkdownHoverParticipant && !(participantInstance instanceof InlayHintsHover)) {
this._markdownHoverParticipant = participantInstance;
}
this._participants.push(participantInstance);
}
this._participants.sort((p1, p2) => p1.hoverOrdinal - p2.hoverOrdinal);

Expand Down Expand Up @@ -82,16 +100,15 @@ export class ContentHoverController extends Disposable {
*/
private _startShowingOrUpdateHover(
anchor: HoverAnchor | null,
mode: HoverStartMode,
source: HoverStartSource,
focus: boolean,
mouseEvent: IEditorMouseEvent | null
mouseEvent: IEditorMouseEvent | null,
opts: IHoverOptions
): boolean {

if (!this._widget.position || !this._currentResult) {
// The hover is not visible
if (anchor) {
this._startHoverOperationIfNecessary(anchor, mode, source, focus, false);
this._startHoverOperationIfNecessary(anchor, source, false, opts);
return true;
}
return false;
Expand All @@ -109,7 +126,7 @@ export class ContentHoverController extends Disposable {
// The mouse is getting closer to the hover, so we will keep the hover untouched
// But we will kick off a hover update at the new anchor, insisting on keeping the hover visible.
if (anchor) {
this._startHoverOperationIfNecessary(anchor, mode, source, focus, true);
this._startHoverOperationIfNecessary(anchor, source, true, opts);
}
return true;
}
Expand All @@ -127,29 +144,29 @@ export class ContentHoverController extends Disposable {
if (!anchor.canAdoptVisibleHover(this._currentResult.anchor, this._widget.position)) {
// The new anchor is not compatible with the previous anchor
this._setCurrentResult(null);
this._startHoverOperationIfNecessary(anchor, mode, source, focus, false);
this._startHoverOperationIfNecessary(anchor, source, false, opts);
return true;
}

// We aren't getting any closer to the hover, so we will filter existing results
// and keep those which also apply to the new anchor.
this._setCurrentResult(this._currentResult.filter(anchor));
this._startHoverOperationIfNecessary(anchor, mode, source, focus, false);
this._startHoverOperationIfNecessary(anchor, source, false, opts);
return true;
}

private _startHoverOperationIfNecessary(anchor: HoverAnchor, mode: HoverStartMode, source: HoverStartSource, focus: boolean, insistOnKeepingHoverVisible: boolean): void {
private _startHoverOperationIfNecessary(anchor: HoverAnchor, source: HoverStartSource, insistOnKeepingHoverVisible: boolean, opts: IHoverOptions): void {

if (this._computer.anchor && this._computer.anchor.equals(anchor)) {
// We have to start a hover operation at the exact same anchor as before, so no work is needed
return;
}
this._hoverOperation.cancel();
this._computer.anchor = anchor;
this._computer.shouldFocus = focus;
this._computer.shouldFocus = opts.focus;
this._computer.source = source;
this._computer.insistOnKeepingHoverVisible = insistOnKeepingHoverVisible;
this._hoverOperation.start(mode);
this._hoverOperation.start(opts.mode);
}

private _setCurrentResult(hoverResult: HoverResult | null): void {
Expand Down Expand Up @@ -212,6 +229,7 @@ export class ContentHoverController extends Disposable {
const context: IEditorHoverRenderContext = {
fragment,
statusBar,
disposables,
setColorPicker: (widget) => colorPicker = widget,
onContentsChanged: () => this._widget.onContentsChanged(),
setMinimumDimensions: (dimensions: dom.Dimension) => this._widget.setMinimumDimensions(dimensions),
Expand Down Expand Up @@ -341,16 +359,21 @@ export class ContentHoverController extends Disposable {
}
}

const options = { mode: HoverStartMode.Delayed, focus: false };
if (anchorCandidates.length === 0) {
return this._startShowingOrUpdateHover(null, HoverStartMode.Delayed, HoverStartSource.Mouse, false, mouseEvent);
return this._startShowingOrUpdateHover(null, HoverStartSource.Mouse, mouseEvent, options);
}

anchorCandidates.sort((a, b) => b.priority - a.priority);
return this._startShowingOrUpdateHover(anchorCandidates[0], HoverStartMode.Delayed, HoverStartSource.Mouse, false, mouseEvent);
return this._startShowingOrUpdateHover(anchorCandidates[0], HoverStartSource.Mouse, mouseEvent, options);
}

public startShowingAtRange(range: Range, source: HoverStartSource, opts: IHoverOptions): void {
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
this._startShowingOrUpdateHover(new HoverRangeAnchor(0, range, undefined, undefined), source, null, opts);
}

public startShowingAtRange(range: Range, mode: HoverStartMode, source: HoverStartSource, focus: boolean): void {
this._startShowingOrUpdateHover(new HoverRangeAnchor(0, range, undefined, undefined), mode, source, focus, null);
public async extendOrContractFocusedMessage(extend: boolean): Promise<void> {
this._markdownHoverParticipant?.extendOrContractFocusedMessage(extend);
}

public getWidgetContent(): string | undefined {
Expand Down
82 changes: 73 additions & 9 deletions src/vs/editor/contrib/hover/browser/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ILanguageService } from 'vs/editor/common/languages/language';
import { GotoDefinitionAtPositionEditorContribution } from 'vs/editor/contrib/gotoSymbol/browser/link/goToDefinitionAtPosition';
import { HoverStartMode, HoverStartSource } from 'vs/editor/contrib/hover/browser/hoverOperation';
import { ContentHoverWidget, ContentHoverController } from 'vs/editor/contrib/hover/browser/contentHover';
import { ContentHoverWidget, ContentHoverController, IHoverOptions } from 'vs/editor/contrib/hover/browser/contentHover';
import { MarginHoverWidget } from 'vs/editor/contrib/hover/browser/marginHover';
import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
Expand Down Expand Up @@ -46,8 +46,9 @@ interface IHoverSettings {

interface IHoverState {
mouseDown: boolean;
// TODO @aiday-mar maybe not needed, investigate this
// TODO@aiday-mar maybe not needed, investigate this
contentHoverFocused: boolean;
// TODO@aiday-mar do not place this here
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
activatedByDecoratorClick: boolean;
}

Expand Down Expand Up @@ -325,7 +326,9 @@ export class HoverController extends Disposable implements IEditorContribution {
const mightTriggerFocus = (
resolvedKeyboardEvent.kind === ResultKind.MoreChordsNeeded ||
(resolvedKeyboardEvent.kind === ResultKind.KbFound
&& resolvedKeyboardEvent.commandId === 'editor.action.showHover'
&& (resolvedKeyboardEvent.commandId === 'editor.action.showHover'
|| resolvedKeyboardEvent.commandId === 'editor.action.showMoreHoverInformation'
|| resolvedKeyboardEvent.commandId === 'editor.action.showLessHoverInformation')
&& this._contentWidget?.isVisible
)
);
Expand Down Expand Up @@ -384,13 +387,16 @@ export class HoverController extends Disposable implements IEditorContribution {

public showContentHover(
range: Range,
mode: HoverStartMode,
source: HoverStartSource,
focus: boolean,
activatedByColorDecoratorClick: boolean = false
activatedByColorDecoratorClick: boolean = false,
hoverOptions: IHoverOptions
): void {
this._hoverState.activatedByDecoratorClick = activatedByColorDecoratorClick;
this._getOrCreateContentWidget().startShowingAtRange(range, mode, source, focus);
this._getOrCreateContentWidget().startShowingAtRange(range, source, hoverOptions);
}

public extendOrContractFocusedMessage(extend: boolean): void {
this._getOrCreateContentWidget().extendOrContractFocusedMessage(extend);
}

public focus(): void {
Expand Down Expand Up @@ -521,7 +527,7 @@ class ShowOrFocusHoverAction extends EditorAction {
const showContentHover = (focus: boolean) => {
const position = editor.getPosition();
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
controller.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Keyboard, focus);
controller.showContentHover(range, HoverStartSource.Keyboard, false, { mode: HoverStartMode.Immediate, focus });
};

const accessibilitySupportEnabled = editor.getOption(EditorOption.accessibilitySupport) === AccessibilitySupport.Enabled;
Expand Down Expand Up @@ -574,7 +580,7 @@ class ShowDefinitionPreviewHoverAction extends EditorAction {

const promise = goto.startFindDefinitionFromCursor(position);
promise.then(() => {
controller.showContentHover(range, HoverStartMode.Immediate, HoverStartSource.Keyboard, true);
controller.showContentHover(range, HoverStartSource.Keyboard, false, { mode: HoverStartMode.Immediate, focus: true });
});
}
}
Expand Down Expand Up @@ -825,6 +831,62 @@ class GoToBottomHoverAction extends EditorAction {
}
}

class ShowMoreHoverInformationAction extends EditorAction {

constructor() {
super({
id: 'editor.action.showMoreHoverInformation',
label: nls.localize({
key: 'showMoreHoverInformation',
comment: ['Label for action that will trigger showing more hover information.']
}, "Show More Hover Information"),
alias: 'Show More Hover Information',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyP),
weight: KeybindingWeight.EditorContrib
}
});
}

public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
extendOrContractFocusedMessage(editor, true);
}
}

class ShowLessHoverInformationAction extends EditorAction {

constructor() {
super({
id: 'editor.action.showLessHoverInformation',
label: nls.localize({
key: 'showLessHoverInformation',
comment: ['Label for action that will trigger showing less hover information.']
}, "Show Less Hover Information"),
alias: 'Show Less Hover Information',
precondition: EditorContextKeys.hoverFocused,
kbOpts: {
kbExpr: EditorContextKeys.hoverFocused,
primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyMod.CtrlCmd | KeyCode.KeyM),
weight: KeybindingWeight.EditorContrib
}
});
}

public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
extendOrContractFocusedMessage(editor, false);
}
aiday-mar marked this conversation as resolved.
Show resolved Hide resolved
}

export function extendOrContractFocusedMessage(editor: ICodeEditor, extend: boolean) {
const controller = HoverController.get(editor);
if (!controller) {
return;
}
controller.extendOrContractFocusedMessage(extend);
}

registerEditorContribution(HoverController.ID, HoverController, EditorContributionInstantiation.BeforeFirstInteraction);
registerEditorAction(ShowOrFocusHoverAction);
registerEditorAction(ShowDefinitionPreviewHoverAction);
Expand All @@ -836,6 +898,8 @@ registerEditorAction(PageUpHoverAction);
registerEditorAction(PageDownHoverAction);
registerEditorAction(GoToTopHoverAction);
registerEditorAction(GoToBottomHoverAction);
registerEditorAction(ShowMoreHoverInformationAction);
registerEditorAction(ShowLessHoverInformationAction);
HoverParticipantRegistry.register(MarkdownHoverParticipant);
HoverParticipantRegistry.register(MarkerHoverParticipant);

Expand Down
6 changes: 5 additions & 1 deletion src/vs/editor/contrib/hover/browser/hoverTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Dimension } from 'vs/base/browser/dom';
import { AsyncIterableObject } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { ICodeEditor, IEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
Expand Down Expand Up @@ -103,6 +103,10 @@ export interface IEditorHoverRenderContext {
* The status bar for actions for this hover.
*/
readonly statusBar: IEditorHoverStatusBar;
/**
* The disposable store for the hover
*/
readonly disposables: DisposableStore | undefined;
Copy link
Member

@hediet hediet Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unclear to me.
Is the IEditorHoverRenderContext disposable? Who calls disposables.dispose()?

Copy link
Contributor Author

@aiday-mar aiday-mar Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes so the disposable store is created here:

const disposables = new DisposableStore();

I pass it into the context here:

const context: IEditorHoverRenderContext = {

It is also passed in the showAt method here:

this._widget.showAt(fragment, new ContentHoverVisibleData(

The context is saved in the field this._hoverData. When the hover is hidden, the code always calls _setHoverData with undefined:

this._setHoverData(undefined);

Finally inside of _setHoverData we dispose the store:

this._visibleData?.disposables.dispose();

/**
* Set if the hover will render a color picker widget.
*/
Expand Down
Loading
Loading