diff --git a/src/vs/editor/contrib/hover/hover.ts b/src/vs/editor/contrib/hover/hover.ts index 1fdad70ae85ba10b55867a5405ce2b05f00a0748..ddbc96953b3ea32f045016bbf20e6ae5468fd22c 100644 --- a/src/vs/editor/contrib/hover/hover.ts +++ b/src/vs/editor/contrib/hover/hover.ts @@ -24,6 +24,7 @@ import { editorHoverHighlight, editorHoverBackground, editorHoverBorder, textLin import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer'; import { IEmptyContentData } from 'vs/editor/browser/controller/mouseTarget'; +import { HoverStartMode } from 'vs/editor/contrib/hover/hoverOperation'; export class ModesHoverController implements editorCommon.IEditorContribution { @@ -143,7 +144,7 @@ export class ModesHoverController implements editorCommon.IEditorContribution { if (this._editor.getConfiguration().contribInfo.hover && targetType === MouseTargetType.CONTENT_TEXT) { this.glyphWidget.hide(); - this.contentWidget.startShowingAt(mouseEvent.target.range, false); + this.contentWidget.startShowingAt(mouseEvent.target.range, HoverStartMode.Delayed, false); } else if (targetType === MouseTargetType.GUTTER_GLYPH_MARGIN) { this.contentWidget.hide(); this.glyphWidget.startShowingAt(mouseEvent.target.position.lineNumber); @@ -174,8 +175,8 @@ export class ModesHoverController implements editorCommon.IEditorContribution { this._glyphWidget = new ModesGlyphHoverWidget(this._editor, renderer); } - public showContentHover(range: Range, focus: boolean): void { - this.contentWidget.startShowingAt(range, focus); + public showContentHover(range: Range, mode: HoverStartMode, focus: boolean): void { + this.contentWidget.startShowingAt(range, mode, focus); } public getId(): string { @@ -223,7 +224,7 @@ class ShowHoverAction extends EditorAction { } const position = editor.getPosition(); const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column); - controller.showContentHover(range, true); + controller.showContentHover(range, HoverStartMode.Immediate, true); } } diff --git a/src/vs/editor/contrib/hover/hoverOperation.ts b/src/vs/editor/contrib/hover/hoverOperation.ts index 432f710711629e96959563e8918e19474b5c03a0..3fdc36ff02fd44a17bdee2c37600aef4b968dd62 100644 --- a/src/vs/editor/contrib/hover/hoverOperation.ts +++ b/src/vs/editor/contrib/hover/hoverOperation.ts @@ -46,6 +46,11 @@ const enum ComputeHoverOperationState { WAITING_FOR_ASYNC_COMPUTATION = 3 } +export const enum HoverStartMode { + Delayed = 0, + Immediate = 1 +} + export class HoverOperation { static HOVER_TIME = 300; @@ -152,11 +157,25 @@ export class HoverOperation { } } - public start(): void { - if (this._state === ComputeHoverOperationState.IDLE) { - this._state = ComputeHoverOperationState.FIRST_WAIT; - this._firstWaitScheduler.schedule(); - this._loadingMessageScheduler.schedule(); + public start(mode: HoverStartMode): void { + if (mode === HoverStartMode.Delayed) { + if (this._state === ComputeHoverOperationState.IDLE) { + this._state = ComputeHoverOperationState.FIRST_WAIT; + this._firstWaitScheduler.schedule(); + this._loadingMessageScheduler.schedule(); + } + } else { + switch (this._state) { + case ComputeHoverOperationState.IDLE: + this._triggerAsyncComputation(); + this._secondWaitScheduler.cancel(); + this._triggerSyncComputation(); + break; + case ComputeHoverOperationState.SECOND_WAIT: + this._secondWaitScheduler.cancel(); + this._triggerSyncComputation(); + break; + } } } diff --git a/src/vs/editor/contrib/hover/modesContentHover.ts b/src/vs/editor/contrib/hover/modesContentHover.ts index bb029b40dedcb0b4f465f33057ad157508719f9c..d8a23d854fd74afe498af06dd963a2bd81e18476 100644 --- a/src/vs/editor/contrib/hover/modesContentHover.ts +++ b/src/vs/editor/contrib/hover/modesContentHover.ts @@ -12,7 +12,7 @@ import { Position } from 'vs/editor/common/core/position'; import { HoverProviderRegistry, Hover, IColor, DocumentColorProvider } from 'vs/editor/common/modes'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { getHover } from 'vs/editor/contrib/hover/getHover'; -import { HoverOperation, IHoverComputer } from './hoverOperation'; +import { HoverOperation, IHoverComputer, HoverStartMode } from './hoverOperation'; import { ContentHoverWidget } from './hoverWidgets'; import { IMarkdownString, MarkdownString, isEmptyMarkdownString, markedStringsEquals } from 'vs/base/common/htmlContent'; import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer'; @@ -220,12 +220,12 @@ export class ModesContentHoverWidget extends ContentHoverWidget { this._computer.clearResult(); if (!this._colorPicker) { // TODO@Michel ensure that displayed text for other decorations is computed even if color picker is in place - this._hoverOperation.start(); + this._hoverOperation.start(HoverStartMode.Delayed); } } } - startShowingAt(range: Range, focus: boolean): void { + startShowingAt(range: Range, mode: HoverStartMode, focus: boolean): void { if (this._lastRange && this._lastRange.equalsRange(range)) { // We have to show the widget at the exact same range as before, so no work is needed return; @@ -262,7 +262,7 @@ export class ModesContentHoverWidget extends ContentHoverWidget { this._lastRange = range; this._computer.setRange(range); this._shouldFocus = focus; - this._hoverOperation.start(); + this._hoverOperation.start(mode); } hide(): void { diff --git a/src/vs/editor/contrib/hover/modesGlyphHover.ts b/src/vs/editor/contrib/hover/modesGlyphHover.ts index c1844e2e33ef5762d8103ca6d7fefff7d327bf54..535aab4a2508c5fe1fd00e3db4e77eadfee21d6f 100644 --- a/src/vs/editor/contrib/hover/modesGlyphHover.ts +++ b/src/vs/editor/contrib/hover/modesGlyphHover.ts @@ -5,7 +5,7 @@ 'use strict'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { HoverOperation, IHoverComputer } from './hoverOperation'; +import { HoverOperation, IHoverComputer, HoverStartMode } from './hoverOperation'; import { GlyphHoverWidget } from './hoverWidgets'; import { $ } from 'vs/base/browser/dom'; import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer'; @@ -123,7 +123,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget { // we need to recompute the displayed text this._hoverOperation.cancel(); this._computer.clearResult(); - this._hoverOperation.start(); + this._hoverOperation.start(HoverStartMode.Delayed); } } @@ -139,7 +139,7 @@ export class ModesGlyphHoverWidget extends GlyphHoverWidget { this._lastLineNumber = lineNumber; this._computer.setLineNumber(lineNumber); - this._hoverOperation.start(); + this._hoverOperation.start(HoverStartMode.Delayed); } public hide(): void {