提交 e16aead2 编写于 作者: D Daniel Imms

Move hover service into core workbench

Fixes #100637
上级 9c142ea3
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IHoverService, IHoverOptions } from 'vs/workbench/contrib/hover/browser/hover';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { HoverWidget } from 'vs/workbench/contrib/hover/browser/hoverWidget';
import { IContextViewProvider, IDelegate } from 'vs/base/browser/ui/contextview/contextview';
export class HoverService implements IHoverService {
declare readonly _serviceBrand: undefined;
private _currentHoverOptions: IHoverOptions | undefined;
constructor(
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IContextViewService private readonly _contextViewService: IContextViewService
) {
}
showHover(options: IHoverOptions, focus?: boolean): void {
if (this._currentHoverOptions === options) {
return;
}
this._currentHoverOptions = options;
const hover = this._instantiationService.createInstance(HoverWidget, options);
hover.onDispose(() => this._currentHoverOptions = undefined);
const provider = this._contextViewService as IContextViewProvider;
provider.showContextView(new HoverContextViewDelegate(hover, focus));
hover.onRequestLayout(() => provider.layout());
}
hideHover(): void {
if (!this._currentHoverOptions) {
return;
}
this._currentHoverOptions = undefined;
this._contextViewService.hideContextView();
}
}
class HoverContextViewDelegate implements IDelegate {
get anchorPosition() {
return this._hover.anchor;
}
constructor(
private readonly _hover: HoverWidget,
private readonly _focus: boolean = false
) {
}
render(container: HTMLElement) {
this._hover.render(container);
if (this._focus) {
this._hover.focus();
}
return this._hover;
}
getAnchor() {
return {
x: this._hover.x,
y: this._hover.y
};
}
layout() {
this._hover.layout();
}
}
......@@ -11,7 +11,7 @@ import { RunOnceScheduler } from 'vs/base/common/async';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import * as dom from 'vs/base/browser/dom';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IHoverService, IHoverOptions } from 'vs/workbench/contrib/hover/browser/hover';
import { IHoverService, IHoverOptions } from 'vs/workbench/services/hover/browser/hover';
export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWidget {
readonly id = 'env-var-info';
......
......@@ -9,7 +9,7 @@ import { Widget } from 'vs/base/browser/ui/widget';
import { ITerminalWidget } from 'vs/workbench/contrib/terminal/browser/widgets/widgets';
import * as dom from 'vs/base/browser/dom';
import { IViewportRange } from 'xterm';
import { IHoverTarget, IHoverService } from 'vs/workbench/contrib/hover/browser/hover';
import { IHoverTarget, IHoverService } from 'vs/workbench/services/hover/browser/hover';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorHoverHighlight } from 'vs/platform/theme/common/colorRegistry';
......
......@@ -5,10 +5,78 @@
import 'vs/css!./media/hover';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { HoverService } from 'vs/workbench/contrib/hover/browser/hoverService';
import { IHoverService } from 'vs/workbench/contrib/hover/browser/hover';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorHoverBackground, editorHoverBorder, textLinkForeground, editorHoverForeground, editorHoverStatusBarBackground, textCodeBlockBackground } from 'vs/platform/theme/common/colorRegistry';
import { IHoverService, IHoverOptions } from 'vs/workbench/services/hover/browser/hover';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { HoverWidget } from 'vs/workbench/services/hover/browser/hoverWidget';
import { IContextViewProvider, IDelegate } from 'vs/base/browser/ui/contextview/contextview';
export class HoverService implements IHoverService {
declare readonly _serviceBrand: undefined;
private _currentHoverOptions: IHoverOptions | undefined;
constructor(
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IContextViewService private readonly _contextViewService: IContextViewService
) {
}
showHover(options: IHoverOptions, focus?: boolean): void {
if (this._currentHoverOptions === options) {
return;
}
this._currentHoverOptions = options;
const hover = this._instantiationService.createInstance(HoverWidget, options);
hover.onDispose(() => this._currentHoverOptions = undefined);
const provider = this._contextViewService as IContextViewProvider;
provider.showContextView(new HoverContextViewDelegate(hover, focus));
hover.onRequestLayout(() => provider.layout());
}
hideHover(): void {
if (!this._currentHoverOptions) {
return;
}
this._currentHoverOptions = undefined;
this._contextViewService.hideContextView();
}
}
class HoverContextViewDelegate implements IDelegate {
get anchorPosition() {
return this._hover.anchor;
}
constructor(
private readonly _hover: HoverWidget,
private readonly _focus: boolean = false
) {
}
render(container: HTMLElement) {
this._hover.render(container);
if (this._focus) {
this._hover.focus();
}
return this._hover;
}
getAnchor() {
return {
x: this._hover.x,
y: this._hover.y
};
}
layout() {
this._hover.layout();
}
}
registerSingleton(IHoverService, HoverService, true);
......
......@@ -8,7 +8,7 @@ import { renderMarkdown } from 'vs/base/browser/markdownRenderer';
import { Event, Emitter } from 'vs/base/common/event';
import * as dom from 'vs/base/browser/dom';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IHoverTarget, IHoverOptions } from 'vs/workbench/contrib/hover/browser/hover';
import { IHoverTarget, IHoverOptions } from 'vs/workbench/services/hover/browser/hover';
import { KeyCode } from 'vs/base/common/keyCodes';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { EDITOR_FONT_DEFAULTS, IEditorOptions } from 'vs/editor/common/config/editorOptions';
......
......@@ -85,6 +85,7 @@ import 'vs/workbench/services/views/browser/viewDescriptorService';
import 'vs/workbench/services/quickinput/browser/quickInputService';
import 'vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService';
import 'vs/workbench/services/authentication/browser/authenticationService';
import 'vs/workbench/services/hover/browser/hoverService';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionGalleryService';
......@@ -284,7 +285,4 @@ import 'vs/workbench/contrib/welcome/common/viewsWelcome.contribution';
// Timeline
import 'vs/workbench/contrib/timeline/browser/timeline.contribution';
// Hover
import 'vs/workbench/contrib/hover/browser/hover.contribution';
//#endregion
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册