From 2f817caf6e7b59a299089a2e953ff02688cdc8b7 Mon Sep 17 00:00:00 2001 From: Alexandru Dima Date: Thu, 31 Dec 2020 11:01:09 +0100 Subject: [PATCH] Move more marker specific logic to markerHoverParticipant --- src/vs/editor/contrib/hover/hover.ts | 8 ++--- .../contrib/hover/markerHoverParticipant.ts | 23 +++++++++----- .../editor/contrib/hover/modesContentHover.ts | 31 ++++++++++--------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/vs/editor/contrib/hover/hover.ts b/src/vs/editor/contrib/hover/hover.ts index 83c26d73729..cac3678e642 100644 --- a/src/vs/editor/contrib/hover/hover.ts +++ b/src/vs/editor/contrib/hover/hover.ts @@ -22,11 +22,10 @@ import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegis import { IOpenerService } from 'vs/platform/opener/common/opener'; import { editorHoverBackground, editorHoverBorder, editorHoverHighlight, textCodeBlockBackground, textLinkForeground, editorHoverStatusBarBackground, editorHoverForeground } from 'vs/platform/theme/common/colorRegistry'; import { IThemeService, registerThemingParticipant } from 'vs/platform/theme/common/themeService'; -import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService'; -import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility'; import { GotoDefinitionAtPositionEditorContribution } from 'vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition'; import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; export class ModesHoverController implements IEditorContribution { @@ -64,10 +63,9 @@ export class ModesHoverController implements IEditorContribution { } constructor(private readonly _editor: ICodeEditor, + @IInstantiationService private readonly _instantiationService: IInstantiationService, @IOpenerService private readonly _openerService: IOpenerService, @IModeService private readonly _modeService: IModeService, - @IMarkerDecorationsService private readonly _markerDecorationsService: IMarkerDecorationsService, - @IKeybindingService private readonly _keybindingService: IKeybindingService, @IThemeService private readonly _themeService: IThemeService, @IContextKeyService _contextKeyService: IContextKeyService ) { @@ -233,7 +231,7 @@ export class ModesHoverController implements IEditorContribution { } private _createHoverWidgets() { - this._contentWidget.value = new ModesContentHoverWidget(this._editor, this._hoverVisibleKey, this._markerDecorationsService, this._keybindingService, this._themeService, this._modeService, this._openerService); + this._contentWidget.value = new ModesContentHoverWidget(this._editor, this._hoverVisibleKey, this._instantiationService, this._themeService, this._modeService, this._openerService); this._glyphWidget.value = new ModesGlyphHoverWidget(this._editor, this._modeService, this._openerService); } diff --git a/src/vs/editor/contrib/hover/markerHoverParticipant.ts b/src/vs/editor/contrib/hover/markerHoverParticipant.ts index dcc79ab4aad..24e57eba963 100644 --- a/src/vs/editor/contrib/hover/markerHoverParticipant.ts +++ b/src/vs/editor/contrib/hover/markerHoverParticipant.ts @@ -7,14 +7,14 @@ import * as nls from 'vs/nls'; import * as dom from 'vs/base/browser/dom'; import { IDisposable, toDisposable, DisposableStore, Disposable } from 'vs/base/common/lifecycle'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { IRange, Range } from 'vs/editor/common/core/range'; +import { Range } from 'vs/editor/common/core/range'; import { CodeActionTriggerType } from 'vs/editor/common/modes'; import { isNonEmptyArray } from 'vs/base/common/arrays'; import { IMarker, IMarkerData, MarkerSeverity } from 'vs/platform/markers/common/markers'; import { basename } from 'vs/base/common/resources'; import { IMarkerDecorationsService } from 'vs/editor/common/services/markersDecorationService'; import { onUnexpectedError } from 'vs/base/common/errors'; -import { IOpenerService, NullOpenerService } from 'vs/platform/opener/common/opener'; +import { IOpenerService } from 'vs/platform/opener/common/opener'; import { MarkerController, NextMarkerAction } from 'vs/editor/contrib/gotoError/gotoError'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { CancelablePromise, createCancelablePromise, disposableTimeout } from 'vs/base/common/async'; @@ -26,15 +26,22 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions'; import { Progress } from 'vs/platform/progress/common/progress'; import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; import { renderHoverAction } from 'vs/base/browser/ui/hover/hoverWidget'; -import { IEditorHover, IEditorHoverParticipant } from 'vs/editor/contrib/hover/modesContentHover'; +import { HoverPart, IEditorHover, IEditorHoverParticipant, IHoverPart } from 'vs/editor/contrib/hover/modesContentHover'; const $ = dom.$; -export class MarkerHover { +export class MarkerHover implements IHoverPart { constructor( - public readonly range: IRange, + public readonly range: Range, public readonly marker: IMarker, ) { } + + public equals(other: IHoverPart | HoverPart): boolean { + if (other instanceof MarkerHover) { + return IMarkerData.makeKey(this.marker) === IMarkerData.makeKey(other.marker); + } + return false; + } } const markerCodeActionTrigger: CodeActionTrigger = { @@ -49,9 +56,9 @@ export class MarkerHoverParticipant implements IEditorHoverParticipant { @@ -227,15 +230,14 @@ export class ModesContentHoverWidget extends Widget implements IContentWidget { constructor( editor: ICodeEditor, private readonly _hoverVisibleKey: IContextKey, - markerDecorationsService: IMarkerDecorationsService, - private readonly _keybindingService: IKeybindingService, + instantiationService: IInstantiationService, private readonly _themeService: IThemeService, private readonly _modeService: IModeService, private readonly _openerService: IOpenerService = NullOpenerService, ) { super(); - this._markerHoverParticipant = new MarkerHoverParticipant(editor, this, markerDecorationsService, this._keybindingService, this._openerService); + this._markerHoverParticipant = instantiationService.createInstance(MarkerHoverParticipant, editor, this); this._hover = this._register(new HoverWidget()); this._id = ModesContentHoverWidget.ID; @@ -644,16 +646,15 @@ function hoverContentsEquals(first: HoverPart[], second: HoverPart[]): boolean { for (let i = 0; i < first.length; i++) { const firstElement = first[i]; const secondElement = second[i]; - if (firstElement instanceof MarkerHover && secondElement instanceof MarkerHover) { - return IMarkerData.makeKey(firstElement.marker) === IMarkerData.makeKey(secondElement.marker); - } - if (firstElement instanceof ColorHover || secondElement instanceof ColorHover) { + if (firstElement instanceof MarkerHover) { + if (!firstElement.equals(secondElement)) { + return false; + } + } else if (firstElement instanceof ColorHover || secondElement instanceof ColorHover) { return false; - } - if (firstElement instanceof MarkerHover || secondElement instanceof MarkerHover) { + } else if (firstElement instanceof MarkerHover || secondElement instanceof MarkerHover) { return false; - } - if (!markedStringsEquals(firstElement.contents, secondElement.contents)) { + } else if (!markedStringsEquals(firstElement.contents, secondElement.contents)) { return false; } }