55
66import { EventType } from 'vs/base/browser/dom' ;
77import { IMarkdownString , MarkdownString } from 'vs/base/common/htmlContent' ;
8- import { DisposableStore , dispose , IDisposable } from 'vs/base/common/lifecycle' ;
8+ import { DisposableStore , dispose , IDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
99import { Schemas } from 'vs/base/common/network' ;
1010import { posix , win32 } from 'vs/base/common/path' ;
1111import { isMacintosh , OperatingSystem , OS } from 'vs/base/common/platform' ;
@@ -32,6 +32,8 @@ import { ITerminalCapabilityStore, TerminalCapability } from 'vs/platform/termin
3232import { ITerminalConfiguration , ITerminalProcessManager , TERMINAL_CONFIG_SECTION } from 'vs/workbench/contrib/terminal/common/terminal' ;
3333import { IHoverAction } from 'vs/workbench/services/hover/browser/hover' ;
3434import type { ILink , ILinkProvider , IViewportRange , Terminal } from 'xterm' ;
35+ import { convertBufferRangeToViewport } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkHelpers' ;
36+ import { RunOnceScheduler } from 'vs/base/common/async' ;
3537
3638export type XtermLinkMatcherHandler = ( event : MouseEvent | undefined , link : string ) => Promise < void > ;
3739export type XtermLinkMatcherValidationCallback = ( uri : string , callback : ( isValid : boolean ) => void ) => void ;
@@ -92,6 +94,48 @@ export class TerminalLinkManager extends DisposableStore {
9294 this . _openers . set ( TerminalBuiltinLinkType . Url , this . _instantiationService . createInstance ( TerminalUrlLinkOpener , ! ! this . _processManager . remoteAuthority ) ) ;
9395
9496 this . _registerStandardLinkProviders ( ) ;
97+
98+ let activeHoverDisposable : IDisposable | undefined ;
99+ let activeTooltipScheduler : RunOnceScheduler | undefined ;
100+ this . add ( toDisposable ( ( ) => {
101+ activeHoverDisposable ?. dispose ( ) ;
102+ activeTooltipScheduler ?. dispose ( ) ;
103+ } ) ) ;
104+ this . _xterm . options . linkHandler = {
105+ activate : ( _ , text ) => {
106+ this . _openers . get ( TerminalBuiltinLinkType . Url ) ?. open ( {
107+ type : TerminalBuiltinLinkType . Url ,
108+ text,
109+ bufferRange : null ! ,
110+ uri : URI . parse ( text )
111+ } ) ;
112+ } ,
113+ hover : ( e , text , range ) => {
114+ activeHoverDisposable ?. dispose ( ) ;
115+ activeHoverDisposable = undefined ;
116+ activeTooltipScheduler ?. dispose ( ) ;
117+ activeTooltipScheduler = new RunOnceScheduler ( ( ) => {
118+ const core = ( this . _xterm as any ) . _core as IXtermCore ;
119+ const cellDimensions = {
120+ width : core . _renderService . dimensions . actualCellWidth ,
121+ height : core . _renderService . dimensions . actualCellHeight
122+ } ;
123+ const terminalDimensions = {
124+ width : this . _xterm . cols ,
125+ height : this . _xterm . rows
126+ } ;
127+ activeHoverDisposable = this . _showHover ( {
128+ viewportRange : convertBufferRangeToViewport ( range , this . _xterm . buffer . active . viewportY ) ,
129+ cellDimensions,
130+ terminalDimensions
131+ } , this . _getLinkHoverString ( text , text ) , undefined , ( text ) => this . _xterm . options . linkHandler ?. activate ( e , text , range ) ) ;
132+ // Clear out scheduler until next hover event
133+ activeTooltipScheduler ?. dispose ( ) ;
134+ activeTooltipScheduler = undefined ;
135+ } , this . _configurationService . getValue ( 'workbench.hover.delay' ) ) ;
136+ activeTooltipScheduler . schedule ( ) ;
137+ }
138+ } ;
95139 }
96140
97141 private _setupLinkDetector ( id : string , detector : ITerminalLinkDetector , isExternal : boolean = false ) : ILinkProvider {
@@ -236,14 +280,16 @@ export class TerminalLinkManager extends DisposableStore {
236280 actions : IHoverAction [ ] | undefined ,
237281 linkHandler : ( url : string ) => void ,
238282 link ?: TerminalLink
239- ) {
283+ ) : IDisposable | undefined {
240284 if ( this . _widgetManager ) {
241285 const widget = this . _instantiationService . createInstance ( TerminalHover , targetOptions , text , actions , linkHandler ) ;
242286 const attached = this . _widgetManager . attachWidget ( widget ) ;
243287 if ( attached ) {
244288 link ?. onInvalidated ( ( ) => attached . dispose ( ) ) ;
245289 }
290+ return attached ;
246291 }
292+ return undefined ;
247293 }
248294
249295 setWidgetManager ( widgetManager : TerminalWidgetManager ) : void {
0 commit comments