Skip to content

Commit efc080a

Browse files
committed
add abt support
1 parent 500af95 commit efc080a

File tree

2 files changed

+32
-46
lines changed

2 files changed

+32
-46
lines changed

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

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@
44
*/
55

66
import * as vscode from 'vscode'
7-
import { fs } from '../../../shared'
7+
import { FeatureConfigProvider, fs } from '../../../shared'
88
import path = require('path')
99
import { BM25Document, BM25Okapi } from './rankBm25'
1010
import { ToolkitError } from '../../../shared/errors'
11-
import { crossFileContextConfig, supplemetalContextFetchingTimeoutMsg, UserGroup } from '../../models/constants'
11+
import { crossFileContextConfig, supplemetalContextFetchingTimeoutMsg } from '../../models/constants'
1212
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
1313
import { isTestFile } from './codeParsingUtil'
1414
import { getFileDistance } from '../../../shared/filesystemUtilities'
1515
import { getOpenFilesInWindow } from '../../../shared/utilities/editorUtilities'
1616
import { getLogger } from '../../../shared/logger/logger'
1717
import { CodeWhispererSupplementalContext, CodeWhispererSupplementalContextItem } from '../../models/model'
1818
import { LspController } from '../../../amazonq/lsp/lspController'
19-
import { CodeWhispererUserGroupSettings } from '../userGroupUtil'
2019

2120
type CrossFileSupportedLanguage =
2221
| 'java'
@@ -49,35 +48,27 @@ interface Chunk {
4948
score?: number
5049
}
5150

51+
type SupplementalContextConfig = 'none' | 'v1' | 'v2'
52+
5253
export async function fetchSupplementalContextForSrc(
5354
editor: vscode.TextEditor,
5455
cancellationToken: vscode.CancellationToken
5556
): Promise<Pick<CodeWhispererSupplementalContext, 'supplementalContextItems' | 'strategy'> | undefined> {
56-
const shouldProceed = shouldFetchCrossFileContext(
57-
editor.document.languageId,
58-
CodeWhispererUserGroupSettings.instance.userGroup
59-
)
57+
const supplementalContextConfig = getSupplementalContextConfig(editor.document.languageId)
6058

61-
if (!shouldProceed) {
62-
return shouldProceed === undefined
63-
? undefined
64-
: {
65-
supplementalContextItems: [],
66-
strategy: 'Empty',
67-
}
59+
if (supplementalContextConfig === 'none') {
60+
return undefined
6861
}
69-
70-
// TODO:
71-
if (false) {
62+
if (supplementalContextConfig === 'v1') {
63+
return fetchSupplementalContextForSrcV1(editor, cancellationToken)
64+
}
65+
try {
66+
return fetchSupplementalContextForSrcV2(editor)
67+
} catch (e) {
68+
getLogger().error(`Failed to fetch supplemental context from LSP ${e}`)
7269
return fetchSupplementalContextForSrcV1(editor, cancellationToken)
73-
} else {
74-
try {
75-
return fetchSupplementalContextForSrcV2(editor)
76-
} catch (e) {
77-
getLogger().error(`Failed to fetch supplemental context from LSP ${e}`)
78-
return fetchSupplementalContextForSrcV1(editor, cancellationToken)
79-
}
8070
}
71+
8172
}
8273

8374
export async function fetchSupplementalContextForSrcV2(
@@ -100,20 +91,6 @@ export async function fetchSupplementalContextForSrcV1(
10091
editor: vscode.TextEditor,
10192
cancellationToken: vscode.CancellationToken
10293
): Promise<Pick<CodeWhispererSupplementalContext, 'supplementalContextItems' | 'strategy'> | undefined> {
103-
const shouldProceed = shouldFetchCrossFileContext(
104-
editor.document.languageId,
105-
CodeWhispererUserGroupSettings.instance.userGroup
106-
)
107-
108-
if (!shouldProceed) {
109-
return shouldProceed === undefined
110-
? undefined
111-
: {
112-
supplementalContextItems: [],
113-
strategy: 'Empty',
114-
}
115-
}
116-
11794
const codeChunksCalculated = crossFileContextConfig.numberOfChunkToFetch
11895

11996
// Step 1: Get relevant cross files to refer
@@ -204,15 +181,14 @@ function getInputChunk(editor: vscode.TextEditor) {
204181
* @returns specifically returning undefined if the langueage is not supported,
205182
* otherwise true/false depending on if the language is fully supported or not belonging to the user group
206183
*/
207-
function shouldFetchCrossFileContext(
208-
languageId: vscode.TextDocument['languageId'],
209-
userGroup: UserGroup
210-
): boolean | undefined {
184+
function getSupplementalContextConfig(languageId: vscode.TextDocument['languageId']): SupplementalContextConfig {
211185
if (!isCrossFileSupported(languageId)) {
212-
return undefined
186+
return 'none'
213187
}
214-
215-
return true
188+
if (FeatureConfigProvider.instance.isNewProjectContextGroup()) {
189+
return 'v2'
190+
}
191+
return 'v1'
216192
}
217193

218194
/**

packages/core/src/shared/featureConfig.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ export class FeatureContext {
2424
public name: string,
2525
public variation: string,
2626
public value: FeatureValue
27-
) {}
27+
) { }
2828
}
2929

3030
const featureConfigPollIntervalInMs = 30 * 60 * 1000 // 30 mins
3131

3232
export const Features = {
3333
customizationArnOverride: 'customizationArnOverride',
3434
dataCollectionFeature: 'IDEProjectContextDataCollection',
35+
projectContextFeature: 'NewProjectContext',
3536
test: 'testFeature',
3637
} as const
3738

@@ -52,6 +53,8 @@ export class FeatureConfigProvider {
5253

5354
private _isDataCollectionGroup = false
5455

56+
private _isNewProjectContextGroup = false
57+
5558
constructor() {
5659
this.fetchFeatureConfigs().catch((e) => {
5760
getLogger().error('fetchFeatureConfigs failed: %s', (e as Error).message)
@@ -68,6 +71,9 @@ export class FeatureConfigProvider {
6871
return this._isDataCollectionGroup
6972
}
7073

74+
isNewProjectContextGroup(): boolean {
75+
return this._isNewProjectContextGroup
76+
}
7177
public async listFeatureEvaluations(): Promise<ListFeatureEvaluationsResponse> {
7278
const request: ListFeatureEvaluationsRequest = {
7379
userContext: {
@@ -151,6 +157,10 @@ export class FeatureConfigProvider {
151157
globals.globalState.tryUpdate('aws.amazonq.workspaceIndexToggleOn', true)
152158
}
153159
}
160+
const projectContextFeatureValue = this.featureConfigs.get(Features.projectContextFeature)?.value.stringValue
161+
if (projectContextFeatureValue) {
162+
this._isNewProjectContextGroup = true
163+
}
154164
} catch (e) {
155165
getLogger().error(`CodeWhisperer: Error when fetching feature configs ${e}`, e)
156166
}

0 commit comments

Comments
 (0)