Skip to content
Merged
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
Expand Up @@ -18,7 +18,11 @@ import { isTestFile } from './codeParsingUtil'
import { getFileDistance } from '../../../shared/filesystemUtilities'
import { getOpenFilesInWindow } from '../../../shared/utilities/editorUtilities'
import { getLogger } from '../../../shared/logger/logger'
import { CodeWhispererSupplementalContext, CodeWhispererSupplementalContextItem } from '../../models/model'
import {
CodeWhispererSupplementalContext,
CodeWhispererSupplementalContextItem,
SupplementalContextStrategy,
} from '../../models/model'
import { LspController } from '../../../amazonq/lsp/lspController'
import { waitUntil } from '../../../shared/utilities/timeoutUtils'

Expand Down Expand Up @@ -75,14 +79,18 @@ export async function fetchSupplementalContextForSrc(

// opentabs context will use bm25 and users' open tabs to fetch supplemental context
if (supplementalContextConfig === 'opentabs') {
const supContext = (await fetchOpentabsContext(editor, cancellationToken)) ?? []
return {
supplementalContextItems: (await fetchOpentabsContext(editor, cancellationToken)) ?? [],
strategy: 'opentabs',
supplementalContextItems: supContext,
strategy: supContext.length === 0 ? 'Empty' : 'opentabs',
}
}

// codemap will use opentabs context plus repomap if it's present
if (supplementalContextConfig === 'codemap') {
let strategy: SupplementalContextStrategy = 'Empty'
let hasCodemap: boolean = false
let hasOpentabs: boolean = false
const opentabsContextAndCodemap = await waitUntil(
async function () {
const result: CodeWhispererSupplementalContextItem[] = []
Expand All @@ -91,20 +99,30 @@ export async function fetchSupplementalContextForSrc(

if (codemap && codemap.length > 0) {
result.push(...codemap)
hasCodemap = true
}

if (opentabsContext && opentabsContext.length > 0) {
result.push(...opentabsContext)
hasOpentabs = true
}

return result
},
{ timeout: supplementalContextTimeoutInMs, interval: 5, truthy: false }
)

if (hasCodemap) {
strategy = 'codemap'
} else if (hasOpentabs) {
strategy = 'opentabs'
} else {
strategy = 'Empty'
}

return {
supplementalContextItems: opentabsContextAndCodemap ?? [],
strategy: 'codemap',
strategy: strategy,
}
}

Expand Down Expand Up @@ -133,9 +151,10 @@ export async function fetchSupplementalContextForSrc(
}
}

const supContext = opentabsContext ?? []
return {
supplementalContextItems: opentabsContext ?? [],
strategy: 'opentabs',
supplementalContextItems: supContext,
strategy: supContext.length === 0 ? 'Empty' : 'opentabs',
}
}

Expand Down
Loading