@@ -40,6 +40,9 @@ import {
4040 tabBarActionRequestType ,
4141 contextCommandsNotificationType ,
4242 ContextCommandParams ,
43+ ShowDocumentParams ,
44+ ShowDocumentResult ,
45+ ShowDocumentRequest ,
4346 openFileDiffNotificationType ,
4447 OpenFileDiffParams ,
4548 LINK_CLICK_NOTIFICATION_METHOD ,
@@ -70,6 +73,7 @@ import { telemetry, TelemetryBase } from 'aws-core-vscode/telemetry'
7073import { isValidResponseError } from './error'
7174import { decryptResponse , encryptRequest } from '../encryption'
7275import { getCursorState } from '../utils'
76+ import { focusAmazonQPanel } from './commands'
7377
7478export function registerLanguageServerEventListener ( languageClient : LanguageClient , provider : AmazonQChatViewProvider ) {
7579 languageClient . info (
@@ -316,7 +320,7 @@ export function registerMessageListeners(
316320 )
317321 if ( ! buttonResult . success ) {
318322 languageClient . error (
319- `[VSCode Client] Failed to execute action associated with button with reason : ${ buttonResult . failureReason } `
323+ `[VSCode Client] Failed to execute button action : ${ buttonResult . failureReason } `
320324 )
321325 }
322326 break
@@ -412,6 +416,40 @@ export function registerMessageListeners(
412416 }
413417 } )
414418
419+ languageClient . onRequest < ShowDocumentParams , ShowDocumentResult > (
420+ ShowDocumentRequest . method ,
421+ async ( params : ShowDocumentParams ) : Promise < ShowDocumentParams | ResponseError < ShowDocumentResult > > => {
422+ focusAmazonQPanel ( ) . catch ( ( e ) => languageClient . error ( `[VSCode Client] focusAmazonQPanel() failed` ) )
423+
424+ try {
425+ const uri = vscode . Uri . parse ( params . uri )
426+
427+ if ( params . external ) {
428+ // Note: Not using openUrl() because we probably don't want telemetry for these URLs.
429+ // Also it doesn't yet support the required HACK below.
430+
431+ // HACK: workaround vscode bug: https://github.com/microsoft/vscode/issues/85930
432+ vscode . env . openExternal ( params . uri as any ) . then ( undefined , ( e ) => {
433+ // TODO: getLogger('?').error('failed vscode.env.openExternal: %O', e)
434+ vscode . env . openExternal ( uri ) . then ( undefined , ( e ) => {
435+ // TODO: getLogger('?').error('failed vscode.env.openExternal: %O', e)
436+ } )
437+ } )
438+ return params
439+ }
440+
441+ const doc = await vscode . workspace . openTextDocument ( uri )
442+ await vscode . window . showTextDocument ( doc , { preview : false } )
443+ return params
444+ } catch ( e ) {
445+ return new ResponseError (
446+ LSPErrorCodes . RequestFailed ,
447+ `Failed to open document: ${ ( e as Error ) . message } `
448+ )
449+ }
450+ }
451+ )
452+
415453 languageClient . onNotification ( contextCommandsNotificationType . method , ( params : ContextCommandParams ) => {
416454 void provider . webview ?. postMessage ( {
417455 command : contextCommandsNotificationType . method ,
0 commit comments