Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/amazonq/src/lsp/chat/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import { registerLanguageServerEventListener, registerMessageListeners } from '.
import { getLogger, globals } from 'aws-core-vscode/shared'
import { activate as registerLegacyChatListeners } from '../../app/chat/activation'
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
import { updateConfigurationRequestType } from '@aws/language-server-runtimes/protocol'

export async function activate(languageClient: LanguageClient, encryptionKey: Buffer, mynahUIPath: string) {
// Make sure we've sent an auth profile to the language server before even initializing the UI
await updateProfile(languageClient)

const provider = new AmazonQChatViewProvider(mynahUIPath)

globals.context.subscriptions.push(
Expand Down Expand Up @@ -44,4 +49,21 @@ export async function activate(languageClient: LanguageClient, encryptionKey: Bu

// register event listeners from the legacy agent flow
await registerLegacyChatListeners(globals.context)

globals.context.subscriptions.push(
AuthUtil.instance.regionProfileManager.onDidChangeRegionProfile(async () => {
void updateProfile(languageClient)
await provider.refreshWebview()
})
)
}

async function updateProfile(client: LanguageClient) {
// update the profile on the language server
await client.sendRequest(updateConfigurationRequestType.method, {
section: 'aws.q',
settings: {
profileArn: AuthUtil.instance.regionProfileManager.activeRegionProfile?.arn,
},
})
}
24 changes: 18 additions & 6 deletions packages/amazonq/src/lsp/chat/webviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {

webview: Webview | undefined

connectorAdapterPath?: string
uiPath?: string

constructor(private readonly mynahUIPath: string) {}

public async resolveWebviewView(
Expand All @@ -49,20 +52,22 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {

const source = 'vue/src/amazonq/webview/ui/amazonq-ui-connector-adapter.js' // Sent to dist/vue folder in webpack.
const serverHostname = process.env.WEBPACK_DEVELOPER_SERVER
const connectorAdapterPath =

this.connectorAdapterPath =
serverHostname !== undefined
? Uri.parse(serverHostname)
.with({ path: `/${source}` })
.toString()
: webviewView.webview.asWebviewUri(Uri.parse(path.join(dist.fsPath, source))).toString()
const uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString()
webviewView.webview.html = await this.getWebviewContent(uiPath, connectorAdapterPath)
this.uiPath = webviewView.webview.asWebviewUri(Uri.parse(this.mynahUIPath)).toString()

webviewView.webview.html = await this.getWebviewContent()

this.onDidResolveWebviewEmitter.fire()
performance.mark(amazonqMark.open)
}

private async getWebviewContent(mynahUIPath: string, hybridChatConnector: string) {
private async getWebviewContent() {
const featureConfigData = await featureConfig.getFeatureConfigs()

const isSM = isSageMaker('SMAI')
Expand Down Expand Up @@ -110,8 +115,8 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
</style>
</head>
<body>
<script type="text/javascript" src="${mynahUIPath.toString()}" defer onload="init()"></script>
<script type="text/javascript" src="${hybridChatConnector.toString()}"></script>
<script type="text/javascript" src="${this.uiPath?.toString()}" defer onload="init()"></script>
<script type="text/javascript" src="${this.connectorAdapterPath?.toString()}"></script>
<script type="text/javascript">
const init = () => {
const vscodeApi = acquireVsCodeApi()
Expand All @@ -137,4 +142,11 @@ export class AmazonQChatViewProvider implements WebviewViewProvider {
</body>
</html>`
}

async refreshWebview() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more general place we can put this? I imagine this is useful functionality for all webviews.

if (this.webview) {
// refresh the webview when the profile changes
this.webview.html = await this.getWebviewContent()
}
}
}
3 changes: 3 additions & 0 deletions packages/amazonq/src/lsp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export async function startLanguageServer(
clientId: crypto.randomUUID(),
},
awsClientCapabilities: {
q: {
developerProfiles: true,
},
window: {
notifications: true,
},
Expand Down