Skip to content

Commit b63f600

Browse files
committed
still wip, remember to reset soft this commit
1 parent cb0f640 commit b63f600

File tree

7 files changed

+145
-114
lines changed

7 files changed

+145
-114
lines changed

aws-toolkit-vscode.code-workspace

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
{
1313
"path": "packages/amazonq",
1414
},
15+
{
16+
"path": "../language-servers",
17+
},
1518
],
1619
"settings": {
1720
"typescript.tsdk": "node_modules/typescript/lib",

packages/amazonq/.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1414
"env": {
1515
"SSMDOCUMENT_LANGUAGESERVER_PORT": "6010",
16-
"WEBPACK_DEVELOPER_SERVER": "http://localhost:8080"
16+
"WEBPACK_DEVELOPER_SERVER": "http://localhost:8080",
1717
// Below allows for overrides used during development
18-
// "__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/agent-standalone.js",
18+
"__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/agent-standalone.js"
1919
// "__AMAZONQLSP_UI": "${workspaceFolder}/../../../language-servers/chat-client/build/amazonq-ui.js"
2020
},
2121
"envFile": "${workspaceFolder}/.local.env",

packages/amazonq/package.json

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,159 +1289,173 @@
12891289
"fontCharacter": "\\f1d2"
12901290
}
12911291
},
1292-
"aws-lambda-function": {
1292+
"aws-lambda-deployed-function": {
12931293
"description": "AWS Contributed Icon",
12941294
"default": {
12951295
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
12961296
"fontCharacter": "\\f1d3"
12971297
}
12981298
},
1299-
"aws-mynah-MynahIconBlack": {
1299+
"aws-lambda-function": {
13001300
"description": "AWS Contributed Icon",
13011301
"default": {
13021302
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13031303
"fontCharacter": "\\f1d4"
13041304
}
13051305
},
1306-
"aws-mynah-MynahIconWhite": {
1306+
"aws-lambda-invoke-remotely": {
13071307
"description": "AWS Contributed Icon",
13081308
"default": {
13091309
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13101310
"fontCharacter": "\\f1d5"
13111311
}
13121312
},
1313-
"aws-mynah-logo": {
1313+
"aws-mynah-MynahIconBlack": {
13141314
"description": "AWS Contributed Icon",
13151315
"default": {
13161316
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13171317
"fontCharacter": "\\f1d6"
13181318
}
13191319
},
1320-
"aws-redshift-cluster": {
1320+
"aws-mynah-MynahIconWhite": {
13211321
"description": "AWS Contributed Icon",
13221322
"default": {
13231323
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13241324
"fontCharacter": "\\f1d7"
13251325
}
13261326
},
1327-
"aws-redshift-cluster-connected": {
1327+
"aws-mynah-logo": {
13281328
"description": "AWS Contributed Icon",
13291329
"default": {
13301330
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13311331
"fontCharacter": "\\f1d8"
13321332
}
13331333
},
1334-
"aws-redshift-database": {
1334+
"aws-redshift-cluster": {
13351335
"description": "AWS Contributed Icon",
13361336
"default": {
13371337
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13381338
"fontCharacter": "\\f1d9"
13391339
}
13401340
},
1341-
"aws-redshift-redshift-cluster-connected": {
1341+
"aws-redshift-cluster-connected": {
13421342
"description": "AWS Contributed Icon",
13431343
"default": {
13441344
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13451345
"fontCharacter": "\\f1da"
13461346
}
13471347
},
1348-
"aws-redshift-schema": {
1348+
"aws-redshift-database": {
13491349
"description": "AWS Contributed Icon",
13501350
"default": {
13511351
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13521352
"fontCharacter": "\\f1db"
13531353
}
13541354
},
1355-
"aws-redshift-table": {
1355+
"aws-redshift-redshift-cluster-connected": {
13561356
"description": "AWS Contributed Icon",
13571357
"default": {
13581358
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13591359
"fontCharacter": "\\f1dc"
13601360
}
13611361
},
1362-
"aws-s3-bucket": {
1362+
"aws-redshift-schema": {
13631363
"description": "AWS Contributed Icon",
13641364
"default": {
13651365
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13661366
"fontCharacter": "\\f1dd"
13671367
}
13681368
},
1369-
"aws-s3-create-bucket": {
1369+
"aws-redshift-table": {
13701370
"description": "AWS Contributed Icon",
13711371
"default": {
13721372
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13731373
"fontCharacter": "\\f1de"
13741374
}
13751375
},
1376-
"aws-sagemaker-code-editor": {
1376+
"aws-s3-bucket": {
13771377
"description": "AWS Contributed Icon",
13781378
"default": {
13791379
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13801380
"fontCharacter": "\\f1df"
13811381
}
13821382
},
1383-
"aws-sagemaker-jupyter-lab": {
1383+
"aws-s3-create-bucket": {
13841384
"description": "AWS Contributed Icon",
13851385
"default": {
13861386
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13871387
"fontCharacter": "\\f1e0"
13881388
}
13891389
},
1390-
"aws-sagemakerunifiedstudio-catalog": {
1390+
"aws-sagemaker-code-editor": {
13911391
"description": "AWS Contributed Icon",
13921392
"default": {
13931393
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
13941394
"fontCharacter": "\\f1e1"
13951395
}
13961396
},
1397-
"aws-sagemakerunifiedstudio-spaces": {
1397+
"aws-sagemaker-jupyter-lab": {
13981398
"description": "AWS Contributed Icon",
13991399
"default": {
14001400
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14011401
"fontCharacter": "\\f1e2"
14021402
}
14031403
},
1404-
"aws-sagemakerunifiedstudio-spaces-dark": {
1404+
"aws-sagemakerunifiedstudio-catalog": {
14051405
"description": "AWS Contributed Icon",
14061406
"default": {
14071407
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14081408
"fontCharacter": "\\f1e3"
14091409
}
14101410
},
1411-
"aws-sagemakerunifiedstudio-symbol-int": {
1411+
"aws-sagemakerunifiedstudio-spaces": {
14121412
"description": "AWS Contributed Icon",
14131413
"default": {
14141414
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14151415
"fontCharacter": "\\f1e4"
14161416
}
14171417
},
1418-
"aws-sagemakerunifiedstudio-table": {
1418+
"aws-sagemakerunifiedstudio-spaces-dark": {
14191419
"description": "AWS Contributed Icon",
14201420
"default": {
14211421
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14221422
"fontCharacter": "\\f1e5"
14231423
}
14241424
},
1425-
"aws-schemas-registry": {
1425+
"aws-sagemakerunifiedstudio-symbol-int": {
14261426
"description": "AWS Contributed Icon",
14271427
"default": {
14281428
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14291429
"fontCharacter": "\\f1e6"
14301430
}
14311431
},
1432-
"aws-schemas-schema": {
1432+
"aws-sagemakerunifiedstudio-table": {
14331433
"description": "AWS Contributed Icon",
14341434
"default": {
14351435
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14361436
"fontCharacter": "\\f1e7"
14371437
}
14381438
},
1439-
"aws-stepfunctions-preview": {
1439+
"aws-schemas-registry": {
14401440
"description": "AWS Contributed Icon",
14411441
"default": {
14421442
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
14431443
"fontCharacter": "\\f1e8"
14441444
}
1445+
},
1446+
"aws-schemas-schema": {
1447+
"description": "AWS Contributed Icon",
1448+
"default": {
1449+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1450+
"fontCharacter": "\\f1e9"
1451+
}
1452+
},
1453+
"aws-stepfunctions-preview": {
1454+
"description": "AWS Contributed Icon",
1455+
"default": {
1456+
"fontPath": "./resources/fonts/aws-toolkit-icons.woff",
1457+
"fontCharacter": "\\f1ea"
1458+
}
14451459
}
14461460
},
14471461
"walkthroughs": [

packages/amazonq/src/app/inline/EditRendering/imageRenderer.ts

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { AmazonQInlineCompletionItemProvider } from '../completion'
1414
import { vsCodeState } from 'aws-core-vscode/codewhisperer'
1515
import { applyPatch, createPatch } from 'diff'
1616
import { EditSuggestionState } from '../editSuggestionState'
17+
import { debounce } from 'aws-core-vscode/utils'
1718

1819
function logSuggestionFailure(type: 'DISCARD' | 'REJECT', reason: string, suggestionContent: string) {
1920
getLogger('nextEditPrediction').debug(
@@ -22,7 +23,8 @@ function logSuggestionFailure(type: 'DISCARD' | 'REJECT', reason: string, sugges
2223
}
2324

2425
const autoRejectEditCursorDistance = 25
25-
const maxPrefixRetryCount = 5
26+
const maxPrefixRetryCharDiff = 7
27+
const docChangedHandlerDeboucneInMs = 750
2628

2729
enum RejectReason {
2830
DocumentChange = 'Invalid patch due to document change',
@@ -34,9 +36,11 @@ export class EditsSuggestionSvg {
3436
private readonly logger = getLogger('nextEditPrediction')
3537
private documentChangedListener: vscode.Disposable | undefined
3638
private cursorChangedListener: vscode.Disposable | undefined
37-
private readonly updatedSuggestions: InlineCompletionItemWithReferences[] = []
39+
3840
private startLine = 0
3941

42+
private docChanged: string = ''
43+
4044
constructor(
4145
private suggestion: InlineCompletionItemWithReferences,
4246
private readonly editor: vscode.TextEditor,
@@ -45,15 +49,12 @@ export class EditsSuggestionSvg {
4549
private readonly inlineCompletionProvider?: AmazonQInlineCompletionItemProvider
4650
) {}
4751

48-
async show() {
52+
async show(patchedSuggestion?: InlineCompletionItemWithReferences) {
4953
if (!this.editor) {
5054
return
5155
}
5256

53-
const item =
54-
this.updatedSuggestions.length > 0
55-
? this.updatedSuggestions[this.updatedSuggestions.length - 1]
56-
: this.suggestion
57+
const item = patchedSuggestion ? patchedSuggestion : this.suggestion
5758

5859
try {
5960
const svgGenerationService = new SvgGenerationService()
@@ -74,7 +75,24 @@ export class EditsSuggestionSvg {
7475
if (svgImage) {
7576
const documentChangedListener = (this.documentChangedListener ??=
7677
vscode.workspace.onDidChangeTextDocument(async (e) => {
77-
await this.onDocChange(e)
78+
if (e.contentChanges.length <= 0) {
79+
return
80+
}
81+
if (e.document !== this.editor.document) {
82+
return
83+
}
84+
if (vsCodeState.isCodeWhispererEditing) {
85+
return
86+
}
87+
if (getContext('aws.amazonq.editSuggestionActive') === false) {
88+
return
89+
}
90+
91+
// TODO: handle multi-contentChanges scenario
92+
const diff = e.contentChanges[0] ? e.contentChanges[0].text : ''
93+
this.logger.info(`docChange sessionId=${this.session.sessionId}, contentChange=${diff}`)
94+
this.docChanged += e.contentChanges[0].text
95+
await this.debouncedOnDocChanged(e)
7896
}))
7997

8098
const cursorChangedListener = (this.cursorChangedListener ??=
@@ -122,22 +140,12 @@ export class EditsSuggestionSvg {
122140
}
123141
}
124142

125-
private async onDocChange(e: vscode.TextDocumentChangeEvent) {
126-
if (e.contentChanges.length <= 0) {
127-
return
128-
}
129-
if (e.document !== this.editor.document) {
130-
return
131-
}
132-
if (vsCodeState.isCodeWhispererEditing) {
133-
return
134-
}
135-
if (getContext('aws.amazonq.editSuggestionActive') === false) {
136-
return
137-
}
138-
139-
this.logger.info(`docChange ${this.session.sessionId}, contentChange=${e.contentChanges[0].text}`)
143+
debouncedOnDocChanged = debounce(
144+
async (e: vscode.TextDocumentChangeEvent) => await this.onDocChange(e),
145+
docChangedHandlerDeboucneInMs
146+
)
140147

148+
private async onDocChange(e: vscode.TextDocumentChangeEvent) {
141149
/**
142150
* 1. Take the diff returned by the model and apply it to the code we originally sent to the model
143151
* 2. Do a diff between the above code and what's currently in the editor
@@ -150,13 +158,15 @@ export class EditsSuggestionSvg {
150158
if (appliedToOriginal) {
151159
const updatedPatch = this.patchSuggestion(appliedToOriginal)
152160

153-
if (this.updatedSuggestions.length > maxPrefixRetryCount) {
161+
if (this.docChanged.length > maxPrefixRetryCharDiff) {
162+
this.logger.info(`docChange: ${this.docChanged}`)
154163
this.autoReject(RejectReason.MaxRetry)
155-
} else if (applyPatch(this.editor.document.getText(), updatedPatch) === false) {
164+
} else if (applyPatch(this.editor.document.getText(), updatedPatch.insertText as string) === false) {
156165
this.autoReject(RejectReason.DocumentChange)
157166
} else {
158167
// Close the previoius popup and rerender it
159-
await this.rerender()
168+
this.logger.info(`calling rerender with suggestion\n ${updatedPatch.insertText as string}`)
169+
await this.rerender(updatedPatch)
160170
}
161171
} else {
162172
this.autoReject(RejectReason.NotApplicableToOriginal)
@@ -173,26 +183,23 @@ export class EditsSuggestionSvg {
173183
await decorationManager.clearDecorations(this.editor, [])
174184
}
175185

176-
private async rerender() {
186+
private async rerender(suggestion: InlineCompletionItemWithReferences) {
177187
await decorationManager.clearDecorations(this.editor, [])
178-
await this.show()
188+
await this.show(suggestion)
179189
}
180190

181191
private autoReject(reason: string) {
182192
logSuggestionFailure('REJECT', reason, this.suggestion.insertText as string)
183193
void vscode.commands.executeCommand('aws.amazonq.inline.rejectEdit')
184194
}
185195

186-
private patchSuggestion(appliedToOriginal: string): string {
196+
private patchSuggestion(appliedToOriginal: string): InlineCompletionItemWithReferences {
187197
const updatedPatch = createPatch(
188198
this.editor.document.fileName,
189199
this.editor.document.getText(),
190200
appliedToOriginal
191201
)
192-
193202
this.logger.info(`Update edit suggestion\n ${updatedPatch}`)
194-
const updated: InlineCompletionItemWithReferences = { ...this.suggestion, insertText: updatedPatch }
195-
this.updatedSuggestions.push(updated)
196-
return updatedPatch
203+
return { ...this.suggestion, insertText: updatedPatch }
197204
}
198205
}

packages/amazonq/src/app/inline/recommendationService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ export class RecommendationService {
141141
* Edits leverage partialResultToken to achieve EditStreak such that clients can pull all continuous suggestions generated by the model within 1 EOS block.
142142
*/
143143
if (!isTriggerByDeletion && !request.partialResultToken && !EditSuggestionState.isEditSuggestionActive()) {
144-
const completionPromise: Promise<InlineCompletionListWithReferences> = languageClient.sendRequest(
145-
inlineCompletionWithReferencesRequestType.method,
146-
request,
147-
token
148-
)
149-
ps.push(completionPromise)
144+
// const completionPromise: Promise<InlineCompletionListWithReferences> = languageClient.sendRequest(
145+
// inlineCompletionWithReferencesRequestType.method,
146+
// request,
147+
// token
148+
// )
149+
// ps.push(completionPromise)
150150
}
151151

152152
/**

0 commit comments

Comments
 (0)