5
5
6
6
import * as dom from 'vs/base/browser/dom' ;
7
7
import { toErrorMessage } from 'vs/base/common/errorMessage' ;
8
+ import { DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
8
9
import { revive } from 'vs/base/common/marshalling' ;
9
10
import { URI } from 'vs/base/common/uri' ;
10
11
import { Location } from 'vs/editor/common/languages' ;
12
+ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
11
13
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
12
14
import { ILabelService } from 'vs/platform/label/common/label' ;
13
15
import { ILogService } from 'vs/platform/log/common/log' ;
16
+ import { ChatAgentHover } from 'vs/workbench/contrib/chat/browser/chatAgentHover' ;
14
17
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents' ;
15
18
import { ChatRequestAgentPart , ChatRequestDynamicVariablePart , ChatRequestTextPart , IParsedChatRequest } from 'vs/workbench/contrib/chat/common/chatParserTypes' ;
16
19
import { contentRefUrl } from '../common/annotations' ;
17
20
import { IHoverService } from 'vs/platform/hover/browser/hover' ;
18
21
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegateFactory' ;
19
- import { h } from 'vs/base/browser/dom' ;
20
- import { FileAccess } from 'vs/base/common/network' ;
21
- import { ThemeIcon } from 'vs/base/common/themables' ;
22
- import { localize } from 'vs/nls' ;
23
- import { showExtensionsWithIdsCommandId } from 'vs/workbench/contrib/extensions/browser/extensionsActions' ;
24
22
25
23
const variableRefUrl = 'http://_vscodedecoration_' ;
26
24
const agentRefUrl = 'http://_chatagent_' ;
@@ -31,6 +29,7 @@ export class ChatMarkdownDecorationsRenderer {
31
29
@ILabelService private readonly labelService : ILabelService ,
32
30
@ILogService private readonly logService : ILogService ,
33
31
@IChatAgentService private readonly chatAgentService : IChatAgentService ,
32
+ @IInstantiationService private readonly instantiationService : IInstantiationService ,
34
33
@IHoverService private readonly hoverService : IHoverService ,
35
34
) { }
36
35
@@ -62,14 +61,15 @@ export class ChatMarkdownDecorationsRenderer {
62
61
return result ;
63
62
}
64
63
65
- walkTreeAndAnnotateReferenceLinks ( element : HTMLElement ) : void {
64
+ walkTreeAndAnnotateReferenceLinks ( element : HTMLElement ) : IDisposable {
65
+ const store = new DisposableStore ( ) ;
66
66
element . querySelectorAll ( 'a' ) . forEach ( a => {
67
67
const href = a . getAttribute ( 'data-href' ) ;
68
68
if ( href ) {
69
69
if ( href . startsWith ( agentRefUrl ) ) {
70
70
const title = decodeURIComponent ( href . slice ( agentRefUrl . length + 1 ) ) ;
71
71
a . parentElement ! . replaceChild (
72
- this . renderAgentWidget ( a . textContent ! , title ) ,
72
+ this . renderAgentWidget ( a . textContent ! , title , store ) ,
73
73
a ) ;
74
74
} else if ( href . startsWith ( variableRefUrl ) ) {
75
75
const title = decodeURIComponent ( href . slice ( variableRefUrl . length + 1 ) ) ;
@@ -83,57 +83,17 @@ export class ChatMarkdownDecorationsRenderer {
83
83
}
84
84
}
85
85
} ) ;
86
- }
87
-
88
- private renderAgentWidget ( name : string , id : string ) : HTMLElement {
89
- const agent = this . chatAgentService . getAgent ( id ) ! ;
90
-
91
- const container = dom . $ ( 'span.chat-resource-widget' ) ;
92
- const alias = dom . $ ( 'span' , undefined , name ) ;
93
86
94
- const hoverElement = h (
95
- '.chat-agent-hover@root' ,
96
- [
97
- h ( '.chat-agent-hover-header' , [
98
- h ( '.chat-agent-hover-icon@icon' ) ,
99
- h ( '.chat-agent-hover-details' , [
100
- h ( '.chat-agent-hover-name@name' ) ,
101
- h ( '.chat-agent-hover-extension' , [
102
- h ( '.chat-agent-hover-extension-name@extensionName' ) ,
103
- h ( '.chat-agent-hover-separator@separator' ) ,
104
- h ( '.chat-agent-hover-publisher@publisher' ) ,
105
- ] ) ,
106
- ] ) ,
107
- ] ) ,
108
- h ( '.chat-agent-hover-description@description' ) ,
109
- ] ) ;
110
-
111
- if ( agent . metadata . icon instanceof URI ) {
112
- const avatarIcon = dom . $ < HTMLImageElement > ( 'img.icon' ) ;
113
- avatarIcon . src = FileAccess . uriToBrowserUri ( agent . metadata . icon ) . toString ( true ) ;
114
- hoverElement . icon . replaceChildren ( dom . $ ( '.avatar' , undefined , avatarIcon ) ) ;
115
- } else if ( agent . metadata . themeIcon ) {
116
- const avatarIcon = dom . $ ( ThemeIcon . asCSSSelector ( agent . metadata . themeIcon ) ) ;
117
- hoverElement . icon . replaceChildren ( dom . $ ( '.avatar.codicon-avatar' , undefined , avatarIcon ) ) ;
118
- }
119
-
120
- hoverElement . name . textContent = `@${ agent . name } ` ;
121
- hoverElement . extensionName . textContent = agent . extensionDisplayName ;
122
- hoverElement . separator . textContent = ' | ' ;
123
- hoverElement . publisher . textContent = agent . extensionPublisher ;
124
-
125
- const description = agent . description && ! agent . description . endsWith ( '.' ) ?
126
- `${ agent . description } . ` :
127
- ( agent . description || '' ) ;
128
- hoverElement . description . textContent = description ;
87
+ return store ;
88
+ }
129
89
130
- const marketplaceLink = document . createElement ( 'a' ) ;
131
- marketplaceLink . setAttribute ( 'href' , `command:${ showExtensionsWithIdsCommandId } ?${ encodeURIComponent ( JSON . stringify ( [ agent . extensionId . value ] ) ) } ` ) ;
132
- marketplaceLink . textContent = localize ( 'marketplaceLabel' , "View in Marketplace" ) + '.' ;
133
- hoverElement . description . appendChild ( marketplaceLink ) ;
90
+ private renderAgentWidget ( name : string , id : string , store : DisposableStore ) : HTMLElement {
91
+ const container = dom . $ ( 'span.chat-resource-widget' , undefined , dom . $ ( 'span' , undefined , name ) ) ;
134
92
135
- this . hoverService . setupUpdatableHover ( getDefaultHoverDelegate ( 'element' ) , container , hoverElement . root ) ;
136
- container . appendChild ( alias ) ;
93
+ store . add ( this . hoverService . setupUpdatableHover ( getDefaultHoverDelegate ( 'element' ) , container , ( ) => {
94
+ const hover = this . instantiationService . createInstance ( ChatAgentHover , id ) ;
95
+ return hover . domNode ;
96
+ } ) ) ;
137
97
return container ;
138
98
}
139
99
0 commit comments