diff --git a/packages/amazonq/src/lsp/chat/messages.ts b/packages/amazonq/src/lsp/chat/messages.ts index 80ef45426cd..f0dcbd9e608 100644 --- a/packages/amazonq/src/lsp/chat/messages.ts +++ b/packages/amazonq/src/lsp/chat/messages.ts @@ -435,6 +435,21 @@ export function registerMessageListeners( async (params: ShowDocumentParams): Promise> => { try { const uri = vscode.Uri.parse(params.uri) + + if (params.external) { + // Note: Not using openUrl() because we probably don't want telemetry for these URLs. + // Also it doesn't yet support the required HACK below. + + // HACK: workaround vscode bug: https://github.com/microsoft/vscode/issues/85930 + vscode.env.openExternal(params.uri as any).then(undefined, (e) => { + // TODO: getLogger('?').error('failed vscode.env.openExternal: %O', e) + vscode.env.openExternal(uri).then(undefined, (e) => { + // TODO: getLogger('?').error('failed vscode.env.openExternal: %O', e) + }) + }) + return params + } + const doc = await vscode.workspace.openTextDocument(uri) await vscode.window.showTextDocument(doc, { preview: false }) return params diff --git a/packages/core/src/shared/utilities/vsCodeUtils.ts b/packages/core/src/shared/utilities/vsCodeUtils.ts index 03229cf104a..57f9e380974 100644 --- a/packages/core/src/shared/utilities/vsCodeUtils.ts +++ b/packages/core/src/shared/utilities/vsCodeUtils.ts @@ -215,8 +215,11 @@ export function reloadWindowPrompt(message: string): void { * if user dismisses the vscode confirmation prompt. */ export async function openUrl(url: vscode.Uri, source?: string): Promise { + // Avoid PII in URL. + const truncatedUrl = `${url.scheme}${url.authority}${url.path}${url.fragment.substring(20)}` + return telemetry.aws_openUrl.run(async (span) => { - span.record({ url: url.toString(), source }) + span.record({ url: truncatedUrl, source }) const didOpen = await vscode.env.openExternal(url) if (!didOpen) { throw new CancellationError('user')