Skip to content

Commit 264354a

Browse files
committed
partial migration
1 parent 87dc533 commit 264354a

File tree

31 files changed

+169
-152
lines changed

31 files changed

+169
-152
lines changed

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -279,25 +279,27 @@ export class LspController {
279279

280280
async query(s: string): Promise<RelevantTextDocument[]> {
281281
const chunks: Chunk[] | undefined = await LspClient.instance.queryVectorIndex(s)
282-
const resp: RelevantTextDocument[] = []
283-
chunks?.forEach((chunk) => {
284-
const text = chunk.context ? chunk.context : chunk.content
285-
if (chunk.programmingLanguage && chunk.programmingLanguage !== 'unknown') {
286-
resp.push({
287-
text: text,
288-
relativeFilePath: chunk.relativePath ? chunk.relativePath : path.basename(chunk.filePath),
289-
programmingLanguage: {
290-
languageName: chunk.programmingLanguage,
291-
},
292-
})
293-
} else {
294-
resp.push({
295-
text: text,
296-
relativeFilePath: chunk.relativePath ? chunk.relativePath : path.basename(chunk.filePath),
297-
})
298-
}
299-
})
300-
return resp
282+
return (
283+
chunks?.flatMap((chunk) => {
284+
const text = chunk.context ? chunk.context : chunk.content
285+
return chunk.programmingLanguage && chunk.programmingLanguage !== 'unknown'
286+
? [
287+
{
288+
text: text,
289+
relativeFilePath: chunk.relativePath ? chunk.relativePath : path.basename(chunk.filePath),
290+
programmingLanguage: {
291+
languageName: chunk.programmingLanguage,
292+
},
293+
},
294+
]
295+
: [
296+
{
297+
text: text,
298+
relativeFilePath: chunk.relativePath ? chunk.relativePath : path.basename(chunk.filePath),
299+
},
300+
]
301+
}) ?? []
302+
)
301303
}
302304

303305
async queryInlineProjectContext(query: string, path: string, target: 'bm25' | 'codemap' | 'default') {

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,10 @@ export class QuickActionHandler {
107107
if (!this.isScanEnabled) {
108108
return
109109
}
110-
let scanTabId: string | undefined = undefined
111-
112-
this.tabsStorage.getTabs().forEach((tab) => {
113-
if (tab.type === 'review') {
114-
scanTabId = tab.id
115-
}
116-
})
110+
const scanTabId = this.tabsStorage
111+
.getTabs()
112+
.reverse()
113+
.find((tab) => tab.type === 'review')?.id
117114

118115
if (scanTabId !== undefined) {
119116
this.mynahUI.selectTab(scanTabId, eventId || '')
@@ -161,7 +158,7 @@ export class QuickActionHandler {
161158
if (!this.isTestEnabled) {
162159
return
163160
}
164-
const testTabId = this.tabsStorage.getTabs().find((tab) => tab.type === 'testgen')?.id
161+
const testTabId = this.tabsStorage.getTabByType('testgen')?.id
165162
const realPromptText = chatPrompt.escapedPrompt?.trim() ?? ''
166163

167164
if (testTabId !== undefined) {
@@ -290,13 +287,7 @@ export class QuickActionHandler {
290287
return
291288
}
292289

293-
let gumbyTabId: string | undefined = undefined
294-
295-
this.tabsStorage.getTabs().forEach((tab) => {
296-
if (tab.type === 'gumby') {
297-
gumbyTabId = tab.id
298-
}
299-
})
290+
const gumbyTabId = this.tabsStorage.getTabByType('gumby')?.id
300291

301292
if (gumbyTabId !== undefined) {
302293
this.mynahUI.selectTab(gumbyTabId, eventId || '')

packages/core/src/amazonq/webview/ui/storages/tabsStorage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ export class TabsStorage {
9191
return Array.from(this.tabs.values())
9292
}
9393

94+
public getTabByType(type: string): Tab | undefined {
95+
// TODO: Is there ever multiple tabs with the same type or is taking the last one unnecesary?
96+
return this.getTabs()
97+
.reverse()
98+
.find((tab) => tab.type === type)
99+
}
100+
94101
public isTabDead(tabID: string): boolean {
95102
return this.tabs.get(tabID)?.status === 'dead'
96103
}

packages/core/src/amazonqDoc/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ export function init(appContext: AmazonQAppInitContext) {
8989
authenticatingSessionIDs = authenticatingSessions.map((session: any) => session.tabID)
9090

9191
// We've already authenticated these sessions
92-
authenticatingSessions.forEach((session: any) => (session.isAuthenticating = false))
92+
for (const session of authenticatingSessions) {
93+
session.isAuthenticating = false
94+
}
9395
}
9496

9597
messenger.sendAuthenticationUpdate(authenticated, authenticatingSessionIDs)

packages/core/src/amazonqFeatureDev/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ export function init(appContext: AmazonQAppInitContext) {
9595
authenticatingSessionIDs = authenticatingSessions.map((session) => session.tabID)
9696

9797
// We've already authenticated these sessions
98-
authenticatingSessions.forEach((session) => (session.isAuthenticating = false))
98+
for (const session of authenticatingSessions) {
99+
session.isAuthenticating = false
100+
}
99101
}
100102

101103
messenger.sendAuthenticationUpdate(authenticated, authenticatingSessionIDs)

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,13 @@ export class Messenger {
194194
}
195195

196196
public async sendLanguageUpgradeProjectPrompt(projects: TransformationCandidateProject[], tabID: string) {
197-
const projectFormOptions: { value: any; label: string }[] = []
198-
const detectedJavaVersions = new Array<JDKVersion | undefined>()
199-
200-
projects.forEach((candidateProject) => {
201-
projectFormOptions.push({
197+
const projectFormOptions: { value: any; label: string }[] = projects.map((candidateProject) => {
198+
return {
202199
value: candidateProject.path,
203200
label: candidateProject.name,
204-
})
205-
detectedJavaVersions.push(candidateProject.JDKVersion)
201+
}
206202
})
203+
const detectedJavaVersions = projects.map((candidateProject) => candidateProject.JDKVersion)
207204

208205
const formItems: ChatItemFormItem[] = []
209206
formItems.push({
@@ -277,13 +274,11 @@ export class Messenger {
277274
}
278275

279276
public async sendSQLConversionProjectPrompt(projects: TransformationCandidateProject[], tabID: string) {
280-
const projectFormOptions: { value: any; label: string }[] = []
281-
282-
projects.forEach((candidateProject) => {
283-
projectFormOptions.push({
277+
const projectFormOptions: { value: any; label: string }[] = projects.map((candidateProject) => {
278+
return {
284279
value: candidateProject.path,
285280
label: candidateProject.name,
286-
})
281+
}
287282
})
288283

289284
const formItems: ChatItemFormItem[] = []
@@ -659,14 +654,12 @@ ${codeSnippet}
659654
public sendDependencyVersionsFoundMessage(versions: DependencyVersions, tabID: string) {
660655
const message = MessengerUtils.createAvailableDependencyVersionString(versions)
661656

662-
const valueFormOptions: { value: any; label: string }[] = []
663-
664-
versions.allVersions.forEach((version) => {
665-
valueFormOptions.push({
657+
const valueFormOptions: { value: any; label: string }[] = Object.entries(versions.allVersions).map(
658+
([version, _]) => ({
666659
value: version,
667660
label: version,
668661
})
669-
})
662+
)
670663

671664
const formItems: ChatItemFormItem[] = []
672665
formItems.push({

packages/core/src/amazonqTest/chat/controller/controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ export class TestController {
667667
const fileName = path.basename(session.generatedFilePath)
668668
const time = new Date().toLocaleString()
669669
// TODO: this is duplicated in basicCommands.ts for scan (codewhisperer). Fix this later.
670-
session.references.forEach((reference) => {
670+
for (const reference of session.references) {
671671
getLogger().debug('Processing reference: %O', reference)
672672
// Log values for debugging
673673
getLogger().debug('updatedContent: %s', updatedContent)
@@ -702,7 +702,7 @@ export class TestController {
702702
'<br>'
703703
getLogger().debug('Adding reference log: %s', referenceLog)
704704
ReferenceLogViewProvider.instance.addReferenceLog(referenceLog)
705-
})
705+
}
706706

707707
// TODO: see if there's a better way to check if active file is a diff
708708
if (vscode.window.tabGroups.activeTabGroup.activeTab?.label.includes(amazonQTabSuffix)) {
@@ -1241,7 +1241,7 @@ export class TestController {
12411241
groupName
12421242
)
12431243
if (session.listOfTestGenerationJobId.length && groupName) {
1244-
session.listOfTestGenerationJobId.forEach((id) => {
1244+
for (const id of session.listOfTestGenerationJobId) {
12451245
if (id === session.acceptedJobId) {
12461246
TelemetryHelper.instance.sendTestGenerationEvent(
12471247
groupName,
@@ -1267,7 +1267,7 @@ export class TestController {
12671267
0
12681268
)
12691269
}
1270-
})
1270+
}
12711271
}
12721272
session.listOfTestGenerationJobId = []
12731273
session.testGenerationJobGroupName = undefined

packages/core/src/applicationcomposer/composerWebview.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ export class ApplicationComposer {
104104
}
105105
this.isPanelDisposed = true
106106
this.onVisualizationDisposeEmitter.fire()
107-
this.disposables.forEach((disposable) => {
108-
disposable.dispose()
109-
})
107+
for (const d of this.disposables) {
108+
d.dispose()
109+
}
110110
this.onVisualizationDisposeEmitter.dispose()
111111
}
112112

packages/core/src/auth/credentials/sharedCredentials.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { assertHasProps } from '../../shared/utilities/tsUtils'
1010
import { getConfigFilename, getCredentialsFilename } from './sharedCredentialsFile'
1111
import { SectionName, StaticProfile } from './types'
1212
import { UserCredentialsUtils } from '../../shared/credentials/userCredentialsUtils'
13+
import { enumerate } from '../../shared/utilities/collectionUtils'
1314

1415
export async function updateAwsSdkLoadConfigEnvVar(): Promise<void> {
1516
const configFileExists = await fs.exists(getConfigFilename())
@@ -176,7 +177,8 @@ export function mergeAndValidateSections(data: BaseSection[]): ParseResult {
176177
export function parseIni(iniData: string, source: vscode.Uri): BaseSection[] {
177178
const sections = [] as BaseSection[]
178179
const lines = iniData.split(/\r?\n/).map((l) => l.split(/(^|\s)[;#]/)[0]) // remove comments
179-
lines.forEach((line, lineNumber) => {
180+
for (const item of enumerate(lines)) {
181+
const [line, lineNumber] = item
180182
const section = line.match(/^\s*\[([^\[\]]+)]\s*$/)
181183
const currentSection: BaseSection | undefined = sections[sections.length - 1]
182184
if (section) {
@@ -195,7 +197,7 @@ export function parseIni(iniData: string, source: vscode.Uri): BaseSection[] {
195197
})
196198
}
197199
}
198-
})
200+
}
199201

200202
return sections
201203
}

packages/core/src/auth/credentials/validation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ export function getCredentialsErrors(
3636
validateFunc: GetCredentialError = getCredentialError
3737
): CredentialsErrors | undefined {
3838
const errors: CredentialsData = {}
39-
Object.entries(data).forEach(([key, value]) => {
40-
if (!isCredentialsKey(key)) {
41-
return
39+
for (const item of Object.entries(data)) {
40+
const [key, value] = item
41+
if (isCredentialsKey(key)) {
42+
errors[key] = validateFunc(key, value)
4243
}
43-
errors[key] = validateFunc(key, value)
44-
})
44+
}
4545

4646
const hasErrors = Object.values(errors).some(Boolean)
4747
if (!hasErrors) {

0 commit comments

Comments
 (0)