@@ -16,8 +16,9 @@ import { getIcon, codicon } from '../icons'
1616import globals from '../extensionGlobals'
1717import { openUrl } from './vsCodeUtils'
1818import { AmazonQPromptSettings , ToolkitPromptSettings } from '../../shared/settings'
19- import { telemetry } from '../telemetry/telemetry'
19+ import { telemetry , ToolkitShowNotification } from '../telemetry/telemetry'
2020import { vscodeComponent } from '../vscode/commands2'
21+ import { getTelemetryReasonDesc } from '../errors'
2122
2223export const messages = {
2324 editCredentials ( icon : boolean ) {
@@ -35,21 +36,32 @@ export function makeFailedWriteMessage(filename: string): string {
3536 return message
3637}
3738
38- function showMessageWithItems (
39- message : string ,
39+ export function showMessage (
4040 kind : 'info' | 'warn' | 'error' = 'error' ,
41+ message : string ,
4142 items : string [ ] = [ ] ,
42- useModal : boolean = false
43- ) : Thenable < string | undefined > {
44- switch ( kind ) {
45- case 'info' :
46- return vscode . window . showInformationMessage ( message , { modal : useModal } , ...items )
47- case 'warn' :
48- return vscode . window . showWarningMessage ( message , { modal : useModal } , ...items )
49- case 'error' :
50- default :
51- return vscode . window . showErrorMessage ( message , { modal : useModal } , ...items )
43+ options : vscode . MessageOptions & { telemetry ?: boolean } = { } ,
44+ metric : Partial < ToolkitShowNotification > = {
45+ id : 'unknown' ,
46+ component : 'editor' ,
5247 }
48+ ) : Thenable < string | undefined > {
49+ return telemetry . toolkit_showNotification . run ( async ( span ) => {
50+ span . record ( {
51+ passive : true ,
52+ ...metric ,
53+ } )
54+
55+ switch ( kind ) {
56+ case 'info' :
57+ return vscode . window . showInformationMessage ( message , options , ...items )
58+ case 'warn' :
59+ return vscode . window . showWarningMessage ( message , options , ...items )
60+ case 'error' :
61+ default :
62+ return vscode . window . showErrorMessage ( message , options , ...items )
63+ }
64+ } )
5365}
5466
5567/**
@@ -75,7 +87,16 @@ export async function showMessageWithUrl(
7587 const uri = typeof url === 'string' ? vscode . Uri . parse ( url ) : url
7688 const items = [ ...extraItems , urlItem ]
7789
78- const p = showMessageWithItems ( message , kind , items , useModal )
90+ const p = showMessage (
91+ kind ,
92+ message ,
93+ items ,
94+ { modal : useModal } ,
95+ {
96+ id : 'showMessageWithUrl' ,
97+ reasonDesc : getTelemetryReasonDesc ( message ) ,
98+ }
99+ )
79100 return p . then < string | undefined > ( ( selection ) => {
80101 if ( selection === urlItem ) {
81102 void openUrl ( uri )
@@ -102,7 +123,16 @@ export async function showViewLogsMessage(
102123 const logsItem = localize ( 'AWS.generic.message.viewLogs' , 'View Logs...' )
103124 const items = [ ...extraItems , logsItem ]
104125
105- const p = showMessageWithItems ( message , kind , items )
126+ const p = showMessage (
127+ kind ,
128+ message ,
129+ items ,
130+ { } ,
131+ {
132+ id : 'showViewLogsMessage' ,
133+ reasonDesc : getTelemetryReasonDesc ( message ) ,
134+ }
135+ )
106136 return p . then < string | undefined > ( ( selection ) => {
107137 if ( selection === logsItem ) {
108138 globals . logOutputChannel . show ( true )
0 commit comments