Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master into feature/amazonqLSP #6536

Open
wants to merge 3 commits into
base: feature/amazonqLSP
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "`Send to prompt` and other context menu options not sent if chat was closed"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "Amazon Q /dev: support `.hbs`, `.gjs`, `.gts`, `.astro`, `.mdx`, `.svelte`, `.erb`, `.rake` files"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Feature",
"description": "/transform: automatically download results when ready"
}
8 changes: 4 additions & 4 deletions packages/core/src/amazonq/apps/initContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
*/

import { EventEmitter } from 'vscode'
import { MessagePublisher } from '../messages/messagePublisher'
import { MessagePublisher, UiMessagePublisher } from '../messages/messagePublisher'
import { MessageListener } from '../messages/messageListener'
import { TabType } from '../webview/ui/storages/tabsStorage'

export interface AmazonQAppInitContext {
registerWebViewToAppMessagePublisher(eventEmitter: MessagePublisher<any>, tabType: TabType): void
getAppsToWebViewMessagePublisher(): MessagePublisher<any>
getAppsToWebViewMessagePublisher(): UiMessagePublisher<any>
onDidChangeAmazonQVisibility: EventEmitter<boolean>
}

export class DefaultAmazonQAppInitContext implements AmazonQAppInitContext {
private readonly appsToWebViewEventEmitter = new EventEmitter<any>()
private readonly appsToWebViewMessageListener = new MessageListener<any>(this.appsToWebViewEventEmitter)
private readonly appsToWebViewMessagePublisher = new MessagePublisher<any>(this.appsToWebViewEventEmitter)
private readonly appsToWebViewMessagePublisher = new UiMessagePublisher<any>(this.appsToWebViewEventEmitter)
private readonly webViewToAppsMessagePublishers: Map<TabType, MessagePublisher<any>> = new Map()
public readonly onDidChangeAmazonQVisibility = new EventEmitter<boolean>()

Expand All @@ -41,7 +41,7 @@ export class DefaultAmazonQAppInitContext implements AmazonQAppInitContext {
return this.appsToWebViewMessageListener
}

getAppsToWebViewMessagePublisher(): MessagePublisher<any> {
getAppsToWebViewMessagePublisher(): UiMessagePublisher<any> {
return this.appsToWebViewMessagePublisher
}
}
45 changes: 45 additions & 0 deletions packages/core/src/amazonq/messages/messagePublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,48 @@ export class MessagePublisher<T> {
this.eventEmitter.fire(event)
}
}

/**
* Same as {@link MessagePublisher}, but will wait until the UI indicates it
* is ready to recieve messages, before the message is published.
*
* This solves a problem when running a right click menu option like
* "Send To Prompt" BUT chat is not opened yet, it would result in the prompt failing to
* be recieved by chat.
*/
export class UiMessagePublisher<T> extends MessagePublisher<T> {
private isUiReady: boolean = false
private buffer: T[] = []

constructor(eventEmitter: EventEmitter<T>) {
super(eventEmitter)
}

public override publish(event: T): void {
// immediately send if Chat UI is ready
if (this.isUiReady) {
super.publish(event)
return
}

this.buffer.push(event)
}

/**
* Indicate the Q Chat UI is ready to recieve messages.
*/
public setUiReady() {
this.isUiReady = true
this.flush()
}

/**
* Publishes all blocked messages
*/
private flush() {
for (const msg of this.buffer) {
super.publish(msg)
}
this.buffer = []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { telemetry } from '../../../shared/telemetry'
import { AmazonQChatMessageDuration } from '../../messages/chatMessageDuration'
import { globals, openUrl } from '../../../shared'
import { isClickTelemetry, isOpenAgentTelemetry } from '../ui/telemetry/actions'
import { DefaultAmazonQAppInitContext } from '../../apps/initContext'

export function dispatchWebViewMessagesToApps(
webview: Webview,
Expand All @@ -21,12 +22,12 @@ export function dispatchWebViewMessagesToApps(
webview.onDidReceiveMessage((msg) => {
switch (msg.command) {
case 'ui-is-ready': {
DefaultAmazonQAppInitContext.instance.getAppsToWebViewMessagePublisher().setUiReady()
/**
* ui-is-ready isn't associated to any tab so just record the telemetry event and continue.
* This would be equivalent of the duration between "user clicked open q" and "ui has become available"
* NOTE: Amazon Q UI is only loaded ONCE. The state is saved between each hide/show of the webview.
*/

telemetry.webview_load.emit({
webviewName: 'amazonq',
duration: performance.measure(amazonqMark.uiReady, amazonqMark.open).duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,12 @@ export async function postTransformationJob() {
if (transformByQState.getPayloadFilePath() !== '') {
fs.rmSync(transformByQState.getPayloadFilePath(), { recursive: true, force: true }) // delete ZIP if it exists
}

// attempt download for user
// TODO: refactor as explained here https://github.com/aws/aws-toolkit-vscode/pull/6519/files#r1946873107
if (transformByQState.isSucceeded() || transformByQState.isPartiallySucceeded()) {
await vscode.commands.executeCommand('aws.amazonq.transformationHub.reviewChanges.startReview')
}
}

export async function transformationJobErrorHandler(error: any) {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/shared/filetypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const codefileExtensions = new Set([
'.ads',
'.apl',
'.asm',
'.astro',
'.awk',
'.b',
'.bas',
Expand Down Expand Up @@ -195,6 +196,7 @@ export const codefileExtensions = new Set([
'.el',
'.elm',
'.env',
'.erb',
'.erl',
'.ex',
'.exs',
Expand All @@ -211,6 +213,7 @@ export const codefileExtensions = new Set([
'.fsx',
'.gd',
'.gitignore',
'.gjs',
'.go',
'.gql',
'.gradle',
Expand All @@ -220,9 +223,11 @@ export const codefileExtensions = new Set([
'.gsp',
'.gst',
'.gsx',
'.gts',
'.gvy',
'.h',
'.hack',
'.hbs',
'.hh',
'.hpp',
'.hrl',
Expand Down Expand Up @@ -253,6 +258,7 @@ export const codefileExtensions = new Set([
'.mak',
'.makefile',
'.md',
'.mdx',
'.mjs',
'.ml',
'.mli',
Expand Down Expand Up @@ -289,6 +295,7 @@ export const codefileExtensions = new Set([
'.pyw',
'.qs',
'.r',
'.rake',
'.raku',
'.rakumod',
'.rakutest',
Expand Down Expand Up @@ -331,6 +338,7 @@ export const codefileExtensions = new Set([
'.ss',
'.st',
'.sv',
'.svelte',
'.svg',
'.swift',
'.t',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from 'vscode'

export type LogTopic = 'crashMonitoring' | 'dev/beta' | 'notifications' | 'test' | 'childProcess' | 'unknown'
export type LogTopic = 'crashMonitoring' | 'dev/beta' | 'notifications' | 'test' | 'childProcess' | 'unknown' | 'chat'

class ErrorLog {
constructor(
Expand Down