Skip to content

Commit 1170aa9

Browse files
committed
Merge public/master into feature/standalone
2 parents 166f61d + 3d4c65e commit 1170aa9

File tree

9 files changed

+117
-280
lines changed

9 files changed

+117
-280
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q: Fixed quick action command list inconsistency between Q tabs"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q: Fixed cursor not focuses to prompt input when code is sent to Q Chat"
4+
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4003,7 +4003,7 @@
40034003
"@aws-sdk/property-provider": "3.46.0",
40044004
"@aws-sdk/smithy-client": "^3.46.0",
40054005
"@aws-sdk/util-arn-parser": "^3.46.0",
4006-
"@aws/mynah-ui": "4.4.3",
4006+
"@aws/mynah-ui": "4.5.4",
40074007
"@gerhobbelt/gitignore-parser": "^0.2.0-9",
40084008
"@iarna/toml": "^2.2.5",
40094009
"@smithy/shared-ini-file-loader": "^2.2.8",

packages/core/src/amazonq/webview/ui/quickActions/generator.ts

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { QuickActionCommandGroup } from '@aws/mynah-ui/dist/static'
6+
import { QuickActionCommand, QuickActionCommandGroup } from '@aws/mynah-ui/dist/static'
77
import { TabType } from '../storages/tabsStorage'
88

99
export interface QuickActionGeneratorProps {
@@ -21,51 +21,89 @@ export class QuickActionGenerator {
2121
}
2222

2323
public generateForTab(tabType: TabType): QuickActionCommandGroup[] {
24-
switch (tabType) {
25-
case 'featuredev':
26-
return []
27-
default:
28-
return [
29-
...(this.isFeatureDevEnabled
30-
? [
24+
const quickActionCommands = [
25+
...(this.isFeatureDevEnabled
26+
? [
27+
{
28+
groupName: 'Application Development',
29+
commands: [
3130
{
32-
groupName: 'Application Development',
33-
commands: [
34-
{
35-
command: '/dev',
36-
placeholder: 'Briefly describe a task or issue',
37-
description:
38-
'Use all project files as context for code suggestions (increases latency).',
39-
},
40-
],
31+
command: '/dev',
32+
placeholder: 'Briefly describe a task or issue',
33+
description:
34+
'Use all project files as context for code suggestions (increases latency).',
4135
},
42-
]
43-
: []),
44-
...(this.isGumbyEnabled
45-
? [
36+
],
37+
},
38+
]
39+
: []),
40+
...(this.isGumbyEnabled
41+
? [
42+
{
43+
commands: [
4644
{
47-
commands: [
48-
{
49-
command: '/transform',
50-
description: 'Transform your Java 8 or 11 Maven project to Java 17',
51-
},
52-
],
45+
command: '/transform',
46+
description: 'Transform your Java 8 or 11 Maven project to Java 17',
5347
},
54-
]
55-
: []),
48+
],
49+
},
50+
]
51+
: []),
52+
{
53+
commands: [
5654
{
57-
commands: [
58-
{
59-
command: '/help',
60-
description: 'Learn more about Amazon Q',
61-
},
62-
{
63-
command: '/clear',
64-
description: 'Clear this session',
65-
},
66-
],
55+
command: '/help',
56+
description: 'Learn more about Amazon Q',
6757
},
68-
]
58+
{
59+
command: '/clear',
60+
description: 'Clear this session',
61+
},
62+
],
63+
},
64+
]
65+
66+
const commandUnavailability: Record<
67+
TabType,
68+
{
69+
description: string
70+
unavailableItems: string[]
71+
}
72+
> = {
73+
cwc: {
74+
description: '',
75+
unavailableItems: [],
76+
},
77+
featuredev: {
78+
description: "This command isn't available in /dev",
79+
unavailableItems: ['/dev', '/transform', '/help', '/clear'],
80+
},
81+
gumby: {
82+
description: "This command isn't available in /transform",
83+
unavailableItems: ['/dev', '/transform'],
84+
},
85+
unknown: {
86+
description: "This command isn't available",
87+
unavailableItems: ['/dev', '/transform', '/help', '/clear'],
88+
},
6989
}
90+
91+
return quickActionCommands.map(commandGroup => {
92+
return {
93+
groupName: commandGroup.groupName,
94+
commands: commandGroup.commands.map((commandItem: QuickActionCommand) => {
95+
const commandNotAvailable = commandUnavailability[tabType].unavailableItems.includes(
96+
commandItem.command
97+
)
98+
return {
99+
...commandItem,
100+
disabled: commandNotAvailable,
101+
description: commandNotAvailable
102+
? commandUnavailability[tabType].description
103+
: commandItem.description,
104+
}
105+
}) as QuickActionCommand[],
106+
}
107+
}) as QuickActionCommandGroup[]
70108
}
71109
}

packages/core/src/shared/logger/activation.ts

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,17 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import * as path from 'path'
76
import * as vscode from 'vscode'
8-
import * as nls from 'vscode-nls'
97
import { Logger, LogLevel, getLogger } from '.'
108
import { setLogger } from './logger'
119
import { WinstonToolkitLogger } from './winstonToolkitLogger'
12-
import { waitUntil } from '../utilities/timeoutUtils'
13-
import { cleanLogFiles } from './util'
1410
import { Settings } from '../settings'
1511
import { Logging } from './commands'
1612
import { resolvePath } from '../utilities/pathUtils'
1713
import { isWeb } from '../../common/webUtils'
1814
import { fsCommon } from '../../srcShared/fs'
1915
import globals from '../extensionGlobals'
2016

21-
const localize = nls.loadMessageBundle()
22-
2317
export const defaultLogLevel: LogLevel = 'debug'
2418

2519
/**
@@ -33,15 +27,13 @@ export async function activate(
3327
): Promise<void> {
3428
const settings = Settings.instance.getSection('aws')
3529
const devLogfile = settings.get('dev.logfile', '')
36-
const logUri = devLogfile
37-
? vscode.Uri.file(resolvePath(devLogfile))
38-
: vscode.Uri.joinPath(extensionContext.logUri, makeLogFilename())
30+
const logUri = devLogfile ? vscode.Uri.file(resolvePath(devLogfile)) : undefined
3931

4032
await fsCommon.mkdir(extensionContext.logUri)
4133

4234
const mainLogger = makeLogger(
4335
{
44-
logPaths: [logUri],
36+
logPaths: logUri ? [logUri] : undefined,
4537
outputChannels: [logChannel],
4638
useConsoleLog: isWeb(),
4739
},
@@ -55,7 +47,7 @@ export async function activate(
5547
setLogger(
5648
makeLogger(
5749
{
58-
logPaths: [logUri],
50+
logPaths: logUri ? [logUri] : undefined,
5951
outputChannels: [outputChannel, logChannel],
6052
},
6153
extensionContext.subscriptions
@@ -80,18 +72,6 @@ export async function activate(
8072

8173
Logging.init(logUri, mainLogger, contextPrefix)
8274
extensionContext.subscriptions.push(Logging.instance.viewLogs, Logging.instance.viewLogsAtMessage)
83-
84-
createLogWatcher(logUri)
85-
.then(sub => {
86-
extensionContext.subscriptions.push(sub)
87-
})
88-
.catch(err => {
89-
getLogger().warn('Failed to start log file watcher: %s', err)
90-
})
91-
92-
cleanLogFiles(path.dirname(logUri.fsPath)).catch(err => {
93-
getLogger().warn('Failed to clean-up old logs: %s', err)
94-
})
9575
}
9676

9777
/**
@@ -150,60 +130,3 @@ function getLogLevel(): LogLevel {
150130
const configuration = Settings.instance.getSection('aws')
151131
return configuration.get(`${globals.contextPrefix}logLevel`, defaultLogLevel)
152132
}
153-
154-
/**
155-
* Creates a name for the toolkit's logfile.
156-
* Essentially an ISO string, but in the local timezone and without the trailing "Z"
157-
* @returns Log filename
158-
*/
159-
function makeLogFilename(): string {
160-
const now = new Date()
161-
// local to machine: use getMonth/Date instead of UTC equivalent
162-
// month is zero-terminated: offset by 1
163-
const m = (now.getMonth() + 1).toString().padStart(2, '0')
164-
const d = now.getDate().toString().padStart(2, '0')
165-
const h = now.getHours().toString().padStart(2, '0')
166-
const mn = now.getMinutes().toString().padStart(2, '0')
167-
const s = now.getSeconds().toString().padStart(2, '0')
168-
const dt = `${now.getFullYear()}${m}${d}T${h}${mn}${s}`
169-
170-
return `aws_toolkit_${dt}.log`
171-
}
172-
173-
/**
174-
* Watches for renames on the log file and notifies the user.
175-
*/
176-
async function createLogWatcher(logFile: vscode.Uri): Promise<vscode.Disposable> {
177-
if (isWeb()) {
178-
getLogger().debug(`Not watching log file since we are in Browser.`)
179-
return { dispose: () => {} }
180-
}
181-
182-
const exists = await waitUntil(() => fsCommon.existsFile(logFile), { interval: 1000, timeout: 60000 })
183-
184-
if (!exists) {
185-
getLogger().warn(`Log file ${logFile.path} does not exist!`)
186-
return { dispose: () => {} }
187-
}
188-
189-
let checking = false
190-
// TODO: fs.watch() has many problems, consider instead:
191-
// - https://github.com/paulmillr/chokidar
192-
// - https://www.npmjs.com/package/fb-watchman
193-
const fs = await import('fs')
194-
const watcher = fs.watch(logFile.fsPath, async eventType => {
195-
if (checking || eventType !== 'rename') {
196-
return
197-
}
198-
checking = true
199-
if (!(await fsCommon.existsFile(logFile))) {
200-
await vscode.window.showWarningMessage(
201-
localize('AWS.log.logFileMove', 'The log file for this session has been moved or deleted.')
202-
)
203-
watcher.close()
204-
}
205-
checking = false
206-
})
207-
208-
return { dispose: () => watcher.close() }
209-
}

packages/core/src/shared/logger/commands.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Logger } from '.'
88
import { telemetry } from '../telemetry/telemetry'
99
import { Commands } from '../vscode/commands2'
1010
import { getLogger } from './logger'
11+
import globals from '../extensionGlobals'
1112

1213
function revealLines(editor: vscode.TextEditor, start: number, end: number): void {
1314
const startPos = editor.document.lineAt(start).range.start
@@ -36,21 +37,41 @@ export class Logging {
3637
return this.#instance
3738
}
3839

39-
public static init(logUri: vscode.Uri, logger: Logger, contextPrefix: string) {
40+
/**
41+
* @param logUri (optional) Log file path, only used for "developer mode" (`aws.dev.logfile` setting).
42+
* @param logger
43+
* @param contextPrefix Decided the command name based on the extension context.
44+
*/
45+
public static init(logUri: vscode.Uri | undefined, logger: Logger, contextPrefix: string) {
4046
this.#instance = new Logging(logUri, logger, contextPrefix)
4147
}
4248

43-
constructor(private readonly logUri: vscode.Uri, private readonly logger: Logger, contextPrefix: string) {
49+
/**
50+
* @see {@link init}
51+
*/
52+
constructor(
53+
private readonly logUri: vscode.Uri | undefined,
54+
private readonly logger: Logger,
55+
contextPrefix: string
56+
) {
4457
this.viewLogs = Commands.register(`aws.${contextPrefix}.viewLogs`, () => this.openLogUri())
4558
this.viewLogsAtMessage = Commands.register(`aws.${contextPrefix}.viewLogsAtMessage`, id => this.openLogId(id))
4659
}
4760

4861
public async openLogUri(): Promise<vscode.TextEditor | undefined> {
62+
if (!this.logUri) {
63+
globals.logOutputChannel.show(true)
64+
return undefined
65+
}
4966
telemetry.toolkit_viewLogs.emit({ result: 'Succeeded' })
5067
return vscode.window.showTextDocument(this.logUri)
5168
}
5269

5370
public async openLogId(logId: number) {
71+
if (!this.logUri) {
72+
globals.logOutputChannel.show(true)
73+
return
74+
}
5475
const msg = this.logger.getLogById(logId, this.logUri)
5576
const editor = await this.openLogUri()
5677
if (!msg || !editor) {

0 commit comments

Comments
 (0)