Skip to content

Commit dcc47aa

Browse files
committed
Address comments
1 parent 2dccede commit dcc47aa

File tree

11 files changed

+89
-85
lines changed

11 files changed

+89
-85
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Breaking Change",
3+
"description": "Change keybind for focusing chat to ctrl+win+i on Windows, ctrl+cmd+i on macOS and ctrl+meta+i on Linux"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Use inline chat to select code and transform it with natural language instructions"
4+
}

packages/amazonq/src/inlineChat/codeLenses/codeLenseProvider.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import * as vscode from 'vscode'
7+
import * as os from 'os'
78
import { InlineTask, TaskState } from '../controller/inlineTask'
89

910
export class CodelensProvider implements vscode.CodeLensProvider {
@@ -27,7 +28,7 @@ export class CodelensProvider implements vscode.CodeLensProvider {
2728
return
2829
}
2930
switch (task.state) {
30-
case TaskState.InProgress:
31+
case TaskState.InProgress: {
3132
this.codeLenses = []
3233
this.codeLenses.push(
3334
new vscode.CodeLens(new vscode.Range(task.selectedRange.start, task.selectedRange.start), {
@@ -36,26 +37,39 @@ export class CodelensProvider implements vscode.CodeLensProvider {
3637
})
3738
)
3839
break
39-
case TaskState.WaitingForDecision:
40+
}
41+
case TaskState.WaitingForDecision: {
42+
let acceptTitle: string
43+
let rejectTitle: string
44+
if (os.platform() === 'darwin') {
45+
acceptTitle = 'Accept ($(newline))'
46+
rejectTitle = `Reject ( \u238B )`
47+
} else {
48+
acceptTitle = 'Accept (Enter)'
49+
rejectTitle = `Reject (Esc)`
50+
}
51+
4052
this.codeLenses = []
4153
this.codeLenses.push(
4254
new vscode.CodeLens(new vscode.Range(task.selectedRange.start, task.selectedRange.start), {
43-
title: 'Accept ($(newline))',
55+
title: acceptTitle,
4456
command: 'aws.amazonq.inline.waitForUserDecisionAcceptAll',
4557
arguments: [task],
4658
})
4759
)
4860
this.codeLenses.push(
4961
new vscode.CodeLens(new vscode.Range(task.selectedRange.start, task.selectedRange.start), {
50-
title: `Reject ( \u238B )`,
62+
title: rejectTitle,
5163
command: 'aws.amazonq.inline.waitForUserDecisionRejectAll',
5264
arguments: [task],
5365
})
5466
)
5567
break
56-
default:
68+
}
69+
default: {
5770
this.codeLenses = []
5871
break
72+
}
5973
}
6074
this._onDidChangeCodeLenses.fire()
6175
}

packages/amazonq/src/inlineChat/controller/inlineChatController.ts

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import { computeDecorations } from '../decorations/computeDecorations'
1313
import { CodelensProvider } from '../codeLenses/codeLenseProvider'
1414
import { ReferenceLogController } from 'aws-core-vscode/codewhispererChat'
1515
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
16-
import { codicon, getIcon, getLogger, messages, setContext, Timeout } from 'aws-core-vscode/shared'
16+
import { addEofNewline, codicon, getIcon, getLogger, messages, setContext, Timeout } from 'aws-core-vscode/shared'
1717
import { InlineLineAnnotationController } from '../decorations/inlineLineAnnotationController'
18-
import { fixEofNewline } from './utils'
1918

2019
export class InlineChatController {
2120
private task: InlineTask | undefined
@@ -181,7 +180,7 @@ export class InlineChatController {
181180
if (!query) {
182181
return
183182
}
184-
await fixEofNewline(editor)
183+
await addEofNewline(editor)
185184
this.task = await this.createTask(query, editor.document, editor.selection)
186185
await this.inlineLineAnnotationController.disable(editor)
187186
await this.computeDiffAndRenderOnEditor(query, editor.document).catch(async (err) => {
@@ -357,46 +356,6 @@ export class InlineChatController {
357356
}
358357
}
359358

360-
// private async applyDiff(
361-
// task: InlineTask,
362-
// textDiff: TextDiff[],
363-
// undoOption?: { undoStopBefore: boolean; undoStopAfter: boolean }
364-
// ) {
365-
// // const adjustedTextDiff = adjustTextDiffForEditing(textDiff)
366-
// const visibleEditor = vscode.window.visibleTextEditors.find(
367-
// (editor) => editor.document.uri === task.document.uri
368-
// )
369-
// const range = task.newSelectedRange ?? task.selectedRange
370-
// const newRange = new vscode.Range(
371-
// range!.start,
372-
// new vscode.Position(range.start.line + task.estimatedResponse!.split('\n').length - 1, 0)
373-
// )
374-
// task.newSelectedRange = newRange
375-
// if (visibleEditor) {
376-
// await visibleEditor.edit(
377-
// (editBuilder) => {
378-
// editBuilder.replace(range, task.estimatedResponse!)
379-
// },
380-
// undoOption ?? { undoStopBefore: true, undoStopAfter: false }
381-
// )
382-
// } else {
383-
// // if (previousDiff) {
384-
// // const edit = new vscode.WorkspaceEdit()
385-
// // for (const insertion of previousDiff) {
386-
// // edit.delete(task.document.uri, insertion.range)
387-
// // }
388-
// // await vscode.workspace.applyEdit(edit)
389-
// // }
390-
// // const edit = new vscode.WorkspaceEdit()
391-
// // for (const change of textDiff) {
392-
// // if (change.type === 'insertion') {
393-
// // edit.insert(task.document.uri, change.range.start, change.replacementText)
394-
// // }
395-
// // }
396-
// // await vscode.workspace.applyEdit(edit)
397-
// }
398-
// }
399-
400359
private undoListener(task: InlineTask) {
401360
const listener: vscode.Disposable = vscode.workspace.onDidChangeTextDocument(async (event) => {
402361
const { document, contentChanges } = event

packages/amazonq/src/inlineChat/controller/inlineTask.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import type { CodeReference } from 'aws-core-vscode/amazonq'
77
import type { InlineChatEvent } from 'aws-core-vscode/codewhisperer'
88
import type { Decorations } from '../decorations/inlineDecorator'
99
import { computeDecorations } from '../decorations/computeDecorations'
10-
import { expandSelectionToFullLines } from './utils'
1110
import { extractLanguageNameFromFile } from 'aws-core-vscode/codewhispererChat'
11+
import { expandSelectionToFullLines } from 'aws-core-vscode/shared'
1212

1313
interface TextToInsert {
1414
type: 'insertion'

packages/amazonq/src/inlineChat/controller/utils.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/amazonq/src/inlineChat/output/responseTransformer.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import { getLogger } from 'aws-core-vscode/shared'
77
import { decode } from 'he'
88
import { InlineTask } from '../controller/inlineTask'
99

10+
/**
11+
* Transforms the response from the INLINE_CHAT GenerateAssistantResponse call.
12+
*
13+
* @param response - The raw response string from GenerateAssistantResponse.
14+
* @param inlineTask - The inline task object containing information about the current task.
15+
* @param isWholeResponse - A boolean indicating whether this is a complete response or a partial one.
16+
* @returns The decoded response string, or undefined if an error occurs.
17+
*/
1018
export function responseTransformer(
1119
response: string,
1220
inlineTask: InlineTask,
@@ -28,6 +36,16 @@ export function responseTransformer(
2836
}
2937
}
3038

39+
/**
40+
* This function is used to handle partial responses in inline tasks. It divides
41+
* the selected text into two parts:
42+
* 1. The "left" part, which contains the same number of lines as the response.
43+
* 2. The "right" part, which contains the remaining lines.
44+
*
45+
* @param response - The response string from the assistant.
46+
* @param inlineTask - The inline task object containing the full selected text.
47+
* @returns A tuple with two strings: [leftPart, rightPart].
48+
*/
3149
function extractPartialCode(response: string, inlineTask: InlineTask): [string, string] {
3250
const lineCount = response.split('\n').length
3351
const splitLines = inlineTask.selectedText.split('\n')

packages/core/src/amazonq/util/authUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
import { FeatureAuthState } from '../../codewhisperer'
77
import { AuthFollowUpType, AuthMessageDataMap } from '../auth/model'
88

9+
/**
10+
* This function evaluates the authentication state of CodeWhisperer features (chat and core)
11+
* when the authentication is not valid, and returns the appropriate authentication follow-up type and message.
12+
*
13+
* @param credentialState - The current authentication state for each CodeWhisperer feature
14+
* @returns An object containing:
15+
* - authType: The type of authentication follow-up required (AuthFollowUpType)
16+
* - message: The corresponding message for the determined auth type
17+
*/
918
export function extractAuthFollowUp(credentialState: FeatureAuthState) {
1019
let authType: AuthFollowUpType = 'full-auth'
1120
let message = AuthMessageDataMap[authType].message

packages/core/src/codewhisperer/client/codewhisperer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ export class DefaultCodeWhispererClient {
226226
const client = await this.createUserSdkClient()
227227
const requester = async (request: CodeWhispererUserClient.ListAvailableCustomizationsRequest) =>
228228
client.listAvailableCustomizations(request).promise()
229-
// @ts-ignore
230229
return pageableToCollection(requester, {}, 'nextToken')
231230
.promise()
232231
.then((resps) => {

packages/core/src/shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ export { CrashMonitoring } from './crashMonitoring'
5656
export { amazonQDiffScheme } from './constants'
5757
export * from './featureConfig'
5858
export * from './icons'
59+
export * from './utilities/textDocumentUtilities'

0 commit comments

Comments
 (0)