Skip to content

Commit f1ff2fd

Browse files
committed
fine tune supplemental context strategy telemetry
1 parent 914bf73 commit f1ff2fd

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

packages/core/src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import { isTestFile } from './codeParsingUtil'
1818
import { getFileDistance } from '../../../shared/filesystemUtilities'
1919
import { getOpenFilesInWindow } from '../../../shared/utilities/editorUtilities'
2020
import { getLogger } from '../../../shared/logger/logger'
21-
import { CodeWhispererSupplementalContext, CodeWhispererSupplementalContextItem } from '../../models/model'
21+
import {
22+
CodeWhispererSupplementalContext,
23+
CodeWhispererSupplementalContextItem,
24+
SupplementalContextStrategy,
25+
} from '../../models/model'
2226
import { LspController } from '../../../amazonq/lsp/lspController'
2327
import { waitUntil } from '../../../shared/utilities/timeoutUtils'
2428

@@ -75,14 +79,18 @@ export async function fetchSupplementalContextForSrc(
7579

7680
// opentabs context will use bm25 and users' open tabs to fetch supplemental context
7781
if (supplementalContextConfig === 'opentabs') {
82+
const supContext = (await fetchOpentabsContext(editor, cancellationToken)) ?? []
7883
return {
79-
supplementalContextItems: (await fetchOpentabsContext(editor, cancellationToken)) ?? [],
80-
strategy: 'opentabs',
84+
supplementalContextItems: supContext,
85+
strategy: supContext.length === 0 ? 'Empty' : 'opentabs',
8186
}
8287
}
8388

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

92100
if (codemap && codemap.length > 0) {
93101
result.push(...codemap)
102+
hasCodemap = true
94103
}
95104

96105
if (opentabsContext && opentabsContext.length > 0) {
97106
result.push(...opentabsContext)
107+
hasOpentabs = true
98108
}
99109

100110
return result
101111
},
102112
{ timeout: supplementalContextTimeoutInMs, interval: 5, truthy: false }
103113
)
104114

115+
if (hasCodemap) {
116+
strategy = 'codemap'
117+
} else if (hasOpentabs) {
118+
strategy = 'opentabs'
119+
} else {
120+
strategy = 'Empty'
121+
}
122+
105123
return {
106124
supplementalContextItems: opentabsContextAndCodemap ?? [],
107-
strategy: 'codemap',
125+
strategy: strategy,
108126
}
109127
}
110128

@@ -133,9 +151,10 @@ export async function fetchSupplementalContextForSrc(
133151
}
134152
}
135153

154+
const supContext = opentabsContext ?? []
136155
return {
137-
supplementalContextItems: opentabsContext ?? [],
138-
strategy: 'opentabs',
156+
supplementalContextItems: supContext,
157+
strategy: supContext.length === 0 ? 'Empty' : 'opentabs',
139158
}
140159
}
141160

0 commit comments

Comments
 (0)