44 */
55
66import * as vscode from 'vscode'
7- import { fs } from '../../../shared'
7+ import { FeatureConfigProvider , fs } from '../../../shared'
88import path = require( 'path' )
99import { BM25Document , BM25Okapi } from './rankBm25'
1010import { ToolkitError } from '../../../shared/errors'
11- import { crossFileContextConfig , supplemetalContextFetchingTimeoutMsg , UserGroup } from '../../models/constants'
11+ import { crossFileContextConfig , supplemetalContextFetchingTimeoutMsg } from '../../models/constants'
1212import { CancellationError } from '../../../shared/utilities/timeoutUtils'
1313import { isTestFile } from './codeParsingUtil'
1414import { getFileDistance } from '../../../shared/filesystemUtilities'
1515import { getOpenFilesInWindow } from '../../../shared/utilities/editorUtilities'
1616import { getLogger } from '../../../shared/logger/logger'
1717import { CodeWhispererSupplementalContext , CodeWhispererSupplementalContextItem } from '../../models/model'
1818import { LspController } from '../../../amazonq/lsp/lspController'
19- import { CodeWhispererUserGroupSettings } from '../userGroupUtil'
2019
2120type CrossFileSupportedLanguage =
2221 | 'java'
@@ -49,35 +48,27 @@ interface Chunk {
4948 score ?: number
5049}
5150
51+ type SupplementalContextConfig = 'none' | 'v1' | 'v2'
52+
5253export 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
8374export 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/**
0 commit comments